Created
October 16, 2012 08:51
-
-
Save ysawa/3898121 to your computer and use it in GitHub Desktop.
use Mongoid 3 and delete all collections before :each spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Mongoid 3 uses Moped as MongoDB driver, not mongo-ruby-driver. | |
| # Thus we should replace some codes. | |
| # Change your spec/spec_helper.rb like this code below: | |
| RSpec.configure do |config| | |
| config.before(:each) do | |
| Mongoid.session(:default).collections.each do |collection| | |
| # Each Moped::Collection instance is picked up, | |
| # and drop the collection. | |
| collection.drop | |
| end | |
| # # If you are a Mongoid 2 user, choose this code below: | |
| # Mongoid.database.collections.each do |collection| | |
| # unless collection.name =~ /^system\./ | |
| # collection.remove | |
| # end | |
| # end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment