1

rspecを使用してRailsでコントローラーをテストしています。応答本文は、実際の応答ではなく、応答インスタンスの文字列にすぎません。私のテストは以下の通りです。

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は、文字列「#<ActionDispatch :: Response:0x007f87d6ee8800>」です。実際のjson応答を取得するにはどうすればよいですか?ブラウザを使用すると、正常に動作します。

4

1 に答える 1

0

それは、宣言的な承認と工夫に関係していました。この回答は、テストの設定方法を理解するのに役立ちました。Rails 3.1 の RSpec を使用した Devise および宣言型テストでの Stringify Keys エラー

于 2012-08-07T01:47:39.383 に答える