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

前端 未结 4 1414
野趣味
野趣味 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:31

    The correct answer above helped me. Of course, I needed to change some other tests that (wrongly or rightly) assumed a fixture did not exist. For more information: there's some info about this in the Capybara README.

    https://github.com/jnicklas/capybara

    "If you are using a SQL database, it is common to run every test in a transaction, which is rolled back at the end of the test, rspec-rails does this by default out of the box for example. Since transactions are usually not shared across threads, this will cause data you have put into the database in your test code to be invisible to Capybara."

    You can also config RSpec to clean up after your test manually:

    https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Cleanup-after-your-Rspec-tests

提交回复
热议问题