LoginSignup
0
0

More than 3 years have passed since last update.

Rakeエラー rake spec rake aborted!

Posted at

Railsでrake specを使い、rspecを実行しましたが、NoMEthodErrorになりました。

仕様

# A sample Gemfile
source "https://rubygems.org"

gem "rspec", ">= 3.0.0"
gem "rake"

Rakefileを作成する

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec

rakeコマンドでspecを実行

$ bundle exec rake spec

エラー

$ bundle exec rake spec
rake aborted!
NoMethodError: undefined method `last_comment' for #<Rake::Application:0x00007fb211222548>
/Users/yuki/rspec_test/Rakefile:3:in `new'
/Users/yuki/rspec_test/Rakefile:3:in `<top (required)>'
/Users/yuki/.rbenv/versions/2.5.1/bin/bundle:23:in `load'
/Users/yuki/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)

解決方法

gemのバージョンを指定し直し、bundleし直しました。

# A sample Gemfile
source "https://rubygems.org"

gem 'rspec', '~> 3.0.0'
gem 'rake', '< 11.0'

するとエラー回避、正常に働きました!

$ bundle exec rake spec
/Users/yuki/.rbenv/versions/2.5.1/bin/ruby -I/Users/yuki/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rspec-core-3.0.4/lib:/Users/yuki/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rspec-support-3.0.4/lib -S /Users/yuki/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rspec-core-3.0.4/exe/rspec ./spec/hello_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Hello
  message return hello

Finished in 0.00169 seconds (files took 0.16417 seconds to load)
1 example, 0 failures

Top 1 slowest examples (0.00114 seconds, 67.4% of total time):
  Hello message return hello
    0.00114 seconds ./spec/hello_spec.rb:4
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0