You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
reference mock_model(Transfer) instead of mock_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?
The text was updated successfully, but these errors were encountered:
rdunlop
changed the title
mock_model("Transfer") doesn't clean up afterwards
mock_model("Transfer") creates persistent Class.new instead of loading ActiveRecord model
Mar 7, 2017
rdunlop
changed the title
mock_model("Transfer") creates persistent Class.new instead of loading ActiveRecord model
mock_model("Transfer") creates persistent Class.new instead of loading ActiveRecord-backed class
Mar 7, 2017
We are seeing this same problem, which manifested for our team when we moved our continuous integration build into a cloud provider (seen on both Semaphore and CirceCI) that was splitting up our test suite. Sometimes, we'd get the following error:
I tracked that down to see that the only places that class was defined was where it should be, but that it was also used in a mock_model('SurveyAnswer') call. And sure enough, if I add a similar call to thebefore of the flickering spec, I can make it fail reliably. Using @rdunlop's link above, I then added the following line right after my new mock_model invocation:
p loc: SurveyAnswer.method(:primary_key).source_location
And the output shows that the SurveyAnswer constant is indeed being set to the mocked version:
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 toTransfer
will return aClass.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:
eager_load = true
in test.rbmock_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?
The text was updated successfully, but these errors were encountered: