Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which gem for RSpec matchers should I use with Mongoid?

It seems there are two gems that provide RSpec matchers to use with Mongoid.

Which is a better choice and why?

MONGOID-RSPEC
Evan Sagge's mongoid-rspec gem provides RSpec matchers for Mongoid. Includes matchers for associations, options, validations, and fields.
http://github.com/evansagge/mongoid-rspec

REMARKABLE-MONGOID
Brian Cardarella's remarkable-mongoid gem provides RSpec matchers for Mongoid. It contains matchers just for Mongoid, plus all validation matchers fromRemarkable::ActiveModel.
http://github.com/bcardarella/remarkable_mongoid

like image 875
Daniel Kehoe Avatar asked Mar 04 '11 03:03

Daniel Kehoe


2 Answers

Personally, I don't think you should be using either. Specify the behaviour you expect from your code, not the implementation and your specs will be that much more meaningful.

What happens if you decide to switch from Mongoid to MongoMapper? Or back to ActiveRecord? You have to throw out the majority of your test suite and re-write it.

All those libraries do is direct you to do Development-Driven Testing, which is the complete antithesis of BDD/TDD.

like image 58
dnch Avatar answered Oct 17 '22 08:10

dnch


remarkable-mongoid's advantage is also, unfortunately, its disadvantage. The idea was to use the Remarkable ActiveModel matchers for the validators. This requires the alpha version of Remarkable 4.0. While Remarkable is a library of very high quality it also hasn't been touched since last June. This is a huge issue with my library, the main dependency hasn't left alpha in over 8 months! I pinged several of the devs and never heard back from any of them.

As for which of the two libraries is better, a quick look at the README it seems like mongoid-rspec has more features. However, I have never used it and cannot speak about any experience with it.

All this being said, to be perfectly honest (even though I wrote one of the libraries) I think both are pretty bullshit. Unfortunately Shoulda started this useless style of testing of validations and associations and everybody has followed suit. (myself included) In pretty much every case writing the test is just a duplication of effort of writing the actual code. You're not really testing anything at all. At the very best they can be seen a sanity check. At worst they are a complete waste of time.

I suggest asserting the behavior in different parts of the test suite.

like image 22
bcardarella Avatar answered Oct 17 '22 08:10

bcardarella