I\'m having problem making two requests to the same url in a rails integration test, with rspec
it \'does something\' do
# get \'/something\', {:status=>\'
Using Capybara instead of rspec is a better solution for (request) intergration tests. It uses the same syntax as rspec and allow multiple requests in a single it block. I use rspec for unit testing and capybara for integration testing.
https://github.com/jnicklas/capybara
With plain old Rails test suite, functional tests are for single request and if you want to test flows you should use integration tests (you can reset the controller in functional tests).
Controller specs from rspec-rails inherit from Rails functional tests, so they have same limitation. You can use rspec with capybara or webrat (I recommend the former) for integration tests.
Also, recent versions of rspec-rails has "request specs" which "mix in behaivour of Rails integration tests": https://github.com/rspec/rspec-rails
You have to clear your instance variables, or maybe the only necessary one.
Let's pretend you use @book
in your controller.
get '/something'
assert ...
controller.instance_variable_set(:@book, nil)
get '/something'
assert ...
If you are using inherit_resources
get '/something'
assert ...
controller.send(:set_resource_ivar, nil)
get '/something'
assert ...
rails integration tests should be written so that the on case tests the one single request - response cycle. we can check redirects. but if you have to do something like
get '/something', {:status=>'any_other'}, @header
get '/something', {:status=>'ok'}, @header
You should write two different cases for this.
I don't think the problem is that you are getting the same response, it is that you are actually sending the same request twice.
The following works for me when I want to make two requests in the same test:
@request.delete_header 'RAW_POST_DATA'