Description
Environment:
- Ruby 2.3.1
- Guard 2.14.0
- Guard::RSpec 4.7.3
- Atom 1.12.5
- Emacs 25.1
- Gedit 3.22
- Vim 8.0.0086
A while back (2014-ish) Guard::RSpec had both #run_on_modifications and #run_on_additions hooks defined. This was then switched to a single #run_on_changes hook. Using #run_on_changes apparently caused some users (especially those using vim) to experience multiple spec runs for file changes and so the #run_on_changes hook was reverted back to using #run_on_modifications; the #run_on_additions hook was not restored.
Fast forward to today, when I open and save a new file with atom, emacs, gedit or vim I see no test runs. If I touch
the file, or make a further change and save it, the spec runs properly. I should also note that all but emacs are running in their default configuration (no cusomization of save behaviors). Emacs is fairly customized as it's my editor of choice, but save behavior should be the default.
Given the above, if I add the following code block to my Guardfile...
class Guard::RSpec
def run_on_additions(paths)
return false if paths.empty?
_throw_if_failed { runner.run(paths) }
end
end
... creating and saving a new spec file in each of the editors now results in guard-rspec running the newly created spec properly (once). The guard debug output shows only the #run_on_additions hook being triggered. I tried unsuccessfully to investigate further, but it would seem that the Guard implementation may now be smarter about create vs modification events and filters out duplicate/extraneous hooks.
I would be happy to attach a pull request to enable the additions hook if there is interest in it, but thought it best to test the waters first.