我正在运行黄瓜测试,并希望数据库在我运行的测试中为空。我已将配置设置为执行此操作,但运行测试时数据存在。我究竟做错了什么?我也使用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
答案 0 :(得分:1)
您实际上并未在任何时候清理数据库。您有数据库清理程序,但没有调用clean方法。
在env.rb
中试试Before do
DatabaseCleaner.start
end
After do
DatabaseCleaner.clean
end