Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 205
Fabio Avatar asked Sep 05 '11 18:09

Fabio


2 Answers

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.

like image 171
numbers1311407 Avatar answered Nov 02 '22 22:11

numbers1311407


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...

like image 28
Fabio Avatar answered Nov 02 '22 22:11

Fabio