guard/guard — Issue #244: :run_all_begin and :run_all_end don't get called sometimes
Author: relaxdiego
Created: 2012-02-27 07:01:04+00:00
State: open

When I start guard, all tests are run but the run_all hooks don't get triggered. Also, when I go from failed to pass, guard does rerun all tests but, again, the run_all hooks don't get called.

Here's what I have in my .Guardfile:

```ruby
guard 'rspec', :version => 2, :all_after_pass => true 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{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_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('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" }

# Guard#start runs once right after startup
callback(:start_begin) { coverage }
callback(:start_end) { no_coverage }

# Guard#run_all runs
callback(:run_all_begin) { coverage }
callback(:run_all_end) { no_coverage }
end

def coverage
`touch tmp/coverage.txt`
end

def no_coverage
`rm tmp/coverage.txt`
end
```

```bash
$ bundle exec guard --verbose
Guard could not detect any of the supported notification libraries.
Guard is now watching at '/Users/mmaglana/src/mign'
DEBUG (14:50:04): Hook :start_begin executed for Guard::RSpec
DEBUG (14:50:04): Command execution: touch tmp/coverage.txt
Guard::RSpec is running, with RSpec 2!
Running all specs
DEBUG (14:50:04): Command execution: rspec --help
DEBUG (14:50:05): Command execution: bundle exec rspec -f progress -r /Users/mmaglana/.rvm/gems/ruby-1.9.3-p125@mign/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb -f Guard::RSpec::Formatter::NotificationRSpec --out /dev/null --failure-exit-code 2 spec
.

Finished in 0.43448 seconds
1 example, 0 failures
Coverage report generated for RSpec to /Users/mmaglana/src/mign/coverage. 15 / 43 LOC (34.88%) covered.
DEBUG (14:50:07): Hook :start_end executed for Guard::RSpec
DEBUG (14:50:07): Command execution: rm tmp/coverage.txt
DEBUG (14:50:37): Guard::RSpec#run_on_change with ["spec/requests/items_spec.rb"]
DEBUG (14:50:37): Hook :run_on_change_begin executed for Guard::RSpec
Running: spec/requests/items_spec.rb
DEBUG (14:50:37): Command execution: bundle exec rspec -f progress -r /Users/mmaglana/.rvm/gems/ruby-1.9.3-p125@mign/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb -f Guard::RSpec::Formatter::NotificationRSpec --out /dev/null --failure-exit-code 2 spec/requests/items_spec.rb
F

Failures:

1) Items Items index
Failure/Error: page.should have_content(@item2.subject)
NoMethodError:
undefined method `subject' for nil:NilClass
# ./spec/requests/items_spec.rb:12:in `block (2 levels) in '

Finished in 0.38268 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/items_spec.rb:9 # Items Items index
DEBUG (14:50:49): Guard::RSpec#run_on_change with ["spec/requests/items_spec.rb"]
DEBUG (14:50:49): Hook :run_on_change_begin executed for Guard::RSpec
Running: spec/requests/items_spec.rb
DEBUG (14:50:49): Command execution: bundle exec rspec -f progress -r /Users/mmaglana/.rvm/gems/ruby-1.9.3-p125@mign/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb -f Guard::RSpec::Formatter::NotificationRSpec --out /dev/null --failure-exit-code 2 spec/requests/items_spec.rb
.

Finished in 0.38563 seconds
1 example, 0 failures
Running all specs
DEBUG (14:50:51): Command execution: bundle exec rspec -f progress -r /Users/mmaglana/.rvm/gems/ruby-1.9.3-p125@mign/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb -f Guard::RSpec::Formatter::NotificationRSpec --out /dev/null --failure-exit-code 2 spec
.

Finished in 0.3912 seconds
1 example, 0 failures
DEBUG (14:50:52): Hook :run_on_change_end executed for Guard::RSpec
```