Ruby guard minitest在测试中的类更改时找不到要执行的测试
我创建了一个Gem项目,并将minitest和guard添加到依赖项中:Ruby guard minitest在测试中的类更改时找不到要执行的测试,ruby,unit-testing,guard,minitest,Ruby,Unit Testing,Guard,Minitest,我创建了一个Gem项目,并将minitest和guard添加到依赖项中: spec.add_development_dependency "minitest", "~> 5.0.7" spec.add_development_dependency 'guard-minitest' 我使用的是minitest规范,所以所有被测试的代码都位于lib目录中,所有测试都位于spec目录中 我使用相应的设置创建了一个Guardfile: guard :minitest do # wit
spec.add_development_dependency "minitest", "~> 5.0.7"
spec.add_development_dependency 'guard-minitest'
我使用的是minitest规范,所以所有被测试的代码都位于lib
目录中,所有测试都位于spec
目录中
我使用相应的设置创建了一个Guardfile:
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
每次修改规范(比如spec/shell/remote\u shell\u spec.rb
)时,测试都会正确执行
# Running:
.......
Fabulous run in 0.064205s, 109.0261 runs/s, 529.5554 assertions/s.
7 runs, 34 assertions, 0 failures, 0 errors, 0 skips
问题是,当我修改测试中的代码(比如lib/shell/remote\u shell.rb
)时,guard会检测到更改,但不会执行任何测试:
# Running:
Finished in 0.000824s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
查看链接的源代码,我看到您的代码位于
lib/electric\u sheeps/shell/remote\u shell.rb
而不是lib/shell/remote\u shell.rb
中,如图所示,因此您的规范必须位于spec/electric\u sheeps/shell/remote\u shell\u spec.rb
中,这样映射就可以工作了
您还可以重写监视程序,使其忽略模块文件夹
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
但是
lib/electric_sheeps.rb的映射将无法工作。这看起来很好。你确定你没有打字错误吗<代码>%r{^lib/(.+)\.rb}
将匹配lib/shell/remote\u shell.rb
,捕获组将是shell/remote\u shell
,它将转换为spec/shell/remote\u shell\u spec.rb
。我直接从Guardfile复制/粘贴代码。我还使Guardfile将m[1]
的值输出到一个文件中。它似乎是正确的(shell/remote\u shell
)。这里提供了源代码:现在看起来很明显。。。谢谢