Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / lib / autotest / rspec.rb
blob8f8a4fcdda2947e282c752aabbb20fae1022d8f5
1 require 'autotest'
3 class Autotest::Rspec < Autotest
5   def initialize # :nodoc:
6     super
7     @spec_command = "spec"
8     @test_mappings = {
9       %r%^spec/.*\.rb$% => proc { |filename, _|
10         filename
11       },
12       %r%^lib/(.*)\.rb$% => proc { |_, m|
13         ["spec/#{m[1]}_spec.rb"]
14       },
15       %r%^spec/(spec_helper|shared/.*)\.rb$% => proc {
16         files_matching %r%^spec/.*_spec\.rb$%
17       },
18     }
19   end
20   
21   def tests_for_file(filename)
22     super.select { |f| @files.has_key? f }
23   end
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
29       hook :red
30     else
31       hook :green
32     end unless $TESTING
33     @tainted = true unless @files_to_test.empty?
34   end
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)
41           filters[f] << spec
42           break
43         end
44       end
45     end
46     return filters
47   end
49   def make_test_cmd(files_to_test)
50     return "#{ruby} -S #{@spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
51   end
52   
53   def add_options_if_present
54     File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
55   end
57   def spec_command
58     spec = File.join(Config::CONFIG['bindir'], 'spec')
60     unless File::ALT_SEPARATOR.nil? then
61       spec.gsub! File::SEPARATOR, File::ALT_SEPARATOR
62     end
64     return spec
65   end
67 end