Skip to content

Instantly share code, notes, and snippets.

@ysawa
Created October 16, 2012 08:51
Show Gist options
  • Select an option

  • Save ysawa/3898121 to your computer and use it in GitHub Desktop.

Select an option

Save ysawa/3898121 to your computer and use it in GitHub Desktop.
use Mongoid 3 and delete all collections before :each spec
# 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