Testing REST-API responses with Rspec and Rack::Test Testing REST-API responses with Rspec and Rack::Test ruby ruby

Testing REST-API responses with Rspec and Rack::Test


response is automatic for certain spec types.

Rspec probably mixes ActionController::TestCase::Behavior for :type => :api blocks.
response would come from ActionController::TestCase::Behavior, as it does for :type => :controller blocks.

If you want to get the response before that given by response, try storing it in a variable before you make the next request.

https://www.relishapp.com/rspec/rspec-rails/v/2-3/docs/controller-specs and https://github.com/rspec/rspec-rails give some information about what is mixed in with some of the various spec types.


I think that login(current_user) does not work with Rack::Test::Methods. You need a way to authenticate through your API call, perhaps with an authentication token.

response is tied to ActionController, which knows about your login. If I am not mistaken, API calls are independent of the Controller, so it doesn't know that you are already logged in.

See Ticketee, the example app from Rails 3 in Action, for an example!