16

我正在使用 Libnotify 提供的通知成功运行 Guard。

funkdified@funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications.
Guard is now watching at '/home/funkdified/railsprojects/sample_app'
Guard::RSpec is running, with RSpec 2!
Running all specs
...

Finished in 0.06053 seconds
3 examples, 0 failures

如果我修改规范文件,我会在终端和弹出通知中收到有关测试结果的警报。如果我修改控制器文件,测试再次正常运行。但是,当我修改 routes.rb 时,整个事情都浮出水面,Guard 停止正常工作并引发错误。有人有想法么?

错误:

Running: spec/routing
/home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load': cannot load such file -- /home/funkdified/railsprojects/sample_app/spec/routing (LoadError)
    from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
    from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
    from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
    from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
    from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
    from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
    from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun

忘了提一下,如果我杀死 Guard 并重新启动(在更改 routes.rb 之后)然后 Guard 再次正常执行,这表明测试现在失败了:

funkdified@funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications.
Guard is now watching at '/home/funkdified/railsprojects/sample_app'
Guard::RSpec is running, with RSpec 2!
Running all specs
..F

Failures:

  1) PagesController GET 'about' returns http success
     Failure/Error: get 'about'
     ActionController::RoutingError:
       No route matches {:controller=>"pages", :action=>"about"}
     # ./spec/controllers/pages_controller_spec.rb:22:in `block (3 levels) in <top (required)>'

Finished in 0.0576 seconds
3 examples, 1 failure

Failed examples:

rspec ./spec/controllers/pages_controller_spec.rb:21 # PagesController GET 'about' returns http success
4

2 回答 2

30

检查您的spec目录。它应该有一个routing用于路由规范的子目录。如果没有,只需创建一个空的。spec显然,RSpec在运行时不会在其下创建任何子目录rails g rspec:install,但守卫希望它存在。

于 2012-03-16T01:03:39.003 回答
2

我想你可能有以下行Guardfile

watch('config/routes.rb')                           { "spec/routing" }

如果您在 中没有规范spec/routing,则不要将不需要的文件夹放在文件夹中。将行更改为:

watch('config/routes.rb')                           { "spec" }

现在,当您更新routes.rb文件时,您的所有规范都将运行。

于 2013-04-17T14:38:29.510 回答