Search code examples
ruby-on-railsrspecresponsecontrollers

RSpec controller response body is returning string name of response class instead of response


I am testing a controller in rails using rspec. The response body is just the string of the response instance and not the actual response. My test is below.

require 'spec_helper'

describe CampusesController do
    render_views

    before(:each) do
        sign_in :auth_role, 'test@test.com', 'password'
    end

    it 'should retrieve all campuses as json' do
        FactoryGirl.create(:basic_campus)
        get 'index', :format => :json
        ap response.body
    end

end

response.body is the string "#<ActionDispatch::Response:0x007f87d6ee8800>". How do I get the actual json response? When I go through the browser, it works fine.


Solution

  • It had to do with declarative authorization and devise. This answer helped me figure out how to set up my tests. Stringify Keys Error with Devise and Declarative Testing with RSpec in Rails 3.1