Rails Rspec Capybara和DatabaseCleaner - 仅在特征测试中使用截断

Squ*_*ons 6 testing ruby-on-rails capybara database-cleaner

我看到这个很酷的方法只使用数据库清理程序:使用以下方法截断capybara测试:js => true

在spec_helper.rb中:

config.before(:each) do
  DatabaseCleaner.strategy = if example.metadata[:js]
    :truncation
  else
    :transaction
  end
  DatabaseCleaner.start
end

config.after(:each) do
  DatabaseCleaner.clean
end 
Run Code Online (Sandbox Code Playgroud)

问题是,使用水豚进行的任何功能测试似乎都需要清除策略:截断.

但是,所有其他规格都适用于:交易,这要快得多.

有没有一种方法只为capybara功能测试指定策略?就像是:

DataCleaner.strategy( :truncation ) if :type => :feature
Run Code Online (Sandbox Code Playgroud)

Vik*_*rón 3

这应该可以,让我知道

config.after(:all, :type => :feature) do
  DatabaseCleaner.clean_with :truncation
end
Run Code Online (Sandbox Code Playgroud)