【问题标题】:Why Guard (rspec) stops working on jruby为什么 Guard (rspec) 停止在 jruby 上工作
【发布时间】:2013-03-03 21:22:50
【问题描述】:

我无法让 Guard 在 jruby 上工作。我已经通过 rvm 在 1.9.3 旁边安装了 jruby。尝试在 1.9.3 上运行 Guard - 工作正常。如何使其在 speclib 的每次更改时自动运行规范?

这是我在运行 bundle exec guard 后得到的,同时没有文件更改

vagrant@precise64:/vagrant/sample$ bundle exec guard
21:16:46 - INFO - Guard uses TerminalTitle to send notifications.
21:16:47 - INFO - Guard::RSpec is running
21:16:47 - INFO - Running all specs
...

Finished in 0.025 seconds
3 examples, 0 failures

21:17:20 - INFO - Guard is now watching at '/vagrant/sample'
before_session hook failed: Errno::ENOENT: No such file or directory - /vagrant/sample
org/jruby/RubyFile.java:333:in `initialize'
(see _pry_.hooks.errors to debug)
[1] guard(main)> 

再次运行规范的唯一方法是在此处按 ENTER。我也无法确定这个No such file or directory 的来源(它不会在 1.9.3 MRI 上弹出)。我不熟悉守卫的内部结构,也无法真正找到发生这种情况的原因。

我的Guardfile 是标准的:

guard 'rspec' do        
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }
end

Gemfile 仅包含:

gem 'rspec', '~>2.13.0'
gem 'guard-rspec'
gem 'rb-inotify', '~>0.9'

【问题讨论】:

    标签: ruby rspec jruby guard specifications


    【解决方案1】:

    before_session 钩子来自 Pry,但 Guard 不使用这种类型的钩子(我们只使用 :when_started 和 :after_eval):

    [1] guard(main)> Pry.hooks
    => #<Pry::Hooks:0x007ff0359a36c0
     @errors=[],
     @hooks=
      {:before_session=>
        [[:default,
          #<Proc:0x007ff0359a3648@/Users/michi/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/pry-0.9.12/lib/pry.rb:11>]],
       :when_started=>
        [[:load_guard_rc,
          #<Proc:0x007ff037a12910@/Users/michi/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/guard-1.6.2/lib/guard/interactor.rb:109>]],
       :after_eval=>
        [[:restore_visibility,
          #<Proc:0x007ff037a126e0@/Users/michi/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/guard-1.6.2/lib/guard/interactor.rb:116>]],
       :after_session=>[],
       :after_read=>[],
       :before_eval=>[]}>
    

    我会提交一个 Pry 错误并在没有交互器 (guard -i) 的情况下运行 Guard,直到修复为止。

    【讨论】:

      【解决方案2】:

      将其添加到您的 Guardfile 中

      # disable Pry for continious integration
      interactor :off
      

      【讨论】:

        猜你喜欢
        • 2014-12-24
        • 1970-01-01
        • 2011-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-30
        • 2018-01-19
        相关资源
        最近更新 更多