【问题标题】:Guard w/ RSpec2, Ruby1.9.3, Rails 3.1.3使用 RSpec2、Ruby1.9.3、Rails 3.1.3 进行防护
【发布时间】:2012-02-12 19:16:10
【问题描述】:

我正在使用 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

【问题讨论】:

    标签: ruby-on-rails-3 guard


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我认为您的Guardfile 中可能包含以下行:

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

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

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

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

      【讨论】:

        猜你喜欢
        • 2014-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-23
        • 1970-01-01
        相关资源
        最近更新 更多