"rspec: command not found" in CI
The rspec executable comes from the rspec-core gem in the bundle. A bare rspec call on a fresh runner has nothing on PATH to run.
What this error means
The test step exits 127 with "rspec: command not found". It works locally because rspec resolves through rbenv/global gems or an existing binstub.
bundler
$ rspec
/bin/sh: 1: rspec: command not foundCommon causes
Not run through Bundler
rspec is only available via the bundle. Without bundle exec or bin/rspec, the command is not on PATH.
rspec not in the bundle
The rspec-rails or rspec gem is missing or in a group not installed in CI (e.g. a test group skipped by a without setting).
Bundle not installed
The test step runs before bundle install, so no gem executables exist yet.
How to fix it
Run rspec through the bundle
- Call bundle exec rspec or bin/rspec.
- Confirm rspec-rails is in the :test group and that group is installed.
- Ensure bundle install ran before the test step.
Terminal
bundle install
bundle exec rspec
# or: bin/rspecHow to prevent it
- Use bundle exec rspec or bin/rspec consistently.
- Do not exclude the test group when CI needs to run tests.
- Install the bundle before invoking rspec.
Related guides
"rails: command not found" in CIFix "rails: command not found" in CI - the rails executable is not on PATH because the bundle was not install…
RSpec: An error occurred while loading rails_helper in CIFix "An error occurred while loading ./spec/rails_helper.rb" in CI - RSpec failed to boot the Rails environme…
"bundle exec: command not found" for a gem binary in CIFix "bundler: command not found: X" / "could not find executable" when running bundle exec in CI - the gem pr…