Permalink
Browse files

Deduce the test name from lib names for Guard

There will still be a need for manual coaching, but this is a quick start.
  • Loading branch information...
1 parent 066725c commit 0b5b06d90651f45f29b65ca57b12d2520d9fff9d @rking rking committed with rking@sharpsaw.org Sep 17, 2012
Showing with 19 additions and 2 deletions.
  1. +19 −2 Guardfile
View
@@ -33,8 +33,24 @@ module ::Guard
end
guard 'bacon' do
- # Example of mapping a lib file to one or more test files
- watch('lib/pry/indent.rb') { 'test/test_indent.rb' }
+ def deduce_test_from(token)
+ "test/test_#{token}.rb"
+ end
+
+ Dir['lib/pry/*.rb'].each do |rb|
+ rb[%r(lib/pry/(.+)\.rb$)]
+ test_rb = deduce_test_from $1
+ if File.exists?(test_rb)
+ watch(rb) { test_rb }
+ else
+ exempt = %w(
+ commands
+ version
+ ).map {|token| deduce_test_from token}
+ puts 'Missing ' + test_rb if
+ ENV['WANT_TEST_COMPLAINTS'] and not exempt.include?(test_rb)
+ end
+ end
watch(%r{^lib/pry/commands/([^.]+)\.rb}) { |m| "test/test_commands/test_#{m[1]}.rb" }
@@ -45,3 +61,4 @@ guard 'bacon' do
watch(%r{^test.*/test_.+\.rb$})
end
+# vim:ft=ruby

0 comments on commit 0b5b06d

Please sign in to comment.