Autotest.add_hook :initialize do |at| at.clear_mappings at.add_mapping %r%/^lib/(.*)\.rb$% do |_, m| possible = File.basename(m[1]) files_matching %r%^spec/.*(#{possible}_spec)\.rb$% end at.add_mapping(%r%^spec/.*\_spec.rb$%) {|filename, _| filename } end