RSpec: An error occurred while loading rails_helper in CI
RSpec could not load spec/rails_helper.rb, which boots the Rails app. Because everything depends on that file, RSpec reports zero examples and prints the underlying error that broke the boot.
What this error means
The whole suite aborts with "An error occurred while loading ./spec/rails_helper.rb" and "Failure/Error: require File.expand_path", followed by the real exception. No examples run.
An error occurred while loading ./spec/rails_helper.rb.
Failure/Error: require File.expand_path('../config/environment', __dir__)
ActiveRecord::NoDatabaseError:
We could not find your database: myapp_testCommon causes
Rails environment fails to boot
A database, missing constant, missing secret, or initializer error prevents config/environment from loading, and rails_helper requires it.
Missing setup in CI
The test database was not created/migrated, or a required ENV var/secret is unset on the runner.
Bad rails_helper customization
Code added to rails_helper (a require, a Capybara/driver setup) raises during load.
How to fix it
Fix the wrapped boot error
- Read the exception printed under the loading message; that is the real failure.
- Prepare the test database and set required secrets/ENV before running specs.
- If a require in rails_helper raises, fix or guard it.
RAILS_ENV=test bin/rails db:prepare
bundle exec rspecHow to prevent it
- Run db:prepare and set required secrets before specs.
- Keep rails_helper requires minimal and resilient.
- Reproduce CI boot locally with RAILS_ENV=test.