-
-
Notifications
You must be signed in to change notification settings - Fork 760
Mocking models is not isolated #916
Comments
This is really an rspec-rails issue, but tl;dr is Check out the docs: |
I think mock_model should define a constant only in its outer scope of describe or "it" block, but not globally. How about independent tests? |
This isn't really possible. Even if it were, the code under test wouldn't be able to use the constant. Honestly, I don't write tests that use |
I think it is possible if we change it to use As it stands, right now it's "leaky" in the sense that it mutates the global constants and leaves them as such, which can cause ordering dependencies and other weirdness. Regardless, this is really an rspec-rails issue, so perhaps this discussion should be moved there. |
Interesting. Maybe |
I mock a model in my controller spes (terms_controller.rb). Also I use model (non exsisting yet) without mocking it in my acceptance test (term_display_spec.rb). And I see a strange situation.
If I run acceptance test separatly as
bundle exec rspec spec/features/term_display_spec.rb - everything goes the right way, I get an error NameError: uninitialized constant Term. It's OK, because I really dont have Term model yet.
But, if I run my acceptence test with controller spec in one command as
bundle exec rspec spec/features/term_display_spec.rb spec/controllers/terms_controller_spec.rb
I suddenly get another error, undefined method `create' for Term:Class, that means that somewhere class Term already exsists! I think that mocking something in one test (inside describe block) should not affect another tests. Explaine me pleaase this situation.
My working code is here https://github.com/molfar/sample_rspec
The text was updated successfully, but these errors were encountered: