升级到Rails 5后查看规范失败

时间:2017-10-04 15:24:34

标签: ruby-on-rails rspec ruby-on-rails-5 rspec-rails

我的观点如下:

json = render 'users/info', user: @user
json[:device] = render 'devices/info', device: @device
json[:locations] = locations.map { |l| render 'locations/info', l: l } if params[:locations_scope].present?

json

我的测试如下:

before do
    product
    assign(:user, user)
    assign(:device, device)
    allow(view).to receive(:user_is_connected?) { false }
    allow(view).to receive(:utc_string)
    render
  end

  describe 'user object' do
    it 'provies the email' do
      expect(subject['user']['email']).to eq(user.email)
    end

升级到rails 5之前,它工作正常,但现在我收到了错误

@rendered_views=#<ActionView::TestCase::Behavior::RenderedViewsCollection:0x007fd6e8f29a88 @rendered_views={}>> does not implement: user_is_connected?

user_is_connected?方法是基本控制器中的辅助方法 似乎在RoR 5中这种行为发生了变化,但我无法找到与此相关的任何内容。

我也将rails-controller-testing添加到gemfile中,但仍然是同样的问题

1 个答案:

答案 0 :(得分:1)

刚想通了:在RSpec上禁用部分嘲笑的验证

{
  "body": "token=specificToken&someOtherField=someValue"
}