【问题标题】:views specs failing after upgrade to Rails 5升级到 Rails 5 后查看规范失败
【发布时间】:2017-10-04 15:24:33
【问题描述】:

我的看法如下:

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 中发生了变化,但我找不到与此相关的任何内容。

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

【问题讨论】:

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


    【解决方案1】:

    刚刚发现:禁用 RSpec 上部分模拟的验证

    config.mock_with :rspec do |mocks|
      mocks.verify_partial_doubles = false
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      相关资源
      最近更新 更多