-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix === for multiple mocks of the same model #61
Conversation
500deb0
to
641e55a
Compare
Can you rebase this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why you used a stub to store this data (so its automatically cleared), but rather than a global, I suggest stubing it on the model itself, its slightly neater
641e55a
to
97ce3df
Compare
I went back and forth on stubbing globally or on the model itself, but chose global because 1) we don’t accidentally override a method on the model itself, and 2) one spec fails on Rails 7.1 when I stub on the model itself. However, I think you are correct, it is better to stub on the model. I will look into why the spec is failing. |
97ce3df
to
5d640fe
Compare
Sorry, I changed it back to the global stub store again. It works, and it seems to get properly cleared after each example is run. |
5d640fe
to
fdcc72d
Compare
When the same model is mocked more than once in the same context, comparing with the model class using `#===` would only return true for the first of the mocks. All following mocks would return false when compared to the original model class using `#===`. For `#===` to work correctly, we register each mock in a "mock_store" on the `RSpec::ActiveModel::Mocks::Mocks` module. The store is implemented as an RSpec stub, so it is reset after each spec example. Fixes rspec#60
fdcc72d
to
265ac5e
Compare
Released in 1.2.1, thanks! |
Thank you Jon 👍🏼 |
When the same model is mocked more than once in the same context, comparing with the model class using
#===
would only return true for the first of the mocks. All following mocks would return false when compared to the original model class using#===
.For
#===
to work correctly, we register each mock in a "mock_store" on theRSpec::ActiveModel::Mocks::Mocks
module. The store is implemented as an RSpec stub, so it is reset after each spec example.Fixes #60
I realize that I’m adding some complex code into some already-complex code, so please let me know if you’d rather have it implemented in some other way.