Ruby on rails 无需数据库交互即可加快测试速度
我已经在我的项目中添加了一些Ruby on rails 无需数据库交互即可加快测试速度,ruby-on-rails,rspec,Ruby On Rails,Rspec,我已经在我的项目中添加了一些:js=>true测试,并且必须集成数据库\u cleanergem才能使它工作。现在,我的测试,即使是不使用数据库的测试,也会大大降低速度。有没有一种方法可以跳过模拟/非基于数据库的测试的数据库访问 spec\u helper.rb的相关部分 config.before(:suite) do DatabaseCleaner.strategy = :truncation end config.before(:each) do
:js=>true
测试,并且必须集成数据库\u cleaner
gem才能使它工作。现在,我的测试,即使是不使用数据库的测试,也会大大降低速度。有没有一种方法可以跳过模拟/非基于数据库的测试的数据库访问
spec\u helper.rb的相关部分
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
只有在需要时,才可以使用DatabaseCleaner spec_helper.rb
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
if :without_db != example.metadata[:type]
DatabaseCleaner.start
end
end
config.after(:each) do
if :without_db != example.metadata[:type]
DatabaseCleaner.clean
end
end
用户_spec.rb
describe User, :type => :without_db do
it 'should be valid' do
should be_valid
end
end