[CircleCI 2.0] Rails 5.x Fix for bundler: failed to load command: rspec ~ NoMethodError: undefined method `captures' for nil:NilClass Error

Tadashi Shigeoka ·  Thu, October 19, 2017

When running test cases with the bundle exec rspec command on CircleCI 2.0 + Ruby on Rails 5.x, the following error occurred:

CircleCI | サークルシーアイ
bundler: failed to load command: rspec (/home/circleci/yourapp/vendor/bundle/ruby/2.4.0/bin/rspec)
NoMethodError: undefined method `captures' for nil:NilClass

I was able to resolve it successfully, so I’ll introduce the fix method.

Prerequisites

This is based on the following architecture:

  • CircleCI 2.0 (Free plan)
  • Rails 5.1.4
  • Yarn 0.27.5
  • Webpacker 3.0.2

Fix for CircleCI 2.0 Free Plan

Since CircleCI 2.0’s free plan only runs one container, the code TEST_FILES=”$(circleci tests glob “spec/**/*_spec.rb” | circleci tests split —split-by=timings)” was unnecessary.

diff --git a/.circleci/config.yml b/.circleci/config.yml
index 7cd1539..e5a0f8b 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -48,13 +48,10 @@ jobs:
           name: run tests
           command: |
             mkdir /tmp/test-results
-            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
-
             bundle exec rspec --format progress \\
                             --format RspecJunitFormatter \\
                             --out /tmp/test-results/rspec.xml \\
-                            --format progress \\
-                            "${TEST_FILES}"
+                            --format progress
 
       # collect reports
       - store_test_results:

This processing was sample code taken directly from the CircleCI official site. It doesn’t seem very user-friendly that the free plan can’t run immediately.

.circleci/config.yml That Works on Free Plan

Sample code for .circleci/config.yml that works on CircleCI 2.0’s free plan (just 1 container) is written in a separate article [CircleCI 2.0] Rails 5.x + Webpacker Configuration Job Setup Method for Running Rspec Tests, so please refer to that.

That’s all from the Gemba, where I want to run Rails 5.x Rspec on CircleCI 2.0.

Reference Information

That’s all from the Gemba.