1

I recently upgraded to Rails 4. When I ran my RSpec tests I got an error.

Here is my spec:

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

I got the error <NoMethodError: undefined method 'i18n_scope' for RSpec::Mocks::Mock:Class> in line 3.

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

1

1 Answer 1

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

Not sure why RSpec::Mocks::Mock:Class was looking for 'i18n_scope' method. But to fix it, I stubbed 'i18n_scope'. Then it works.

1
  • This isn't correct. The double class is RSpec::Mocks::Double. This class also doesn't implement i18n_scope. You can see my answer here: stackoverflow.com/questions/33037136/…. At least for RSpec 3.3+
    – daino3
    Dec 18, 2015 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.