Factory Girl / Capybara deleting records from database mid-test?

前端 未结 4 1435
野趣味
野趣味 2021-02-19 10:10

Working with RSpec & Capybara, I\'m getting an interesting test failure mode which goes away with a few subtle rearrangements of lines in the test case...stuff that shouldn\

4条回答
  •  情话喂你
    2021-02-19 10:20

    With the help of the Factory Girl mailing list I've found the issue.

    By default RSpec uses transactions to maintain the database in a clean state and each transaction is tied to a thread. Somewhere along the pipeline the visit_page command splits off and the transaction tied to the current thread dies.

    The solution is simple: disable transactions.

    describe "Sessions" do
      self.use_transactional_fixtures = false
    
       it 'no longer uses transactions' do
         #whatever you want
      end
    end
    

    Update for Rails 5.1

    As of Rails 5.1, use_transactional_fixtures is deprecated and should be replaced with use_transactional_tests.

    self.use_transactional_tests = false
    

提交回复
热议问题