NoMethodError:升级到rake 11后的未定义方法`last_comment'

时间:2016-03-09 13:54:46

标签: ruby-on-rails ruby-on-rails-3 rake

运行任何rake任务时,我得到:

  

NoMethodError:

的未定义方法`last_comment'      

这是在bundle update之后推出了新版本的rake版本11.0.1

$ grep rake Gemfile.lock
       rake
       rake (>= 0.8.7)
     rake (11.0.1)
       rake
$ bundle update
$ bundle exec rake db:drop # any rake task
  

NoMethodError:#<未定义的方法`last_comment'耙::应用:0x007ff0cf37be38>

版本

  • Rails 3.2.11
  • Rake 11.0.1

5 个答案:

答案 0 :(得分:142)

Rake 11.0.1 removes Rails 2.3 rspec-core(< 3.4.4)使用的last_comment方法。因此,如果补丁被释放,我们需要将rake引脚到Gemfile中的旧版本:

gem 'rake', '< 11.0'

然后:

$ bundle update
$ grep rake Gemfile.lock 
      rake
      rake (>= 0.8.7)
    rake (10.5.0)
      rake
  rake (< 11.0)

我们现在使用rake 10.5.0,它仍然使用last_comment方法,我们的rake任务将再次运行。

UPDATE :现在已经在rspec中修复了,所以唯一需要的是更新rspec。

答案 1 :(得分:71)

在Rails快速修复中的

可以编辑./Rakefile(在你的app文件夹中)

并在调用Rails.application.load_tasks之前添加这些行:

module TempFixForRakeLastComment
  def last_comment
    last_description
  end 
end
Rake::Application.send :include, TempFixForRakeLastComment

因此整个Rakefile可能看起来像

  require File.expand_path('../config/application', __FILE__)
  require 'rake'
  require 'resque/tasks'

+ # temp fix for NoMethodError: undefined method `last_comment'
+ # remove when fixed in Rake 11.x
+ module TempFixForRakeLastComment
+   def last_comment
+     last_description
+   end 
+ end
+ Rake::Application.send :include, TempFixForRakeLastComment
+ ### end of temfix
+ 
  task "resque:preload" => :environment

  Rails.application.load_tasks

答案 2 :(得分:26)

更新到最新的Rspec gem可以完成工作:

bundle update rspec-rails

答案 3 :(得分:20)

这已经解决了issue in rake

@ equivalent8的回答是一个猴子补丁,应该避免。

正如@Kris指出的那样,这是一个与rake 11.0.1隔离的问题。由于@Kris已经发布了他的答案,因此可以使用Rake的新版本,理想情况下,您可以与时俱进,而不是固定在旧版本的rake上。相信我,我一直在那里,如果你可以帮助它,这不是一个好主意。这也不是Rails 2.3或任何版本的rails的问题。

任何Rake < v11.0.1> v11.0.1 and < v12都可以使用,但这仍然是一种解决方法,也应该避免;理想情况下,你将能够与时俱进。

由于last_comment被弃用,因此应该升级依赖项本身。就我而言,它是rspec-core偶然只在v3.4.4修正了这个问题。

修复

将您的依赖项升级为不会调用last_comment但会调用last_description的版本。它可能rspec并将rspec-core升级到3.4.4或更高版本将解决它。 rspec-core&lt; 3.4.4调用last_comment

如果您的依赖项没有不会调用last_description的版本,请成为一名好公民并提交PR来修复它:)

答案 4 :(得分:20)

只需升级gem rspec-rails

即可

现在:gem 'rspec-rails', '~> 3.5', '>= 3.5.2'

拥抱!

相关问题