Getting the new Shoulda Matchers to work in Rails

CJ Bryan
Ministry of Velocity
1 min readNov 25, 2015

--

When you’re writing tests against your models, the convenience of ThoughtBot’s Shoulda Matchers Gem is tremendous. I was working on a client project recently and we tried to install this Gem. Unfortunately, we ran into this strange error related to ActiveSupport::TestCase:

Oh no! With the latest version of `shoulda-matchers` they changed their interface a little bit. Instead of automatically loading into Rails like it always did, you’ll have to manually set things up. Fortunately, the fix is simple. Head over to your `spec/support/shoulda.rb` file and make sure that it looks like this:

Here at Ministry of Velocity we’re fans of the `spec/support` folder. If you don’t already include it from your `rails_helper.rb` file, just plunk this line in there:

Hopefully this helped you get your test suite back up and running. It’s great to see the open source world alive and well, but sometimes a Gem update makes your day a little too rocky. Here’s to passing specs!

I am a consultant at Ministry of Velocity. We train engineering teams on refactoring, advise on DevOps automation, and build world-class applications in Rails, Go, and JavaScript. You should work with us.

--

--