Travis CI未能使用RSpec错误构建

时间:2015-10-03 17:40:26

标签: ruby-on-rails ruby rspec travis-ci

我的Travis CI构建在尝试运行RSpec时失败。这是我的.travis.yml

language: ruby
script:
- export RAILS_ENV=test
- bundle exec rake db:create db:schema:load db:test:prepare
- bundle exec rake cucumber
- bundle exec rspec

前三个脚本步骤成功完成,我得到Done. Your build exited with 0.here

但是当我添加第四步(bundle exec rspec)时,我得到Done. Your build exited with 1.here

构建中的错误(uninitialized constant CommentsController (NameError))来自" spec /"中第一个文件的第一行。文件夹(comments_controller_spec.rb)。以下是特拉维斯的错误详情:

$ bundle exec rspec
/home/travis/build/deeprog/goalify/spec/controllers/comments_controller_spec.rb:1:in `<top (required)>': uninitialized constant CommentsController (NameError)
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `load'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `each'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in `setup'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:in `run'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in `run'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:in `invoke'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/exe/rspec:4:in `<top (required)>'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/bin/rspec:23:in `load'
from /home/travis/build/deeprog/goalify/vendor/bundle/ruby/2.2.0/bin/rspec:23:in `<main>'
The command "bundle exec rspec" exited with 1.

我对这个错误感到难过。我已尝试将require 'rails-helper' / require 'spec_helper'添加到规范的顶部,但这并没有帮助。我也试过运行rake而不是bundle exec rspec,但这会产生同样的错误。

该应用目前位于相对根('/goalify'),因此要让测试在本地运行,我必须在config.relative_url_root = nil中设置test.rb。但删除该行并没有在Travis上修复它。我还向Travis添加了任何必需的环境变量。

以下是更多信息:

的Gemfile:

group :development, :test do
  gem 'byebug'
  gem 'cucumber-rails', require: false
  gem 'database_cleaner'
  gem 'factory_girl_rails'
  gem 'rspec-rails'
  gem 'simplecov', require: false
  gem 'spring'
  gem 'spring-commands-rspec'
  gem 'travis'
end

.rspec

--color
--format documentation
--require spec_helper
--require rails_helper

这是source on GitHub

1 个答案:

答案 0 :(得分:1)

感谢@ sam-d指出了答案!

我将require 'rails_helper'添加到comments_controller_spec.rb并开始工作。我认为这很奇怪,因为我在本地不需要额外的require。然后我意识到我的.rspec文件(我将require发送到RSpec的位置)在我的.gitignore文件中 - 所以Travis没有看到包含。我将所有开关添加到脚本部分的第四步,以便我的新travis.yml为:

script:
- export RAILS_ENV=test
- bundle exec rake db:create db:schema:load db:test:prepare
- bundle exec rake cucumber
- bundle exec rspec --color --format documentation --require spec_helper --require rails_helper

现在我从特拉维斯那里得到The command "bundle exec rspec --color --format documentation --require spec_helper --require rails_helper" exited with 0.