Description
In a rails 4.2.7.1 app, with eager_load = false
(and rspec-rails 3.4.2 (though I have the same behavior on 3.5.0))
In my suite, I have a spec which runs mock_model("Transfer")
This sometimes works correctly, and sometimes does not, depending on the order of my specs.
I have tracked it down to the fact that sometimes, before this is run, some other spec has referenced Transfer
, thus loading the class definition.
Problem If the spec which does mock_model("Transfer")
runs first, any subsequent reference to Transfer
will return a Class.new
, instead of the ActiveRecord-backed definition.
I think I've tracked this to https://github.com/rspec/rspec-activemodel-mocks/blob/master/lib/rspec/active_model/mocks/mocks.rb#L91
I feel I have 2 options:
- set
eager_load = true
in test.rb - reference
mock_model(Transfer)
instead ofmock_model("Transfer")
I am reporting this here not because I don't have a way forward, but because I think that this behavior doesn't follow with the documentation https://github.com/rspec/rspec-activemodel-mocks#mock "A String representing a Class that extends ActiveModel::Naming"
Am I using this gem incorrectly?