Joseph Fakelastname
Joseph Fakelastname

Reputation: 895

rake test fails to run because 'guard' can't be loaded

I'm a beginner at rails and I'm working through Hartl's rails tutorial. I've gotten to the point in chapter 3 where we run

bundle exec rake test

for the first time. I'm getting this error:

$ bundle exec rake test
/Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- guard (LoadError)
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/guard-minitest-2.4.4/lib/minitest/guard_minitest_plugin.rb:4:in `<top (required)>'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/minitest-5.6.0/lib/minitest.rb:91:in `block in load_plugins'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/minitest-5.6.0/lib/minitest.rb:85:in `each'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/minitest-5.6.0/lib/minitest.rb:85:in `load_plugins'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/minitest-5.6.0/lib/minitest.rb:114:in `run'
    from /Users/J/.rvm/gems/ruby-2.2.2/gems/minitest-5.6.0/lib/minitest.rb:56:in `block in autorun'

However, guard is installed:

$ irb
2.2.2 :001 > require 'guard'
 => true
2.2.2 :002 >

My Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :test do
  gem 'minitest-reporters'
  gem 'mini_backtrace'
  gem 'guard-minitest'
end

group :production do
  gem 'rails_12factor'
end

I searched for similar problems on google but I couldn't find anything that helped. Does anybody know what I'm doing wrong?

Upvotes: 3

Views: 2556

Answers (3)

C LOKESH REDDY
C LOKESH REDDY

Reputation: 229

I've just updated the Guard gem versions in my gemfile and it worked magic

Upvotes: 1

Joseph Fakelastname
Joseph Fakelastname

Reputation: 895

Guard-Minitest's README:

Please be sure to have Guard installed before you continue.

The simplest way to install Guard::Minitest is to use Bundler.

Add Guard::Minitest to your Gemfile:

group :development do
  gem 'guard' # NOTE: this is necessary in newer versions
  gem 'guard-minitest'
end

I had to change my Gemfile:

group :test do
  gem 'minitest-reporters'
  gem 'mini_backtrace'
  gem 'guard'
  gem 'guard-minitest'
end

Upvotes: 8

vgoff
vgoff

Reputation: 11313

In your Gemfile the gem "guard" line is missing.

You used bundle exec rake test and that loaded the requirements according to your Gemfile. However in your test using irb, if you did not do bundle exec irb it would have also failed.

Instead, you apparently have the guard gem installed outside of your Bundler and so it worked in IRB.

Upvotes: 2

Related Questions