开发者

Guard doesn't see file updates

I'm developing a custom engine using this setup.

I've created the engine with

rails plugin new MyEngine --full

Then I've added rspec-rails and guard-rspec as development dependencies with

s.add_development_dependency "rspec-rails"
s.add_development_dependency "guard-rspec"

in my gemspec file.

When I run both rspec and rake spec (with or without bundle exec) my specs run fine. When I run the guard command however it runs all the specs for the first time and then it does not do nothing. It won't detect any file change in the whole app.

The Guardfile is generated as usual with guard init spec, here is its content

# 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

If I keep a shell open with guard running and I do from another shell touch app/my_model.rb nothing happens. The same for every other file(pattern) listed in the Guardfile.开发者_Go百科

Is there any way to debug this kind of issues?

Update I've created a new project (a rails one) and installed the guard-shell gem with this Guardfile

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

Even in this case if I edit any files nothing happens. I'm starting to think that the problem could be somewhere else, maybe in the rb-fsevents gem. What can I check?


The guard file for rspec apparently isn't quite right. It's watching app/controllers, but not app/models.

You'd need a rule like:

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

Change the 2nd part to where your models specs are kept. It's been a while since I used rspec, can't remember the spec directory layout.

Edit:

Also odd, the lib watcher is defined twice? Once at the top and once under rails. I wonder if that 2nd definition is a mistake, and meant to be the rule for app/models.


Ok, don't know what's wrong, but the problem was in fseventd which was in some way frozen.

Running guard without has solved the problem, so the issue wasn't with guard itself

> 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

Moreover a system restart (don't know how to restart the daemon) has "unlocked" the fseventd and now it works again. Maybe it was my fault because did not restarted the system for more than one month...


There also seems to be a bug in the current version 1.2.2, which showed the same symptoms as you described in my environment. Updating to 1.2.3 helped.


In my case, Guard works initially. Then I created a symbolic link to the directory it watches. It stopped.

Suppose it watches "source/example". I created a symbolic link as "source/link_me" -> "source/example". Guard would stay silent too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜