Guard看不到文件更新

Fab*_*bio 5 rspec ruby-on-rails guard fsevents rails-engines

我正在使用此设置开发自定义引擎.

我用它创建了引擎

rails plugin new MyEngine --full
Run Code Online (Sandbox Code Playgroud)

然后我添加了rspec-railsguard-rspec作为开发依赖项

s.add_development_dependency "rspec-rails"
s.add_development_dependency "guard-rspec"
Run Code Online (Sandbox Code Playgroud)

在我的gemspec文件中.

当我同时运行rspecrake spec(有或没有bundle exec)我的规格运行正常.当我运行guard命令但它第一次运行所有规格然后它什么都不做.它不会检测整个应用程序中的任何文件更改.

Guardfile像往常一样生成guard init spec,这是它的内容

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

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

  # Rails example
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^lib/(.+)\.rb$})                           { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec/" }
  watch('spec/spec_helper.rb')                        { "spec/" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  # Capybara request specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }
end
Run Code Online (Sandbox Code Playgroud)

如果我保持一个打开的外壳与后卫运行,我从另一个外壳做touch app/my_model.rb任何事情.对于Guardfile中列出的每个其他文件(模式)都是相同的.

有没有办法调试这类问题?

更新 我已经创建了一个新项目(一个rails),并使用它安装了guard-shell gemGuardfile

guard 'shell' do
  watch(%r{(.*)}) {|m| `cat #{m[0]}` }
  watch(%r{(.*)}) {|m| raise m.to_s }
end
Run Code Online (Sandbox Code Playgroud)

即使在这种情况下如果我编辑任何文件也没有任何反应 我开始认为问题可能在其他地方,也许在rb-fsevents宝石中.我能检查什么?

num*_*407 10

rspec的保护文件显然不太正确.它正在观看app/controllers,但不是app/models.

你需要一个像这样的规则:

watch(%r{^app/models/(.+)\.rb$}) {|m| "spec/models/#{m[1]}_spec.rb" }
Run Code Online (Sandbox Code Playgroud)

将第二部分更改为保留模型规格的位置.自从我使用rspec以来已经有一段时间了,无法记住spec目录的布局.

编辑:

同样奇怪的是,lib观察者被定义了两次?一旦在顶部,一旦在轨道下.我想知道第二个定义是否是一个错误,并且意味着它的规则app/models.


Fab*_*bio 1

好吧,不知道出了什么问题,但问题出在 fseventd 中,它在某种程度上被冻结了。

没有运行守卫已经解决了问题,所以问题不在于守卫本身

> guard
Please install rb-fsevent gem for Mac OSX FSEvents support
Using polling (Please help us to support your system better than that.)
Please install growl or growl_notify gem for Mac OS X notification support and add it to your Gemfile
Run Code Online (Sandbox Code Playgroud)

此外,系统重新启动(不知道如何重新启动守护进程)已“解锁”fseventd,现在它再次工作。也许是我的错,因为一个多月没有重启系统了……