Rake spec passes all tests then fails from non-zero exit code

ruby
rspec
phantomjs

#1

I’ve been working to migrate to 2.0 and this is the last issue I’m having. All our tests prior (bundle exec rspec) pass as well as all tests seem to pass with rake spec:javascript however for some reason there is a non-zero exit after testing. I’ll probably post more information as I troubleshoot more :slight_smile:

#!/bin/bash --login
export RAILS_ENV="test"
bundle exec rake spec:javascript --trace
** Invoke spec:javascript (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute spec:javascript
Running `phantomjs "/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "file:///home/circleci/MyApp/spec/tmp/runner.html?spec="`
Running: file:///home/circleci/MyApp/spec/tmp/runner.html?spec=
Starting...
BusinessRuleApp: 6 of 6 passed.
BusinessTemplateApp: 5 of 5 passed.
hideMessage: 1 of 1 passed.
sendEmailAttachments: 1 of 1 passed.
...
BUNCH OF TESTS HERE THAT ALSO PASS..
...
StateToggleButtonApp: 14 of 14 passed.
StateToggleButtonSvc: 2 of 2 passed.
stateToggleButtons: 17 of 17 passed.
SurveyResponseApp: 83 of 83 passed.

Finished
-----------------
252 specs, 0 failures in 0.527s.

ConsoleReporter finished
Killed
rake aborted!
Error executing command: phantomjs "/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "file:///home/circleci/MyApp/spec/tmp/runner.html?spec="
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:51:in `run_cmd'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:16:in `block in run'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:34:in `override_rails_config'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:9:in `run'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/tasks/jasmine-rails_tasks.rake:7:in `block (2 levels) in <top (required)>'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/task.rb:251:in `call'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/task.rb:251:in `block in execute'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/task.rb:251:in `each'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/task.rb:251:in `execute'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/task.rb:188:in `invoke_with_call_chain'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/task.rb:181:in `invoke'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:153:in `invoke_task'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:109:in `block (2 levels) in top_level'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:109:in `each'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:109:in `block in top_level'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:118:in `run_with_threads'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:103:in `top_level'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:81:in `block in run'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:179:in `standard_exception_handling'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/lib/rake/application.rb:78:in `run'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/exe/rake:27:in `<top (required)>'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/bin/rake:23:in `load'
/home/circleci/MyApp/vendor/bundle/ruby/2.2.0/bin/rake:23:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/cli/exec.rb:75:in `load'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/cli/exec.rb:75:in `kernel_load'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/cli.rb:424:in `exec'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/cli.rb:27:in `dispatch'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/cli.rb:18:in `start'
/usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.16.1/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/site_ruby/2.2.0/bundler/friendly_errors.rb:122:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => spec:javascript
Exited with code 1

And just for a bit more context, we use Ruby 2.2 and here is my circle.yml

# This configuration was automatically generated from a CircleCI 1.0 config.
# It should include any build commands you had along with commands that CircleCI
# inferred from your project structure. We strongly recommend you read all the
# comments in this file to understand the structure of CircleCI 2.0, as the idiom
# for configuration has changed substantially in 2.0 to allow arbitrary jobs rather
# than the prescribed lifecycle of 1.0. In general, we recommend using this generated
# configuration as a reference rather than using it in production, though in most
# cases it should duplicate the execution of your original 1.0 config.
version: 2
jobs:
  build:
    working_directory: ~/MyApp
    parallelism: 2
    shell: /bin/bash --login
    # CircleCI 2.0 does not support environment variables that refer to each other the same way as 1.0 did.
    # If any of these refer to each other, rewrite them so that they don't or see https://circleci.com/docs/2.0/env-vars/#interpolating-environment-variables-to-set-other-environment-variables .
    environment:
      CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
      CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
    # In CircleCI 1.0 we used a pre-configured image with a large number of languages and other packages.
    # In CircleCI 2.0 you can now specify your own image, or use one of our pre-configured images.
    # The following configuration line tells CircleCI to use the specified docker image as the runtime environment for you job.
    # We have selected a pre-built image that mirrors the build environment we use on
    # the 1.0 platform, but we recommend you choose an image more tailored to the needs
    # of each job. For more information on choosing an image (or alternatively using a
    # VM instead of a container) see https://circleci.com/docs/2.0/executor-types/
    # To see the list of pre-built images that CircleCI provides for most common languages see
    # https://circleci.com/docs/2.0/circleci-images/
    docker:
    - image: circleci/ruby:2.2.9-browsers
      command: sudo apt-get update && sudo apt-get install -y mysql-client && cd /usr/local/share &&
        sudo wget https://repo1.maven.org/maven2/com/github/klieber/phantomjs/1.9.0/phantomjs-1.9.0-linux-x86_64.tar.bz2 &&
        sudo tar xjf phantomjs-1.9.0-linux-x86_64.tar.bz2 &&
        sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs &&
        sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs &&
        sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/bin/phantomjs &&
        phantomjs -v
      environment:
        RAILS_ENV: test
        DB_HOST: localhost
        REDIS_HOST: 127.0.0.1
      command: /sbin/init

    # We don't use utf8mb4 because real utf doesn't fit into the index
    #  https://stackoverflow.com/questions/42043205/how-to-fix-mysql-index-column-size-too-large-laravel-migrate
    - image: circleci/mysql:5.6.37-ram
      command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --innodb-large-prefix=true --innodb-file-format=Barracuda --sort-buffer-size=67108864

    - image: redis
    steps:
    # Machine Setup
    #   If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
    # The following `checkout` command checks out your code to your working directory. In 1.0 we did this implicitly. In 2.0 you can choose where in the course of a job your code should be checked out.
    - checkout
    # Prepare for artifact and test results  collection equivalent to how it was done on 1.0.
    # In many cases you can simplify this from what is generated here.
    # 'See docs on artifact collection here https://circleci.com/docs/2.0/artifacts/'
    - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
    # This is based on your 1.0 configuration file or project settings
    - run: mkdir ./tmp
    - run: mkdir ./spec/support/tmp
    # The following line was run implicitly in your 1.0 builds based on what CircleCI inferred about the structure of your project. In 2.0 you need to be explicit about which commands should be run. In some cases you can discard inferred commands if they are not relevant to your project.
    - run: echo -e "export RAILS_ENV=test\nexport RACK_ENV=test" >> $BASH_ENV
    - run: 'bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
        --jobs=4 --retry=3 '
    # The following line was run implicitly in your 1.0 builds based on what CircleCI inferred about the structure of your project. In 2.0 you need to be explicit about which commands should be run. In some cases you can discard inferred commands if they are not relevant to your project.
    - run: |-
        mkdir -p config && echo 'test:
          adapter: mysql2
          database: circle_test
          username: root
          host: 127.0.0.1
        ' > config/database.yml
    - run: |-
        export RAILS_ENV="test"
        export RACK_ENV="test"
        bundle exec rake db:create db:migrate --trace

    # Test
    #   This would typically be a build job when using workflows, possibly combined with build
    # The following line was run implicitly in your 1.0 builds based on what CircleCI inferred about the structure of your project. In 2.0 you need to be explicit about which commands should be run. In some cases you can discard inferred commands if they are not relevant to your project.
    - run: mkdir -p $CIRCLE_TEST_REPORTS/rspec
    - run: |-
        export RAILS_ENV="test"
        export RACK_ENV="test"
        bundle exec rspec --colour --require spec_helper --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/rspec.xml --format progress $(circleci tests glob spec/**/*.rb | circleci tests split)

    # This is based on your 1.0 configuration file or project settings
    - run:
        name: bundle exec rake spec:javascript
        command: |-
          export RAILS_ENV="test"
          bundle exec rake spec:javascript --trace

#2

Check the config(s) of the tools you’re using. Frequently an exit code of 1 like this is being thrown from a post hook, not the specs themselves.


#3

To troubleshoot I installed the local cli which gave me more than just an "Exit with code 1"
https://circleci.com/docs/2.0/local-cli/

The output from that:

Finished
-----------------
252 specs, 0 failures in 0.501s.

ConsoleReporter finished
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Segmentation fault (core dumped)
rake aborted!
Error executing command: phantomjs "/home/circleci/OpenChain/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "file:///home/circleci/OpenChain/spec/tmp/runner.html?spec="
/home/circleci/OpenChain/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:51:in `run_cmd'
/home/circleci/OpenChain/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:16:in `block in run'
/home/circleci/OpenChain/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:34:in `override_rails_config'
/home/circleci/OpenChain/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/jasmine_rails/runner.rb:9:in `run'
/home/circleci/OpenChain/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.4.6/lib/tasks/jasmine-rails_tasks.rake:7:in `block (2 levels) in <top (required)>'
/home/circleci/OpenChain/vendor/bundle/ruby/2.2.0/gems/rake-12.1.0/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => spec:javascript
(See full trace by running task with --trace)
Error: Exited with code 1
Step failed

The temporary solution was to downgrade phantomjs to 1.9.0, Long term chrome headless is in my future. I added this to the circleci.yml

- run: |-
    cd /usr/local/share
    sudo wget https://repo1.maven.org/maven2/com/github/klieber/phantomjs/1.9.0/phantomjs-1.9.0-linux-x86_64.tar.bz2
    sudo tar xjf phantomjs-1.9.0-linux-x86_64.tar.bz2
    sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
    sudo rm /usr/local/bin/phantomjs
    sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
    sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

#4