RSpec :: Mocks :: Mock:Class的未定义方法`i18n_scope'

时间:2015-08-18 07:20:38

标签: ruby-on-rails-4 internationalization rspec-rails rspec2 rspec-mocks

我最近升级到Rails 4.当我运行RSpec测试时出现错误。

这是我的规格:

1   model = double(:model, errors: double(:errors, full_messages: []))
2   transaction = double(:transaction)
3   transaction.stub(:update_attributes!) { raise ActiveRecord::RecordInvalid.new(model) }

我在第3行收到错误<NoMethodError: undefined method 'i18n_scope' for RSpec::Mocks::Mock:Class>

Per the API documentation 'i18n_scope' has been removed from Rails 4.

1 个答案:

答案 0 :(得分:-1)

RSpec::Mocks::Mock.stub(:i18n_scope).and_return(:activerecord)
model = double(:model, errors: double(:errors, full_messages: []))
ActiveRecord::RecordInvalid.new(model)

不确定为什么RSpec :: Mocks :: Mock:Class正在寻找'i18n_scope'方法。但为了修复它,我打断了'i18n_scope'。然后就行了。