Capybara can't find database records during feature specs
You may have config.use_transactional_fixtures = true
set in your spec_helper.rb
. This would override what you have above.
You want to either remove this line from your spec_helper.rb
or change it there to be false
.
I ran into this same issue and had a very similar config. After looking through the DatabaseCleaner README, I found this small note:
It's also recommended to use
append_after
to ensureDatabaseCleaner.clean
runs after the after-test cleanup capybara/rspec installs.
That means changing your
config.after(:each) do DatabaseCleaner.cleanend
to
config.append_after(:each) do DatabaseCleaner.cleanend
Note the append_after
instead of after
. This fixed my problem.
Working on legacy project I have had such issue, it was caused by switching DatabaseCleaner strategy to :truncation like the following:
config.before(:suite) do DatabaseCleaner.strategy = :truncation DatabaseCleaner.clean Test::Seeder.seed! DatabaseCleaner.strategy = :transactionend
so, removing DatabaseCleaner.strategy = :transaction
helped in my case