【问题标题】:Rake 12.3 still produces NoMethodError: undefined method 'last_comment'Rake 12.3 仍然产生 NoMethodError: undefined method 'last_comment'
【发布时间】:2018-07-08 18:55:03
【问题描述】:

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

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

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

上面线程中的共识是'last_comment'方法在rake 11中被弃用(由'last_description'代替)。

答案声称解决方案是将 rake 固定到 Gemfile 中的 10.5 版,它仍然调用“last_comment”,或者升级到 rake 12rspec &gt;3.5,其中的依赖关系已得到解决。我已经尝试了两种解决方案,但仍然遇到相同的错误。

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

宝石文件

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

Gemfile.lock

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

当我运行 bundle show rspec-rails 时,它说找不到 gem。

【问题讨论】:

  • 现在可能不是 rspec 调用 last_comment 了?你能生成更长的堆栈跟踪吗?
  • 已更新跟踪
  • rspec-core-2.99.2 表示您使用的是 rspec 2.99.2...也许您使用的是系统 gems 而不是捆绑程序?如果你这样做bundle exec rake 会发生什么?还有bundle show rspec-rails?
  • 已更新此信息
  • bundle exec rake 是您想要工作的内容 - 您是否有针对该错误的更长堆栈跟踪?并且只是裸bundle 工作正常吗(你能分享输出吗?)?我猜想其他一些 gem 在运行时正在做gem 'rspec', '~&gt; 2';无论是什么宝石都必须升级

标签: ruby-on-rails ruby rspec rake


【解决方案1】:

终于弄明白了:Rakefile 指定了rspec ~&gt; 2.9。刚删了版本号,bundle更新rspec到3.7,一切顺利。

【讨论】:

    猜你喜欢
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2012-02-01
    • 2015-03-19
    • 2016-08-13
    相关资源
    最近更新 更多