3 class Autotest::Rspec < Autotest
5 def initialize # :nodoc:
9 %r%^spec/.*\.rb$% => proc { |filename, _|
12 %r%^lib/(.*)\.rb$% => proc { |_, m|
13 ["spec/#{m[1]}_spec.rb"]
15 %r%^spec/(spec_helper|shared/.*)\.rb$% => proc {
16 files_matching %r%^spec/.*_spec\.rb$%
21 def tests_for_file(filename)
22 super.select { |f| @files.has_key? f }
25 def handle_results(results)
26 failed = results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
27 @files_to_test = consolidate_failures failed
28 unless @files_to_test.empty? then
33 @tainted = true unless @files_to_test.empty?
36 def consolidate_failures(failed)
37 filters = Hash.new { |h,k| h[k] = [] }
38 failed.each do |spec, failed_trace|
39 @files.keys.select{|f| f =~ /spec\//}.each do |f|
40 if failed_trace =~ Regexp.new(f)
49 def make_test_cmd(files_to_test)
50 return "#{ruby} -S #{@spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
53 def add_options_if_present
54 File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
58 spec = File.join(Config::CONFIG['bindir'], 'spec')
60 unless File::ALT_SEPARATOR.nil? then
61 spec.gsub! File::SEPARATOR, File::ALT_SEPARATOR