Skip to content
Latchkey

RSpec failures (exit 1, "expected ... got ...") in CI

RSpec ran the suite and one or more examples failed, so the process exits 1 and CI marks the job red. The failure block names the example and shows the expected versus actual value; the cause is usually an environment or ordering difference from local.

What this error means

The build ends with "N examples, M failures" and a non-zero exit. Each failure prints "expected: X / got: Y" with a backtrace, often only in CI.

bundler
Failures:

  1) Invoice#total sums line items
     Failure/Error: expect(invoice.total).to eq(100)
       expected: 100
            got: 0
     # ./spec/models/invoice_spec.rb:12

3 examples, 1 failure

Common causes

Random order exposes inter-test coupling

RSpec randomizes order by seed; a test that relied on state from another fails when the order changes in CI.

Environment differences (time, locale, unprepared DB)

CI uses UTC, a fresh database, and freshly resolved gems, so time-, locale-, or data-sensitive expectations diverge from local.

How to fix it

Reproduce the CI seed and conditions

  1. Re-run with the seed RSpec printed to reproduce the order locally.
  2. Prepare the test database and match CI time/locale (TZ=UTC).
  3. Fix the coupled or environment-sensitive example.
Terminal
bundle exec rspec --seed 12345

Bisect an order-dependent failure

Let RSpec narrow the minimal set of examples that triggers the failure.

Terminal
bundle exec rspec --bisect --seed 12345

How to prevent it

  • Keep examples independent so random order is safe.
  • Prepare the database and set a fixed TZ/locale for tests.
  • Pin gem versions so CI and local resolve the same.

Frequently asked questions

What causes ""Failures: ... examples, N failures""?
RSpec randomizes order by seed; a test that relied on state from another fails when the order changes in CI.
How do I fix "Failures: ... examples, N failures"?
Reproduce the CI seed and conditions

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card