guard/guard-rspec — Issue #74: Multiple Guard::RSpec instances don't run all files
Author: ashmoran
Created: 2011-11-27 14:34:21+00:00
State: open

I was trying to configure multiple groups as described in the **Running a subset of all specs** section of the [readme][readme], but I found it was only loading files from the last group defined. Here are the `guard "rspec"` blocks I was using:

```ruby
guard "rspec", spec_paths: %w[ spec/decorators spec/presenters ], cli: "--color --format Fuubar" do
watch('spec/spec_helper.rb') { %w[ spec/decorators spec/presenters ] }
watch('spec/environments/decorators.rb') { "spec/decorators" }
watch('spec/environments/presenters.rb') { "spec/presenters" }
watch(%r{^spec/support/(.+)\.rb$}) { %w[ spec/decorators spec/presenters ] }

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

guard "rspec", spec_paths: %w[ spec/models ], cli: "--color --format Fuubar" do
watch('spec/spec_helper.rb') { "spec/models" }
watch('spec/environments/mongoid.rb') { "spec/models" }
watch(%r{^spec/support/(.+)\.rb$}) { "spec/models" }

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

I didn't determine what exact circumstances this did and didn't behave correctly. I looked in the code and figured out that the root cause was the Inspector and Runner objects being singletons (everything being defined on a Module).

I've refactored the code to use instantiable classes, and this appears to solve the problem without introducing any side-effects. I'll send a pull request in a second for you to look over, I had to do a few odd things to make the specs pass.

[readme]: https://github.com/guard/guard-rspec/blob/1f48eb496ff550defd2e37bc8c42d4bbaadcdff7/README.md