Guard doesn't see file updates
Asked Answered
L

4

5

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?

Lauree answered 5/9, 2011 at 18:4 Comment(0)
L
1

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

Lauree answered 5/9, 2011 at 19:59 Comment(0)
R
10

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.

Redhot answered 5/9, 2011 at 19:13 Comment(5)
You're right, I'll update the (default) generated file. However that's not the issue. See my edit to the question.Lauree
ah I see... you can run guard with a --debug flag, but I assume you probably tried that already.Redhot
yep, I tried that, thx. I just solved with a system reboot, see my answer.Lauree
for the records, now that everything works again, I see that any change in app/models/foo.rb trigger the right spec. This should be because the rule in the Guardfile match the models/foo.rb part and returns spec/models/foo_spec.rb.Lauree
That makes sense now, looking at the regex again and knowing the real cause of the problem wasn't the matcher. I was thrown as you mentioned models not working, and the inited rules for test/unit do separate the models/controllers. Different authors, I guess.Redhot
L
1

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

Lauree answered 5/9, 2011 at 19:59 Comment(0)
N
0

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.

Norby answered 3/7, 2012 at 9:41 Comment(0)
S
0

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.

Seersucker answered 8/4, 2014 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.