Austin Ruby On Rails Developer Blog

Mongoid + Test::Unit + Shoulda Matchers

Trying to do validates_presence_of with a Rails 3 app running Mongoid, Test::Unit, and Shoulda?

You might be in for a bit of pain.

Have no fear! Here’s a quick fix that might help you out:

In your Gemfile, be sure to explicitly add both lines:

gem "shoulda"
gem "shoulda-matchers"

Apparently there is some issue where just installing ‘shoulda’ doesn’t give you the matchers on a non-ActiveRecord app, even though they (mostly) should work ActiveModel and Mongoid.

UPDATE: another solution here is to just use the beta version of shoulda, if you’re so inclined:
gem “shoulda”, “>=3.0.0.beta2”

Published on Wed, 11 Jan 2012 21:33