错误 - 无法加载' guard / rspec'或' '找到Guard :: Rspec类

时间:2015-01-20 13:26:33

标签: ruby-on-rails ruby ruby-on-rails-4 rspec

我通过Ruby on Rails教程(Michael Hartl)学习RoR。

现在我尝试用Guard运行测试。

我的Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.2'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
  gem 'guard-rspec', '2.5.0'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'libnotify', '0.8.0'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

我的警卫档案:

require 'active_support/inflector'

guard 'rspec', all_after_pass: false do

  watch('config/routes.rb')
  # Custom Rails Tutorial specs
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
    ["spec/routing/#{m[1]}_routing_spec.rb",
     "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
     "spec/acceptance/#{m[1]}_spec.rb",
     (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")]
  end
  watch(%r{^app/views/(.+)/}) do |m|
    (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                      "spec/requests/#{m[1].singularize}_pages_spec.rb")
  end
  watch(%r{^app/controllers/sessions_controller\.rb$}) do |m|
    "spec/requests/authentication_pages_spec.rb"
  end

end

当我尝试跑步时:后卫(或捆绑执行警卫队)我得到了错误:

gvyntyk@gvyntyk-r60:~/rails_projects/sample_app$ guard
14:31:28 - INFO - Guard here! It looks like your project has a Gemfile, yet you are running
> [#] `guard` outside of Bundler. If this is your intent, feel free to ignore this
> [#] message. Otherwise, consider using `bundle exec guard` to ensure your
> [#] dependencies are loaded correctly.
> [#] (You can run `guard` with --no-bundler-warning to get rid of this message.)
14:31:29 - ERROR - Could not load 'guard/rspec' or'    ' find class Guard::Rspec
14:31:29 - ERROR - Error is: cannot load such file -- guard/guard
14:31:29 - ERROR - /home/gvyntyk/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in `require'
> [#] /home/gvyntyk/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in `require'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-rspec-2.5.0/lib/guard/rspec.rb:2:in `<top (required)>'
> [#] /home/gvyntyk/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
> [#] /home/gvyntyk/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
> [#] /home/gvyntyk/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/plugin_util.rb:105:in `rescue in plugin_class'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/plugin_util.rb:97:in `plugin_class'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/plugin_util.rb:56:in `initialize_plugin'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/internals/plugins.rb:26:in `add'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/dsl.rb:185:in `block in guard'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/dsl.rb:182:in `each'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/dsl.rb:182:in `guard'
> [#] /home/gvyntyk/rails_projects/sample_app/Guardfile:3:in `evaluate'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/dsl.rb:377:in `instance_eval'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/dsl.rb:377:in `evaluate'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/guardfile/evaluator.rb:90:in `evaluate'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard.rb:134:in `_evaluate'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard.rb:49:in `setup'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/commander.rb:32:in `start'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/cli/environments/valid.rb:16:in `start_guard'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/cli.rb:113:in `start'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/aruba_adapter.rb:32:in `execute'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/lib/guard/aruba_adapter.rb:19:in `execute!'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/gems/guard-2.11.1/bin/guard:11:in `<top (required)>'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/bin/guard:23:in `load'
> [#] /home/gvyntyk/.rvm/gems/ruby-2.0.0-p598@railstutorial_rails_4_0/bin/guard:23:in `<main>'
14:31:29 - ERROR - Invalid Guardfile, original error is: 
> [#] 
> [#] Could not load class: "Rspec", 
> [#] backtrace: 
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/plugin_util.rb:57:in `initialize_plugin'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/internals/plugins.rb:26:in `add'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/dsl.rb:185:in `block in guard'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/dsl.rb:182:in `each'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/dsl.rb:182:in `guard'
> [#]   (dsl)> ./Guardfile:3:in `evaluate'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/dsl.rb:377:in `instance_eval'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/dsl.rb:377:in `evaluate'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/guardfile/evaluator.rb:90:in `evaluate'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard.rb:134:in `_evaluate'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard.rb:49:in `setup'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/commander.rb:32:in `start'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/cli/environments/valid.rb:16:in `start_guard'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/cli.rb:113:in `start'
> [#]   (dsl)> $GEM_PATH[0]/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
> [#]   (dsl)> $GEM_PATH[0]/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
> [#]   (dsl)> $GEM_PATH[0]/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
> [#]   (dsl)> $GEM_PATH[0]/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/aruba_adapter.rb:32:in `execute'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/lib/guard/aruba_adapter.rb:19:in `execute!'
> [#]   (dsl)> $GEM_PATH[0]/gems/guard-2.11.1/bin/guard:11:in `<top (required)>'
> [#]   (dsl)> $GEM_PATH[0]/bin/guard:23:in `load'
> [#]   (dsl)> $GEM_PATH[0]/bin/guard:23:in `<main>'

顺便说一句:

gem list | grep guard
guard (2.11.1)
guard-compat (1.2.1)
guard-rspec (2.5.0)

出了什么问题?

4 个答案:

答案 0 :(得分:13)

这个错误花费了更多时间,我找到了真正的方法

$ cd <appfolder>
$ vim Gemfile

instead of 
gem 'guard-rspec', '2.5.0'
replace on
gem 'guard-rspec', '4.6.0'


instead of 
gem 'rspec-rails', '2.13.1'
replace on
gem 'rspec-rails', '3.3.2'

并且

$ bundle update
$ bundle exec guard init rspec

Guardfile是正确的。

答案 1 :(得分:3)

我遇到了同样的问题并最终得出结论,我的宝石版本中的某些依赖项阻止了我的guard-rspec gem更新到最新版本(4.5.0),而核心防护gem更新为2.12.5。一旦我解决了让我的版本的guard-rspec无法推进的问题,一切都突然就好了。

尝试编辑Gemfile并从中删除所有修复版本(不要删除gem行,只删除版本参数),Rails gem条目除外(保留4.0.2)。然后运行bundle update,看看是否能解决您的问题。

答案 2 :(得分:0)

我也跑过m.Hartl并遇到了这样的问题: 在guard init rspec之后出现错误:

16:31:39 - ERROR - Could not load 'guard/rspec' or '~/.guard/templates/rspec' or find class Guard::Rspec
16:31:39 - ERROR - Error is: No such file or directory - /home/andrey/.guard/templates/rspec

由于我是新手,我花了很多时间来解决这个问题。 据我所知,问题在于rspec 2.13和guard-rspec不兼容,后者需要rspec 2.14或更高版本。 所以最后我只是让bundle update来更新我的宝石。不知道将来它会不会给我带来任何问题,但现在它有效!)

答案 3 :(得分:0)

您可以按照@Igor的说法更新以下内容

$ cd <appfolder>

$ vim Gemfile

代替

gem 'guard-rspec', '2.5.0'

替换

gem 'guard-rspec', '4.6.0'

代替

gem 'rspec-rails', '2.13.1'

替换

gem 'rspec-rails', '3.3.2'

但是,运行rspec时会遇到问题。

所以也要更新以下版本。

代替

gem 'capybara', '2.1.0'

替换为

gem 'capybara', '~> 2.2'