如何为cucumber / rails禁用database_cleaner?

时间:2015-02-15 23:29:33

标签: ruby-on-rails cucumber capybara database-cleaner

我为我的rails项目设置了cucumber / rails并用数据填充了测试数据库,以对其运行测试。当我跑#34;耙黄瓜"数据库被截断。我试图将DatabaseCleaner.strategy设置为:transaction和nil,但它仍然被截断。我现在根本不想使用database_cleaner,但黄瓜需要它的存在。这是我的#34; ./ features / support / env.rb"文件:

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 个答案:

答案 0 :(得分:3)

我不相信有一种策略什么都不做,但黄瓜并不需要它来运行。可能您可能必须从您的env.rb文件中删除它以及钩子文件中的任何数据库清理。

编辑:

我错了,有一个空策略。试试:

DatabaseCleaner.strategy = DatabaseCleaner::NullStrategy

DatabaseCleaner::Base.new

答案 1 :(得分:0)

您需要同时设置DatabaseCleaner.strategyCucumber::Rails::Database.javascript_strategy

Cucumber-rails没有空策略所以你必须制作一个。这适用于我,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