[rspec-devel] [ rspec-Feature Requests-6059 ] Controller testing w/ Rails: response is not upated when same action is GETted multiple times within a specify block

noreply at rubyforge.org noreply at rubyforge.org
Tue Nov 7 06:02:50 EST 2006


Feature Requests item #6059, was opened at 2006-10-08 01:54
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=6059&group_id=797

Category: None
Group: None
Status: Open
Priority: 3
Submitted By: David Lee (davidlee)
Assigned to: Nobody (None)
Summary: Controller testing w/ Rails: response is not upated when same action is GETted multiple times within a specify block

Initial Comment:
Controller testing with RSpec + Rails: response is not upated within a specification when same action is called multiple times within a specify block

using Rails 1.1.6 and RSpec 0.6.4

The response object is not being updated within a specify block if multiple responses are generated by GETting the same action. 

This was verified by checking the redirect_url reported.

This does not appear to be an issue unless the *same action* is called multiple times within a specify block, eg to test the effect of accessing an action with different permissions or parameters. Calling the action with different parameters did not appear to affect the problem.

example:

  specify "Index should redirect to welcome if already logged in" do

    # this will redirect to login as user is not logged in.
    # the presence of this line will break the test.
    get :index 

    request.session[:user] = 1 # subsequent gets will redirect to welcome
   
    # this will be ignored with regard to the response.redirect_url reported
    get :index 
    response.should_redirect

    # fails if first line is present:
    # says the redirect_url equals 'http://test.host/account/login'
    # which is a leftover from the first get :index
    response.redirect_url.should_equal 'http://test.host/account/welcome'
  end

breaking the two `get :index` calls out into separate specify blocks alleviates the problem.


----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2006-11-07 11:02

Message:
Also - moving this over to feature requests - this is by design, not a bug.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-11-07 11:02

Message:
"breaking the two `get :index` calls out into separate specify blocks alleviates the problem."

That's also the BDD way.

Given (context)
When (single event or set of events)
Then (outcomes)

The specs could read:

Given a user who is logged in
- GET index should redirect to welcome

Given a user who is NOT logged in
- GET index should redirect to login page

OR you could have two specs in the same context:

GET index
- should redirect a logged in user to welcome
- should redirect an anonymous user to the login page

We will need to support multiple GETS when we add integration specs, so I'll leave this open to keep it on the radar, but we will likely not be supporting this in the context of controller specs.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=6059&group_id=797


More information about the rspec-devel mailing list