2
votes

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
2

2 Answers

3
votes

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

0
votes

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