我看到了一种只使用数据库清理器:在使用 :js => true 的 capybara 测试中使用截断方法的好方法。
在 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
问题在于使用capybara进行的任何功能测试似乎都需要清理策略为:截断。
然而,所有其他规范都可以使用较快的:事务。
有没有一种方法只针对capybara功能测试指定策略?类似于:
DataCleaner.strategy( :truncation ) if :type => :feature