guard / guard-rspec

Guard::RSpec automatically run your specs (much like autotest)
https://rubygems.org/gems/guard-rspec
MIT License
1.31k stars 241 forks source link

Feature request: automatically discovering dependencies #307

Open e2 opened 9 years ago

e2 commented 9 years ago

E.g. if an rb file is modified, it should run all the specs including that file if there are no other matches.

This is most useful for specs not tied to a single *.rb file, e.g. specs with shared examples, or when names do not map directly between impl <-> spec.

webhat commented 9 years ago
I don't know if this should be tagged here, and whether my methodology is sound.

I work with dummy apps in my modules for testing, mostly in spec/rails-app. Each also contains it's own running guard, separated in my top level Guardfile with ignore %r{^spec/rails-app/}. I would actually like changes in my lib/ dir to trigger specs for classes in my dummy app which implement specific functionality in the library.

Currently I run all the specs in the dummy app, by touching spec/rails-app/spec/spec_helper.rb

Here's an example of what I currently do: https://github.com/webhat/paperclip_montage https://github.com/webhat/paperclip_montage/blob/master/config/Guardfile https://github.com/webhat/paperclip_montage/blob/master/spec/rails-app/config/Guardfile # ignore the broken watch on %r{../../lib/paperclip/(.*).rb}

e2 commented 9 years ago

@webhat - I have some suggestions, if I understood correctly.

Actually, something like the touch would be "built-in" part of a "workflows" feature (Guard 3.x?) - and an example of triggers is here: https://github.com/guard/guard/issues/649

In short, I want people to be able to send "signals" or "events" directly to plugins, because there's no sense in queuing filesystem events to do the same. If you used one Guard instance for both tests, you could do what the change Pry does (simulates a changed file by queuing the change directly as a Guard action).

A lengthy response from me (as usual) - let me know if I've said anything useful. Or if I misunderstood something.

webhat commented 9 years ago

:+1: :chdir is exactly the option I was looking for, is there an example of it's usage?

e2 commented 9 years ago

Nope - probably should be documented, but then again - it doesn't have too much magic behind it from a user's perspective.

If your app is e.g. broken down into modules and each has a spec dir, this is how they can be managed from one Guardfile:

%w(frontend backend api).each do |dir|
  group dir.to_sym
    guard :rspec, chdir: dir do
      watch(%r{^#{dir}/spec/.+_spec\.rb$})
    end
  end
end