Reputation: 21
I set up cucumber/rails for my rails project and populated the test database with data, to run tests against it. When I run "rake cucumber" the database gets truncated. I tried to set DatabaseCleaner.strategy to :transaction and nil, but it still gets truncated. I'd prefer not to use database_cleaner at all for now, but its presence is required by cucumber. Here is my "./features/support/env.rb" file:
require 'cucumber/rails'
require 'capybara/cucumber'
Capybara.default_driver = :selenium
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = nil
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
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Upvotes: 2
Views: 1696
Reputation: 18614
I believe this is the simplest and documented approach.
Cucumber::Rails::Database.autorun_database_cleaner = false
Upvotes: 1
Reputation: 5320
You need to set both the DatabaseCleaner.strategy
and the Cucumber::Rails::Database.javascript_strategy
.
Cucumber-rails does not come with a null strategy so you have to make one. This works for me, in env.rb
:
DatabaseCleaner.strategy = DatabaseCleaner::NullStrategy
class NullStrategy < Cucumber::Rails::Database::Strategy
def before_js
super DatabaseCleaner::NullStrategy
end
end
Cucumber::Rails::Database.javascript_strategy = NullStrategy
Upvotes: 1
Reputation: 1249
I don't believe there is a strategy that does nothing, but cucumber doesn't need it to run. Possibly you may have to remove it from your env.rb file and any db cleaning in your hooks file.
EDIT:
I was wrong, there is a null strategy. Try:
DatabaseCleaner.strategy = DatabaseCleaner::NullStrategy
or
DatabaseCleaner::Base.new
Upvotes: 3