rspec-core: Spec fails only on CI (details included)

Generate rails routing spec fails only on CircleCi (details included). I can’t tell why… Happy to do some more legwork to debug if someone points me in the right direction.

The spec:

require 'rails_helper'

RSpec.describe DocsController, type: :routing do
  describe 'routing' do

    it 'routes to #index' do
      expect(:get => '/docs').to route_to('docs#index')
    end

    it 'routes to #new' do
      expect(:get => '/docs/new').to route_to('docs#new')
    end

    it 'routes to #show' do
      expect(:get => '/docs/1').to route_to('docs#show', :id => '1')
    end

    it 'routes to #edit' do
      expect(:get => '/docs/1/edit').to route_to('docs#edit', :id => '1')
    end

    it 'routes to #create' do
      expect(:post => '/docs').to route_to('docs#create')
    end

    it 'routes to #update via PUT' do
      expect(:put => '/docs/1').to route_to('docs#update', :id => '1')
    end

    it 'routes to #update via PATCH' do
      expect(:patch => '/docs/1').to route_to('docs#update', :id => '1')
    end

    it 'routes to #destroy' do
      expect(:delete => '/docs/1').to route_to('docs#destroy', :id => '1')
    end

  end
end

Failure message

#!/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}"
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.5.4/lib/rspec/core/example.rb:124:in `parse_id'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1953:in `extract_location'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1892:in `block in get_files_to_run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/flat_map.rb:7:in `each'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/flat_map.rb:7:in `flat_map'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/flat_map.rb:7:in `flat_map'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1890:in `get_files_to_run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:928:in `files_to_run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:100:in `setup'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:86:in `run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
  /home/circleci/repo/vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/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)>'
The latest bundler is 1.15.3, but you are currently running 1.15.1.
To update, run `gem install bundler`
Exited with code 1

Gems

#!/bin/bash -eo pipefail
bundle install --jobs=4 --retry=3 --path vendor/bundle
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Fetching rake 12.0.0
Fetching concurrent-ruby 1.0.5
Fetching i18n 0.8.6
Installing erubi 1.6.1
Fetching mini_portile2 2.2.0
Fetching rack 2.0.3
Installing mini_portile2 2.2.0
Fetching nio4r 2.1.0
Installing nio4r 2.1.0 with native extensions
Fetching websocket-extensions 0.1.2
Installing rack 2.0.3
Installing websocket-extensions 0.1.2
Fetching mime-types-data 3.2016.0521
Installing mime-types-data 3.2016.0521
Fetching arel 8.0.0
Fetching method_source 0.8.2
Fetching thor 0.19.4
Installing method_source 0.8.2
Installing arel 8.0.0
Installing thor 0.19.4
Using bundler 1.15.1
Fetching pg 0.21.0
Fetching puma 3.9.1
Installing pg 0.21.0 with native extensions
Fetching sass 3.4.25
Installing puma 3.9.1 with native extensions
Installing sass 3.4.25
Fetching tilt 2.0.7
Fetching execjs 2.7.0
Fetching coffee-script-source 1.12.2
Installing execjs 2.7.0
Installing tilt 2.0.7
Installing coffee-script-source 1.12.2
Fetching turbolinks-source 5.0.3
Installing turbolinks-source 5.0.3
Fetching multi_json 1.12.1
Fetching byebug 9.0.6
Installing multi_json 1.12.1
Installing byebug 9.0.6 with native extensions
Fetching public_suffix 2.0.5
Fetching ffi 1.9.18
Installing public_suffix 2.0.5
Fetching rubyzip 1.2.1
Installing rubyzip 1.2.1
Installing ffi 1.9.18 with native extensions
Fetching rspec-support 3.5.0
Installing rspec-support 3.5.0
Fetching diff-lcs 1.3
Fetching dotenv 2.2.1
Fetching bindex 0.5.0
Installing dotenv 2.2.1
Installing bindex 0.5.0 with native extensions
Installing diff-lcs 1.3
Fetching rb-fsevent 0.10.2
Installing rb-fsevent 0.10.2
Fetching ruby_dep 1.5.0
Fetching temple 0.8.0
Fetching erubis 2.7.0
Installing ruby_dep 1.5.0
Installing temple 0.8.0
Fetching sexp_processor 4.10.0
Installing sexp_processor 4.10.0
Installing erubis 2.7.0
Fetching aws-sigv4 1.0.0
Installing aws-sigv4 1.0.0
Fetching jmespath 1.3.1
Installing jmespath 1.3.1
Fetching tzinfo 1.2.3
Fetching nokogiri 1.8.0
Installing tzinfo 1.2.3
Fetching websocket-driver 0.6.5
Installing websocket-driver 0.6.5 with native extensions
Installing nokogiri 1.8.0 with native extensions
Fetching mime-types 3.1
Fetching rack-test 0.6.3
Installing rack-test 0.6.3
Installing mime-types 3.1
Fetching sprockets 3.7.1
Fetching uglifier 3.2.0
Installing sprockets 3.7.1
Installing uglifier 3.2.0
Fetching turbolinks 5.0.1
Fetching coffee-script 2.4.1
Installing turbolinks 5.0.1
Fetching addressable 2.5.1
Installing coffee-script 2.4.1
Fetching rspec-core 3.5.4
Installing addressable 2.5.1
Installing rspec-core 3.5.4
Fetching childprocess 0.7.1
Installing childprocess 0.7.1
Fetching rb-inotify 0.9.10
Installing rb-inotify 0.9.10
Fetching rspec-expectations 3.5.0
Installing rspec-expectations 3.5.0
Fetching rspec-mocks 3.5.0
Installing rspec-mocks 3.5.0
Fetching ruby_parser 3.10.1
Installing ruby_parser 3.10.1
Fetching haml 5.0.1
Installing haml 5.0.1
Fetching aws-sdk-core 2.9.17
Installing aws-sdk-core 2.9.17
Fetching activesupport 5.1.2
Fetching mail 2.6.6
Fetching selenium-webdriver 3.4.3
Installing mail 2.6.6
Installing activesupport 5.1.2
Installing selenium-webdriver 3.4.3
Fetching rspec_junit_formatter 0.3.0
Installing rspec_junit_formatter 0.3.0
Fetching listen 3.1.5
Installing listen 3.1.5
Fetching aws-sdk-resources 2.9.17
Installing aws-sdk-resources 2.9.17
Fetching loofah 2.0.3
Installing loofah 2.0.3
Fetching xpath 2.1.0
Fetching html2haml 2.2.0
Installing xpath 2.1.0
Fetching rails-dom-testing 2.0.3
Installing html2haml 2.2.0
Installing rails-dom-testing 2.0.3
Fetching globalid 0.4.0
Fetching activemodel 5.1.2
Installing globalid 0.4.0
Fetching jbuilder 2.7.0
Installing activemodel 5.1.2
Fetching spring 2.0.2
Installing jbuilder 2.7.0
Installing spring 2.0.2
Fetching aws-sdk 2.9.17
Installing aws-sdk 2.9.17
Fetching rails-html-sanitizer 1.0.3
Installing rails-html-sanitizer 1.0.3
Fetching capybara 2.14.4
Fetching activejob 5.1.2
Fetching spring-watcher-listen 2.0.1
Installing spring-watcher-listen 2.0.1
Installing activejob 5.1.2
Fetching activerecord 5.1.2
Fetching actionview 5.1.2
Installing capybara 2.14.4
Installing activerecord 5.1.2
Installing actionview 5.1.2
Fetching actionpack 5.1.2
Installing actionpack 5.1.2
Fetching actioncable 5.1.2
Fetching actionmailer 5.1.2
Fetching railties 5.1.2
Installing actioncable 5.1.2
Installing actionmailer 5.1.2
Installing railties 5.1.2
Fetching sprockets-rails 3.2.0
Installing sprockets-rails 3.2.0
Fetching rails 5.1.2
Fetching sass-rails 5.0.6
Fetching coffee-rails 4.2.2
Installing rails 5.1.2
Installing coffee-rails 4.2.2
Installing sass-rails 5.0.6
Fetching rspec-rails 3.5.2
Fetching dotenv-rails 2.2.1
Fetching web-console 3.5.1
Installing dotenv-rails 2.2.1
Installing rspec-rails 3.5.2
Fetching haml-rails 1.0.0
Installing web-console 3.5.1
Installing haml-rails 1.0.0
Fetching jquery-rails 4.3.1
Installing jquery-rails 4.3.1
Bundle complete! 22 Gemfile dependencies, 91 gems now installed.
Bundled gems are installed into ./vendor/bundle.
The latest bundler is 1.15.3, but you are currently running 1.15.1.
To update, run `gem install bundler`

Local gems (passing all specs)

rileytg$ bundle | grep rspec
Using rspec-support 3.5.0
Using rspec-core 3.5.4
Using rspec-expectations 3.5.0
Using rspec-mocks 3.5.0
Using rspec_junit_formatter 0.3.0
Using rspec-rails 3.5.2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

I made a sed based fix for filenames with spaces.

- run:
    name: run tests
    command: |
      mkdir -p /tmp/test-results
      TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
      bundle exec rspec --format documentation \
                        --format RspecJunitFormatter \
                        --out /tmp/test-results/rspec.xml \
                        -- $(echo "${TEST_FILES}" | sed -e 's/\n/\\n/' -e 's/ /\ /')

The local error makes sense; when you quote an argument, it gets treated as a single argument, even though there’s a space in it. So rspec "spec/foo_spec.rb spec/bar_spec.rb" is interpreted as running rspec with a single argument (spec/foo_spec.rb spec/bar_spec.rb) which RSpec is treating as a filename and attempting to load.

The problem you’re running into isn’t a problem with RSpec; it’s a problem with your bash script, and we don’t generally provide bash support so I’m going to close this.

It would be good for RSpec to not crash in the way it did, but I can’t repro locally. Please try RSpec 3.6 as I think it might already give you a better error in this case. If it still crashes with no clear error, please provide a way to repro this and we’ll take a stab at improving the failure message in that case.

$(sed -e 's/\n/\\n/' -e 's/ /\ /' <<< "${TEST_FILES}") is a slightly nicer sed syntax if you find the echo pipe ugly!

I get it… Ill report to CircleCI also (this is their script)

The help was much appreciated! Lemme know if theres a cleanup ticket (or some kinda project chore) you want me to take care of.