3 Autotest.add_hook :initialize do |at|
5 # watch out: Ruby bug (1.8.6):
7 at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
10 at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
11 ["spec/#{m[1]}_spec.rb"]
13 at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
14 at.files_matching %r%^spec/.*_spec\.rb$%
18 class RspecCommandError < StandardError; end
20 class Autotest::Rspec < Autotest
22 def tests_for_file(filename)
23 super.select { |f| @files.has_key? f }
26 alias :specs_for_file :tests_for_file
28 def failed_results(results)
29 results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
32 def handle_results(results)
33 @files_to_test = consolidate_failures failed_results(results)
34 unless @files_to_test.empty? then
39 @tainted = true unless @files_to_test.empty?
42 def consolidate_failures(failed)
43 filters = Hash.new { |h,k| h[k] = [] }
44 failed.each do |spec, failed_trace|
45 @files.keys.select{|f| f =~ /spec\//}.each do |f|
46 if failed_trace =~ Regexp.new(f)
55 def make_test_cmd(files_to_test)
56 return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
59 def add_options_if_present
60 File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
63 # Finds the proper spec command to use. Precendence
64 # is set in the lazily-evaluated method spec_commands. Alias + Override
65 # that in ~/.autotest to provide a different spec command
66 # then the default paths provided.
68 @spec_command ||= spec_commands.each do |command|
69 if File.exists?(command)
70 return @alt_separator ? (command.gsub @separator, @alt_separator) : command
73 raise RspecCommandError, "No spec command could be found!"
76 # Autotest will look for spec commands in the following
77 # locations, in this order:
80 # * default spec bin/loader installed in Rubygems
83 File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
84 File.join(Config::CONFIG['bindir'], 'spec')