Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Rspec Capybara and DatabaseCleaner - using truncation only on feature tests

I saw this cool method for only using Database cleaners :truncation for capybara test using :js => true

In 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 

The problem is that any feature test done with capybara seems to need the cleaning strategy to be :truncation.

All the other specs, however, are fine with :transaction, which is significantly faster.

Is there a way of specifying strategy for only capybara feature tests? SOmething like:

DataCleaner.strategy( :truncation ) if :type => :feature
like image 631
Squadrons Avatar asked Feb 14 '13 17:02

Squadrons


1 Answers

this should do it, let me know

config.after(:all, :type => :feature) do
  DatabaseCleaner.clean_with :truncation
end
like image 195
Viktor Trón Avatar answered Oct 23 '22 21:10

Viktor Trón