我是rails的初学者,我正在通过Hartl的rails教程。我已经在第3章中讨论了我们运行
的问题捆绑exec rake测试
第一次。我收到了这个错误:
$ 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'
然而,安装了防护装置:
$ irb
2.2.2 :001 > require 'guard'
=> true
2.2.2 :002 >
我的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
我在谷歌搜索类似的问题,但我找不到任何有用的东西。有人知道我做错了吗?
答案 0 :(得分:8)
Guard-Minitest的自述文件:
在继续之前,请务必安装Guard。
安装Guard :: Minitest的最简单方法是使用Bundler。
将Guard :: Minitest添加到您的Gemfile:
group :development do gem 'guard' # NOTE: this is necessary in newer versions gem 'guard-minitest' end
我不得不改变我的Gemfile:
group :test do
gem 'minitest-reporters'
gem 'mini_backtrace'
gem 'guard'
gem 'guard-minitest'
end
答案 1 :(得分:2)
在Gemfile
gem "guard"
行缺失。
您使用bundle exec rake test
并根据您的Gemfile加载了需求。但是,在使用irb
的测试中,如果您没有执行bundle exec irb
,那么它也会失败。
相反,你显然已经在Bundler之外安装了guard gem,因此它在IRB中工作。
答案 2 :(得分:1)
我刚刚在我的gemfile中更新了Guard gem版本,它运行了魔法