I am using cucumber + capybara for my tests.The database cleaner is working good, but when I change the Capybara.default_driver to selenium, database cleaner is not working. Below is my env.rb file.
Capybara.default_selector = :css
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
ActionController::Base.allow_rescue = false
Cucumber::Rails::World.use_transactional_fixtures = true
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
OmniAuth.config.test_开发者_如何学编程mode = true
From the database_cleaner documentation, hope it helps:
One of my motivations for writing this library was to have an easy way to turn on what Rails calls “transactional_fixtures” in my non-rails ActiveRecord projects. For example, Cucumber ships with a Rails world that will wrap each scenario in a transaction. This is great, but what if you are using ActiveRecord in a non-rails project? You used to have to copy-and-paste the needed code, but with DatabaseCleaner you can now say:
#env.rb
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :transaction
Now lets say you are running your features and it requires that another process be involved (i.e. Selenium running against your app’s server.) You can simply change your strategy type:
#env.rb
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :truncation
You can have the best of both worlds and use the best one for the job:
#env.rb
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = (ENV['SELENIUM'] == 'true') ? :truncation : :transaction
精彩评论