0

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
Jef
  • 5,424
  • 26
  • 28
  • This looks fine. Are you sure you don't have a typo anywhere? `%r{^lib/(.+)\.rb}` would match `lib/shell/remote_shell.rb` and the capture group would be `shell/remote_shell`, which would be transformed to `spec/shell/remote_shell_spec.rb`. – Netzpirat Dec 23 '13 at 08:06
  • I copy/pasted the code directly from the Guardfile. I also makes the Guardfile output the value of `m[1]` to a file. It seems correct (`shell/remote_shell`). – Jef Dec 23 '13 at 09:44
  • The source code is available here : https://github.com/servebox/electric_sheeps – Jef Dec 23 '13 at 10:25

1 Answers1

2

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.

Netzpirat
  • 5,481
  • 1
  • 22
  • 21