我正在黄瓜中运行测试,并且希望数据库对于我正在运行的测试是空的。我已经配置了执行此操作的设置,但是运行测试时数据存在。我究竟做错了什么?我也在使用 mongoid 并且正在使用 MongoDB。
功能/支持/env.rb:
require 'cucumber/rails'
Capybara.default_selector = :css
Dir[(Rails.root + "spec/factories/**/*.rb").to_s].each {|factory| require factory}
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :truncation
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Cucumber::Rails::Database.javascript_strategy = :truncation
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end