I created a Gem project and added minitest and guard to the dependencies :
spec.add_development_dependency "minitest", "~> 5.0.7"
spec.add_development_dependency 'guard-minitest'
I'm using minitest-spec so all code under test resides in the lib
directory and all tests in spec
.
I created a Guardfile with the corresponding setup :
guard :minitest do
# with Minitest::Spec
watch(%r{^spec/(.*)_spec\.rb})
watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/spec_helper\.rb}) { 'spec' }
end
Each time I modify a spec (say spec/shell/remote_shell_spec.rb
) the test executes properly.
# Running:
.......
Fabulous run in 0.064205s, 109.0261 runs/s, 529.5554 assertions/s.
7 runs, 34 assertions, 0 failures, 0 errors, 0 skips
The issue is that when I modify the code under test (say lib/shell/remote_shell.rb
) guard detects the change but no test is executed :
# Running:
Finished in 0.000824s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
Looking at your linked source code, I see that your code is placed in lib/electric_sheeps/shell/remote_shell.rb
and not in lib/shell/remote_shell.rb
as indicated, thus your spec must be placed in spec/electric_sheeps/shell/remote_shell_spec.rb
so the mapping works.
You could also rewrite the watcher so it ignores the module folder
guard :minitest do
# with Minitest::Spec
watch(%r{^spec/(.*)_spec\.rb})
watch(%r{^lib/electric_sheeps/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/spec_helper\.rb}) { 'spec' }
end
but then the mapping for lib/electric_sheeps.rb
would not work.