Missing Seed Data

Tests that depend on seed data can interact with the DatabaseCleaner gem’s :truncation strategy.

A common way for this to manifest is for all of your tests to pass up until the first cucumber test runs.

Solano CI’s database setup phase loads your schema, and installs seed data. After time DatabaseCleaner runs its truncation, everything in your database, including your seed data, is gone.

Happily, DatabaseCleaner has functionality to let you keep certain tables/models.

Cucumber Solution

# features/support/env.rb
DatabaseCleaner.strategy = :truncation, {:except => %w[widgets dogs some_other_table]}

If this isn’t flexible enough, you can set up a Cucumber Before hook to load your seed data:

# features/support/seeds.rb
Before do
  load "/app/db/seeds.rb"
end

RSpec Solution

A similar approach of forcibly loading seeds before your examples works for RSpec:

# spec/support/seeds.rb
RSpec.configure do |config|
  config.before(:each) do
    load Rails.root.join("app/db/seeds.rb")
  end
end

You can also try to re-install seeds after examples or scenarios that tear them down. If you have a limited number of cases that use :truncation, targeted re-seeding will lead to faster tests.