2012-02-20 3 views
4

RspecとCapybaraを使用して統合仕様を実行していて、Database Cleanerを使用して仕様間のレコードを消去しています。重要な場合は、GuardとSporkを使用して仕様を自動的に実行しています。Database_Cleaner仕様の途中でHTTPリクエスト間でレコードを破棄する

何らかの形で、テスト実行の途中で、レコードがデータベースから削除され、それらが失敗する原因となります。 Datbase Cleanerを間違ってセットアップしましたか?それとも別のことをやっているのですか?私はすでにthis postを見たが、これは私の問題だとは思わない。

助けていただけたら幸いです!ここで

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 

spec_helper.rbされており、ここで私のスペックです:(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 = '[email protected]' 
    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 
+0

どのデータベースを使用していますか? – bdon

+0

私はテストでSQLiteを使用しています –

+1

DatabaseCleaner.strategyをtransactionまたは:deletionに変更してみてください。 – bdon

答えて

1

わからないが、SQLiteのための切り捨て戦略特定の状況では面白いように見える最適化ですので、あまりにも遅くない場合は、トランザクションまたは:削除してください。

関連する問題