运行Rspec 2.8时无法将nil转换为String(TypeError)

时间:2012-01-17 06:26:28

标签: ruby-on-rails rspec cucumber

在尝试运行rspec 2.8时,在某些计算机上出现以下错误(而对于其他计算机则运行良好)。

$ rspec spec
/var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/cucumber-rails-0.4.1/lib/cucumber/rails3.rb:3:in `dirname': can't convert nil into String (TypeError)
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/cucumber-rails-0.4.1/lib/cucumber/rails3.rb:3
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/cucumber-rails-0.4.1/lib/cucumber/rails.rb:5
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/bundler-1.1.rc.7/lib/bundler/runtime.rb:74:in `require'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/bundler-1.1.rc.7/lib/bundler/runtime.rb:74:in `require'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/bundler-1.1.rc.7/lib/bundler/runtime.rb:55:in `each'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/bundler-1.1.rc.7/lib/bundler/runtime.rb:55:in `require'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/bundler-1.1.rc.7/lib/bundler.rb:118:in `require'
    from /var/lib/jenkins/jobs/monaqasat_master/workspace/config/application.rb:10
    from /var/lib/jenkins/.rvm/rubies/ree-1.8.7-2011.12/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /var/lib/jenkins/.rvm/rubies/ree-1.8.7-2011.12/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from /var/lib/jenkins/jobs/monaqasat_master/workspace/config/environment.rb:2
    from /var/lib/jenkins/.rvm/rubies/ree-1.8.7-2011.12/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /var/lib/jenkins/.rvm/rubies/ree-1.8.7-2011.12/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from /var/lib/jenkins/jobs/monaqasat_master/workspace/spec/spec_helper.rb:6
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/spork-0.9.0.rc9/lib/spork.rb:24:in `prefork'
    from /var/lib/jenkins/jobs/monaqasat_master/workspace/spec/spec_helper.rb:4
    from /var/lib/jenkins/.rvm/rubies/ree-1.8.7-2011.12/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /var/lib/jenkins/.rvm/rubies/ree-1.8.7-2011.12/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from /var/lib/jenkins/jobs/monaqasat_master/workspace/spec/helpers/tenders_helper_spec.rb:1
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `autorun'
    from /var/lib/jenkins/.rvm/gems/ree-1.8.7-2011.12@monaqasat3/bin/rspec:19

要把事情放在上下文中,这是我们的Gem文件。

group :test, :development do
  gem 'capybara', '~> 0.4.1.2'
  gem 'cucumber-rails'
  gem 'database_cleaner', '0.6.5'
  gem 'email_spec', '~> 1.2.1'
  gem 'parallel_tests', '~> 0.6.7'
  gem 'rspec-rails', '~> 2.8.1'
  gem 'ruby-debug', '0.10.3'
  gem 'shoulda', '3.0.0.beta2'
  gem 'thin', '1.2.7'
  gem 'spork', '~> 0.9.0.rc9'
  gem 'timecop'
end

另一个有趣的部分是黄瓜在被调用时实际上是完美的。

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:5)

这是一个错误。详情可在名为dirname: can't convert nil to string problem的Google论坛讨论中找到。

您可以通过将cucumber-rails升级到最新版本来解决此问题。只需编辑您的Gemfile即可显示:

gem 'cucumber-rails', '>= 1.1.1'