I'm running integration specs using Rspec and Capybara and cleaning out records between specs using Database Cleaner. If it matters, I'm running my specs automatically using Guard and Spork.
Somehow, in the middle of a test run, records are being deleted from the database, causing them to fail. Have I setup Datbase Cleaner incorrectly? Or am I doing something else wrong? I saw this post already, but I don't 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 spec: (notice the 2 puts statements)
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