【问题标题】:RSpec controller response body is returning string name of response class instead of responseRSpec 控制器响应正文返回响应类的字符串名称而不是响应
【发布时间】:2012-08-03 23:46:56
【问题描述】:

我正在使用 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 是字符串“#<:response:0x007f87d6ee8800>”。如何获得实际的 json 响应?当我通过浏览器时,它工作正常。

【问题讨论】:

    标签: ruby-on-rails rspec response controllers


    【解决方案1】:

    它与声明式授权和设计有关。这个答案帮助我弄清楚如何设置我的测试。 Stringify Keys Error with Devise and Declarative Testing with RSpec in Rails 3.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-30
      • 2023-03-19
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2019-10-28
      相关资源
      最近更新 更多