4
I’m trying to do a test similar to the one below to capture the Exception of a non-existent document
expect(Produto.find('57e2bf76ce222fd11258cd4e')).to raise_error(Mongoid::Errors::DocumentNotFound)
the Exception message being passed is shown, however the test does not pass :(
Mongoid::Errors::DocumentNotFound: message: Document(s) not found for class Produto with id(s) 57e2bf76ce222fd11258cd4e. summary: When calling Produto.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): 57e2bf76ce222fd11258cd4e ... (1 total) and the following ids were not found: 57e2bf76ce222fd11258cd4e. resolution: Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples. from ~/.rvm/gems/ruby-2.3.1@api/bundler/gems/mongoid-71c29a805990/lib/mongoid/criteria.rb:457:in `check_for_missing_documents!'
I don’t know if it has anything to do with the last line of the message
mongoid/criteria.rb:457:in `check_for_missing_documents!'
but what I notice is that raise_error is not working in this situation. What I am doing wrong?
really, had already corrected but still thank you very much for the explanation ;)
– Vinicius Luiz