Skip to content

Instantly share code, notes, and snippets.

@retospect
Created February 11, 2011 20:20
Show Gist options
  • Save retospect/822943 to your computer and use it in GitHub Desktop.
Save retospect/822943 to your computer and use it in GitHub Desktop.
How to get nice test messages in your rspec test logs, and reset mongoid records
RSpec.configure do |config|
config.mock_with :mocha
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
# use_transactional_fixtures config option was removed by Mongoid
# config.use_transactional_fixtures = false
config.before(:each) do
# Make a note in the log to state what test is running
if !@printed_logger_info
msg = "Starting #{example.full_description} on #{Time.new}"
Rails.logger.info("\n#{msg}\n"+
"#{'=' * msg.length}\n"+
"#{example.metadata[:location]}\n\n")
@printed_logger_info = true
end
# Because we don't use transactional fixtures, we'll need to clean out both
# the ActiveRecord and the MongoMapper databases before each test
ActiveRecord::Base.send(:descendants).each{|klass| klass.delete_all }
Mongoid.master.collections.select do |collection|
collection.name !~ /system/
end.each(&:drop)
end
config.include(Capybara, :type => :integration)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment