Question

I ran into a problem using:

  • Rails (3.2)
  • Rspec (2.14.1)
  • Database Cleaner (1.2.0)

This is what my Rspec configuration looked like:

RSpec.configure do |config|
  config.include Capybara::DSL

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

I would create records in my before(:each) block but I wouldn't see them in my application code.

This would cause problems as objects that I expected to be there weren't.

After many attempts, I finally found the answer to my problem.

Was it helpful?

Solution

The problem was that I was using

config.use_transactional_fixtures = true

After changing that to

config.use_transactional_fixtures = false

The problem stopped occurring and I could finally see records in my application code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top