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

Chris Olsen lists at ruby-forum.com
Wed Jan 30 15:54:11 EST 2008


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

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

**Note: These are specs from different describe blocks run under
different authorize conditions.

Here is the do_get
---
def do_get
    get :index, {:account_id => 1}
  end

Notice the difference to where the do_get method is called.  I had an
error and it was due to the order not being as is shown above.  In the
docs it shows the actual request to be made before the assertion
statement, but that doesn't work in the second example.

Thanks
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list