# Configure DatabaseCleaner With Rspec for Mongoid 5 and Beyond

Database Cleaner is a nifty gem for streamlining tests. Configuring it is straightforward but it didn’t work for me out of the box for Mongoid 5.

Here’s my Gemfile segment for testing.

I added a require 'support/database_cleaner' in my spec_helper. And here’s my database_cleaner.rb.

When I ran my spec, I was greeted with an unexpected ugly error.

After looking at the code in the gem, I finally found out what was wrong in it. I created a commit for fix and submitted a pull request to the maintainer. Looking at my commit and the relevant files truncation.rb and truncation_mixin.rb, you should be able to piece together the problem.

Meanwhile, if you are using Mongoid 5 and aren’t able to get it working you could simply point to my fork of database_cleaner by updating your Gemfile to have: