我正在使用Rspec和Capybara运行集成规范,并使用
Database Cleaner清除规范之间的记录.如果重要的话,我会使用Guard和Spork自动运行我的规格.
不知何故,在测试运行过程中,正在从数据库中删除记录,导致它们失败.我是否错误地设置了Datbase Cleaner?或者我做错了什么?我已经看过this post,但我不认为这是我的问题.
任何帮助,将不胜感激!
这是spec_helper.rb
Spork.prefork do # ... RSpec.configure do |config| config.mock_with :rspec config.use_transactional_fixtures = true config.include(MailerMacros) config.treat_symbols_as_Metadata_keys_with_true_values = true config.filter_run :focus => true config.run_all_when_everything_filtered = true config.before(:suite) { DatabaseCleaner.strategy = :truncation } config.before(:each) { DatabaseCleaner.start } config.after(:each) { DatabaseCleaner.clean } end end Spork.each_run do FactoryGirl.reload end
这是我的规范:(注意2放声明)
feature "Claim Firm" do let(:firm) { Factory(:firm,:user_id => nil) } scenario "The details page should show a 'Claim' link",:focus => true do email = 'claimer@foo.com' password = 'secretpass123' u = Factory(:user,:email => email,:password => password,:name => "Bob Claimer") puts "User Count: #{User.count}" # ==> 1 visit login_path puts "User Count: #{User.count}" # ==> 0 # The rest of the spec fails because there are no user records... end end