Changeset 1253
- Timestamp:
- 01/09/08 20:23:52 (8 months ago)
- Files:
-
- trunk/autotest/merbsource_rspec.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/autotest/merbsource_rspec.rb
r799 r1253 1 1 require 'autotest' 2 2 3 # cloned from Rspec's autotest settings, but modified to cope w/ Merb's specs directory layout 3 # cloned from Rspec's autotest settings, but modified 4 # to cope w/ Merb's specs directory layout 4 5 5 6 class RspecCommandError < StandardError; end 6 7 7 8 class Autotest::MerbsourceRspec < Autotest 8 9 def initialize(kernel=Kernel, separator=File::SEPARATOR, alt_separator=File::ALT_SEPARATOR) # :nodoc: 10 super() 9 def initialize(kernel = Kernel, separator = File::SEPARATOR, alt_separator = File::ALT_SEPARATOR) # :nodoc: 10 super() # need parens so that Ruby doesn't pass our args 11 # to the superclass version which takes none.. 12 11 13 @kernel, @separator, @alt_separator = kernel, separator, alt_separator 12 14 @spec_command = spec_command 13 15 14 16 # watch out: Ruby bug (1.8.6): 15 17 # %r(/) != /\// 16 18 # since Ruby compares the REGEXP source, not the resulting pattern 17 19 @test_mappings = { 18 %r %^spec/.*_spec\.rb$% => kernel.proc { |filename, _|19 filename 20 %r{^spec/.*_spec\.rb$} => kernel.proc { |filename, _| 21 filename 20 22 }, 21 %r%^lib/merb/(.*)\.rb$% => kernel.proc { |_, m| 22 ["spec/#{m[1]}_spec.rb", "spec/merb/#{m[1]}_spec.rb"] 23 24 %r{^lib/merb/(.*)\.rb$} => kernel.proc { |_, m| 25 ["spec/#{m[1]}_spec.rb", 26 "spec/merb/#{m[1]}_spec.rb"] 23 27 }, 24 %r%^lib/merb/mixins/(.*)\.rb$% => kernel.proc { |_, m| 25 ["spec/#{m[1]}_spec.rb", "spec/merb/#{m[1]}_spec.rb", 26 "spec/merb/#{m[1]}_mixin_spec.rb"] 28 29 %r{^lib/merb/mixins/(.*)\.rb$} => kernel.proc { |_, m| 30 ["spec/#{m[1]}_spec.rb", 31 "spec/merb/#{m[1]}_spec.rb", 32 "spec/merb/#{m[1]}_mixin_spec.rb"] 27 33 }, 28 %r%^lib/merb\.rb$% => kernel.proc { 29 files_matching %r%^spec/.*_spec\.rb$% 34 35 %r{^lib/merb\.rb$} => kernel.proc { 36 files_matching %r{^spec/.*_spec\.rb$} 30 37 }, 31 %r%^spec/(spec_helper|shared/.*)\.rb$% => kernel.proc { 32 files_matching %r%^spec/.*_spec\.rb$% 38 39 %r{^spec/(spec_helper|shared/.*)\.rb$} => kernel.proc { 40 files_matching %r{^spec/.*_spec\.rb$} 33 41 } 34 42 } … … 44 52 results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m) 45 53 end 46 54 47 55 def handle_results(results) 48 56 @files_to_test = consolidate_failures failed_results(results) 49 unless @files_to_test.empty? then 50 hook :red 51 else 52 hook :green 53 end unless $TESTING 57 unless $TESTING 58 if @files_to_test.empty? 59 hook :green 60 else 61 hook :red 62 end 63 end 54 64 @tainted = true unless @files_to_test.empty? 55 65 end … … 58 68 filters = Hash.new { |h,k| h[k] = [] } 59 69 failed.each do |spec, failed_trace| 60 @files.keys.select {|f| f =~ /spec\//}.each do |f|70 @files.keys.select { |f| f =~ /spec\// }.each do |f| 61 71 if failed_trace =~ Regexp.new(f) 62 72 filters[f] << spec … … 65 75 end 66 76 end 67 return filters 68 end 69 70 def make_test_cmd(files_to_test) 71 return "#{ruby} -S #{@spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}" 77 filters 72 78 end 73 79 74 def add_options_if_present75 File.exist?("specs/spec.opts") ? "-O specs/spec.opts " : ""80 def make_test_cmd(files_to_test) 81 "#{ruby} -S #{@spec_command} #{test_cmd_options} #{files_to_test.keys.flatten.join(' ')}" 76 82 end 77 83 84 def test_cmd_options 85 '-O specs/spec.opts' if File.exist?('specs/spec.opts') 86 end 87 78 88 # Finds the proper spec command to use. Precendence 79 89 # is set in the lazily-evaluated method spec_commands. Alias + Override … … 81 91 # then the default paths provided. 82 92 def spec_command 83 spec_commands.each do |command|84 if File.exists?(command)85 return @alt_separator ? (command.gsub @separator, @alt_separator) : command86 end93 if cmd = spec_commands.detect { |c| File.exist? c } 94 @alt_separator ? (cmd.gsub @separator, @alt_separator) : cmd 95 else 96 raise RspecCommandError, 'No spec command could be found!' 87 97 end 88 89 raise RspecCommandError, "No spec command could be found!"90 98 end 91 99 … … 96 104 # * default spec bin/loader installed in Rubygems 97 105 def spec_commands 98 [ 99 File.join('bin', 'spec'), 100 File.join(Config::CONFIG['bindir'], 'spec') 101 ] 106 [File.join('bin', 'spec'), 107 File.join(Config::CONFIG['bindir'], 'spec')] 102 108 end 103 104 109 end
