2012-08-16 56 views
1

我已经为我的项目添加了一些:js => true测试,并且必须集成database_cleaner gem才能使其工作。现在我的测试,即使是那些不使用数据库的测试也会显着减慢。有没有办法跳过基于模拟/非基于数据库的测试的数据库访问?加速测试没有数据库交互

spec_helper.rb的有关部分

config.before(:suite) do 
     DatabaseCleaner.strategy = :truncation 
    end 

    config.before(:each) do 
     DatabaseCleaner.start 
    end 

    config.after(:each) do 
     DatabaseCleaner.clean 
    end 

回答

0

您可以使用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 

user_spec.rb

describe User, :type => :without_db do 
    it 'should be valid' do 
    should be_valid 
    end 
end