gpt4 book ai didi

ruby-on-rails - Rails cucumber 未定义方法 `config' 为 nil :NilClass (NoMethodError)

转载 作者:数据小太阳 更新时间:2023-10-29 07:15:26 26 4
gpt4 key购买 nike

我刚刚升级到 ruby​​ 1.9.3-p125(从 1.9.3-p0)。所有测试在升级前都有效。现在我在运行 rake features 时收到以下错误

Using the default profile...
undefined method `config' for nil:NilClass (NoMethodError)
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-rails-1.3.0/lib/cucumber/rails.rb:17:in `<top (required)>'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `require'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `rescue in block in require'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/bundler-1.1.3/lib/bundler/runtime.rb:62:in `block in require'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
/home/map7/pais/config/application.rb:7:in `<top (required)>'
/home/map7/pais/config/environment.rb:2:in `require'
/home/map7/pais/config/environment.rb:2:in `<top (required)>'
/home/map7/pais/features/support/env.rb:8:in `require'
/home/map7/pais/features/support/env.rb:8:in `<top (required)>'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `each'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:175:in `load_step_definitions'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:40:in `run!'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:43:in `execute!'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:20:in `execute'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/cucumber-1.1.9/bin/cucumber:14:in `<top (required)>'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/bin/cucumber:19:in `load'
/home/map7/.rvm/gems/ruby-1.9.3-p194@rails3.2/bin/cucumber:19:in `<main>'
rake aborted!
Command failed with status (1): [/home/map7/.rvm/rubies/ruby-1.9.3-p194/bin...]

Tasks: TOP => features => cucumber => cucumber:ok
(See full trace by running task with --trace)

我追溯到错误中提到的 rails.rb 文件第 17 行:

  if !Rails.application.config.cache_classes
warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb). This setting is known to cause problems with database transactions. Set config.cache_classes to true if you want to use transactions. For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
end

所以看起来它在 cucumber 中找不到 Rails.application。

如果我进入控制台“rails c”并输入 Rails.application.config,它会返回 Configuration 对象。

我已经尝试将我的 cucumber-rails gem 升级到 1.3.0 和 cucumber 1.1.9。

最佳答案

这可能是 cucumber-rails gem 的加载顺序问题。如果您更新您的 Gemfile 不立即加载它,稍后将需要它:

gem "cucumber-rails", "1.3.0", :require => false

关于ruby-on-rails - Rails cucumber 未定义方法 `config' 为 nil :NilClass (NoMethodError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10426175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com