Rails 5 with 2.0, can't run rspec using multiple containers

rails
paralellism

#1

Hello. We’ve just set up a pretty vanilla Rails 5/postgres Rspec project in Circle.

We experienced this issue where with this run command (This was taken verbatim from the suggested version shown when I created the project): *EDIT: I previously pasted the wrong thing here.

      - run:
          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}"

We see this error:

#!/bin/bash -eo pipefail
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}"
Requested historical based timing, but they are not present.  Falling back to name based sorting
bundler: failed to load command: rspec (/home/circleci/repo/vendor/bundle/ruby/2.4.0/bin/rspec)
NoMethodError: undefined method `captures' for nil:NilClass
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:124:in `parse_id'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:2026:in `extract_location'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1965:in `block in get_files_to_run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/flat_map.rb:7:in `each'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/flat_map.rb:7:in `flat_map'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/flat_map.rb:7:in `flat_map'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1963:in `get_files_to_run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:976:in `files_to_run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1492:in `load_spec_files'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:100:in `setup'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:86:in `run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:71:in `run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:45:in `invoke'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.6.0/exe/rspec:4:in `<top (required)>'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/bin/rspec:23:in `load'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/bin/rspec:23:in `<top (required)>'
Exited with code 1

If we strip out all the circleci stuff that looks like it’s splitting files for use in the multiple containers:

      - run:
          name: run tests
          command: |
            mkdir /tmp/test-results
            bundle exec rspec --format progress \
                            --format RspecJunitFormatter \
                            --out /tmp/test-results/rspec.xml \
                            --format progress \
                            spec

Then the tests run correctly.

This guy had the same problem, but doesn’t care that his workaround doesn’t support multiple containers since he’s using the free version: http://blog.overstuffedgorilla.com/rails-5-x-and-postgresql-on-circleci-2-0/


#2

same issue…


#3

I can confirm this is not just for Rails projects. I have a Ruby gem that also has the same problem. In the OP, I think the content is duplicated. But when I run this:

      - run:
      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}"

I get the failed to load rspec error. Removing the ${TEST_FILES} portion fixes it.


#4

(duplicating my support ticket response with you for others who see this)

Hi Daniel,

I think the issue might be how the rspec command separates flags and files. Can you add a -- separator like so:

bundle exec rspec --format progress \
                --format RspecJunitFormatter \
                --out /tmp/test-results/rspec.xml \
                --format progress \
                -- \
                "${TEST_FILES}"

If this works, can you also share the link to where this was? We’ll need to fix this.


#5

So this issue is with the bash variable expansion. You’ll want to update the command to this:

bundle exec rspec --format progress \
                --format RspecJunitFormatter \
                --out /tmp/test-results/rspec.xml \
                --format progress \
                -- \
                $TEST_FILES

#6

This fixed it for me, as well. Can we look at getting the sample.yml updated provided to us when adding a new project?


#7

Looks like this has been updated in the CircleCi docs, however, the invalid sample file is still being provided on a new app setup (https://circleci.com/setup-project/gh/org/reponame) :frowning:.


#8

Confirmed that the example Eric posted worked for me too. Thanks guys for the solution. @Eric, when is Circle going to stop giving out the wrong config to users setting up new projects?


#9

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.