Database_Cleaner Destroying records between HTTP requests in the middle of a specification

I use integration specifications using Rspec and Capybara, and I clear records between specifications using Database Cleaner. If that matters, I automatically run my specs with Guard and Spork.

Be that as it may, in the middle of a test run, records are deleted from the database, which leads to their failure. Did I configure Datbase Cleaner incorrectly? Or am I doing something else wrong? I have already seen this post , but I do not think this is my problem.

Any help would be appreciated!

Here is 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 

And here is my specification: (pay attention to 2 puts clauses)

 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 
+4
source share
1 answer

Not sure what the main reason is, but the truncation strategy for SQLite is optimization, which seems to behave funny in certain situations, so stick with: transaction or: deletion if they are not too slow.

+1
source

Source: https://habr.com/ru/post/1397343/


All Articles