【问题标题】:Why is response.body is a string instance when testing controller with rspec为什么在使用 rspec 测试控制器时 response.body 是一个字符串实例
【发布时间】:2012-11-04 21:32:46
【问题描述】:

在我的控制器的 rspec 测试中,响应的主体始终是 ActiveDispatch::Response 实例的字符串表示形式。

=> #<ActionController::TestResponse:0x00000007863010
 ...
 @body=["#<ActionDispatch::Response:0x00000007530d70>"],...

有问题的控制器规格:

it 'should not allow invalid email' do
     json = { :format => 'json', :patron_profile => { :email =>   'bogusemail.com', :password => 'password' } }
     post :create, json
     response.status.should eq(302)
     response.body.to_json.should be_json_eql(%({ 'error' : 'error message'}))
end

什么可能导致response.body 成为上面显示的 ActionDispatch 字符串?

【问题讨论】:

  • 你用render_views试试这个吗?
  • 是的,但结果相同。

标签: ruby-on-rails-3 rspec


【解决方案1】:

Devise 的 Github 帐户上的问题 2074 似乎是导致此问题的原因。

截至 2012 年 11 月 4 日,解决方法是在 Gemfile 中使用 Devise 的 git master 分支。

【讨论】:

    猜你喜欢
    • 2016-07-30
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多