Closed iainbeeston closed 11 years ago
@iainbeeston We thought that does not make sense to test callback in this way. Usually callbacks have dependencies and should be tested on through model actions.
@nanocity Thanks for you PR, but we believe mongoid-rspec wouldn't support this feature following the reason above. We believe it has another scope, so I think it could be another gem similar to shoulda-callback-matchers.
Hi again, I just created a repo, mostly copy-pasting this source, to publish a separate gem.
I have a question, is there any reason to not to include the matchers module automatically and suggesting the user to do it in spec/support?
Thanks.
@nanocity The reason is that to test callbacks isolated as these matchers support, isn't a good practice.
Callbacks should be tested on the model context, i.e: If you have a callback that is called on after create of model, the spec should call model.create
to test the callback. Is not a good practice only look up for a definition of callback in a model/document.
Best
Sure, I get that. I have not expressed myself well, sorry for my english.
I was talking about the gem itself, by now the user has to explicitly include Mongoid::Matchers
module in RSpec.configure
block. I was wondering what is the reason to not do that on lib/mongoid-rpsec.rb automatically.
I went that way on mongoid-rspec-callbacks gem but i'd like to stay as similar as possible to this gem.
Regards.
Edit: I forgot that rails probably won't load lib/mongoid-rspec.rb automatically so...
mongoid-rspec has no support for testing callbacks on models. shoulda doesn't either, but there is an additional gem for testing this (shoulda-callback-matchers). Is this something that mongoid-rspec should provide?