Rake 12.3仍然产生NoMethodError:未定义的方法'last_comment'

时间:2018-01-30 00:20:27

标签: ruby-on-rails ruby rspec rake

NoMethodError: undefined method `last_comment' after upgrading to rake 11

我遇到过上述话题中描述的问题。回顾一下,运行rake会产生以下错误:

NoMethodError: undefined method `last_comment' for #<Rake::Application:0x00000002b15ba0>

上述主题中的共识是'{1}}中不推荐使用'last_comment'方法(替换为'last_description')。

答案声称解决方案是在Gemfile中将rake 11固定到版本10.5,仍然调用'last_comment',或升级到rakerake 12,其中依赖项具有已经解决了。我已经尝试了两种解决方案,但仍然会遇到同样的错误。

更新 rspec >3.5跟踪表明bundle exec正在使用rake的系统gem,其中只有2.9。如何升级系统gem或让捆绑器识别我在gem路径中指定的版本?

的Gemfile

rspec

Gemfile.lock的

gem "rake"
gem "rspec", '>= 3.7'

版本

GEM

remote: https://rubygems.org/
  specs:
    diff-lcs (1.3)
    rake (12.3.0)
    rspec (3.7.0)
      rspec-core (~> 3.7.0)
      rspec-expectations (~> 3.7.0)
      rspec-mocks (~> 3.7.0)
    rspec-core (3.7.1)
      rspec-support (~> 3.7.0)
    rspec-expectations (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-mocks (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-support (3.7.1)

PLATFORMS
  ruby

DEPENDENCIES
  rake
  rspec (>= 3.7)

BUNDLED WITH
   1.16.1  

痕量

当我运行ruby 2.3.1 Rails 4.2.6 rake, version 12.3.0 RSpec 3.7 - rspec-core 3.7.1 - rspec-expectations 3.7.0 - rspec-mocks 3.7.0 - rspec-rails 3.7.2 - rspec-support 3.7.0 时:

rake

当我运行/var/lib/gems/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/rake_task.rb:143:in `initialize' /home/alexander/Documents/Coding/Ruby/learn_ruby/Rakefile:8:in `new' /home/alexander/Documents/Coding/Ruby/learn_ruby/Rakefile:8:in `<top (required)>' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/rake_module.rb:29:in `load' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/rake_module.rb:29:in `load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:703:in `raw_load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:104:in `block in load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:103:in `load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:82:in `block in run' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run' /var/lib/gems/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>' /usr/local/bin/rake:23:in `load' /usr/local/bin/rake:23:in `<main>' 时:

bundle exec rake

当我运行Gem::LoadError: can't activate rspec (~> 2), already activated rspec-3.7.0. Make sure all dependencies are added to Gemfile. /var/lib/gems/2.3.0/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:404:in `block (2 levels) in replace_gem' /home/alexander/Documents/Coding/Ruby/learn_ruby/Rakefile:2:in `<top (required)>' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/rake_module.rb:29:in `load' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/rake_module.rb:29:in `load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:703:in `raw_load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:104:in `block in load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:103:in `load_rakefile' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:82:in `block in run' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling' /var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run' /var/lib/gems/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>' /usr/local/bin/rake:23:in `load' /usr/local/bin/rake:23:in `<main>' 时:

bundle

当我运行Using rake 12.3.0 Using bundler 1.16.1 Using diff-lcs 1.3 Using rspec-support 3.7.1 Using rspec-core 3.7.1 Using rspec-expectations 3.7.0 Using rspec-mocks 3.7.0 Using rspec 3.7.0 时,它说无法找到宝石。

1 个答案:

答案 0 :(得分:0)

最后想出来了:Rakefile指定了rspec ~> 2.9。刚刚删除了版本号,将更新后的rspec更新为3.7,一切运行顺利。