[rspec-users] Order of the get call and xxx.should

Courtenay court3nay at gmail.com
Wed Jan 30 16:01:07 EST 2008

On Jan 30, 2008 12:54 PM, Chris Olsen <lists at ruby-forum.com> wrote:
> Just out of curiosity, why is that the following .should calls have to
> differ to work?
> The first is a normal check on the if the user is redirected if not
> logged in
> =========
> it "should redirect the user to the login screen" do
>     do_get
>     response.should redirect_to(new_session_url)
>   end

Because the response object doesn't exist before the 'get'.

> The second is checking to ensure that the proper user validation method
> is called
> =========
> it "should validate the user" do
>     controller.should_receive(:authorized?).and_return(true)
>     do_get
>   end

Because we need to stub the method on the controller before the request is run.
i.e., prevent it from running.

The former is checking that something happened, which didn't exist before the
call was run.  Whereas the latter is stubbing the method as well as
raising if it doesn't.


More information about the rspec-users mailing list