2

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

I have been encountering the problem described in the thread above. To recap, running rake produces the following error:

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

The consensus in the thread above is that the 'last_comment' method is deprecated in rake 11 (replaced by 'last_description').

The answers claim the solution is to either pin rake to version 10.5 in the Gemfile, which still calls 'last_comment', or upgrade to rake 12 and rspec >3.5, where the dependency has been resolved. I've tried both solutions, and I still get the same error.

Update The bundle exec trace suggests that rake is using the system gem for rspec, which is only 2.9. How do I either upgrade the system gem or get the bundler to recognize the version I've specified in my gem path?

Gemfile

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  

Versions

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

Traces

When I run 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>'

When I run 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>'

When I just run 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

When I run bundle show rspec-rails, it says that it could not find the gem.

  • Perhaps it's not rspec calling `last_comment` now? Can you produce a longer stack trace? – Abe Voelker Jan 30 '18 at 02:43
  • Updated with the trace – magnanimus1994 Jan 30 '18 at 04:54
  • 2
    `rspec-core-2.99.2` would indicate you're using rspec 2.99.2... perhaps you're using system gems instead of bundler? What happens if you do `bundle exec rake`? And `bundle show rspec-rails`? – Abe Voelker Jan 30 '18 at 05:33
  • Updated with this information – magnanimus1994 Jan 30 '18 at 13:41
  • `bundle exec rake` is what you want to get working - do you have a longer stack trace for that error? And does just bare `bundle` work okay (can you share the output?)? I would guess some other gem is doing `gem 'rspec', '~> 2'` at runtime; whatever gem that is will have to be upgraded – Abe Voelker Jan 30 '18 at 15:42
  • I've added the `bundle` output - all the versions are the same as when I just do `rspec --version`, except `rspec-rails` is missing. Any idea why it's not there? – magnanimus1994 Jan 30 '18 at 21:44
  • I've also included the bundle trace. – magnanimus1994 Jan 30 '18 at 21:45
  • Ah if this is for a Rails app you should delete `gem "rspec", '>= 3.7'` from your Gemfile and replace it with `gem "rspec-rails"`. Then execute `bundle` to install it, then `bundle exec rake` to run rake. That might fix it. – Abe Voelker Jan 30 '18 at 23:01

1 Answers1

0

Finally figured this out: the Rakefile specified rspec ~> 2.9. Just deleted the version number, bundle updated rspec to 3.7, and everything ran smoothly.