6

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
Viktor Trón
  • 8,774
  • 4
  • 45
  • 48
Squadrons
  • 2,467
  • 5
  • 25
  • 36
  • 1
    I didn't need the accepted answer but your question was very useful for me! I am using the 'if JS use truncation' block and it's working perfectly! Thanks! – Alan LaMielle Jan 14 '14 at 17:31
  • 1
    Glad to help. The number of hours I spent messing around with this was not fun. – Squadrons Jan 14 '14 at 19:04

1 Answers1

3

this should do it, let me know

config.after(:all, :type => :feature) do
  DatabaseCleaner.clean_with :truncation
end
Viktor Trón
  • 8,774
  • 4
  • 45
  • 48