Changeset 1253 for trunk/autotest

Show
Ignore:
Timestamp:
01/09/08 20:23:52 (11 months ago)
Author:
sethrasmuss..@gmail.com
Message:

cleanup and doc autotest file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autotest/merbsource_rspec.rb

    r799 r1253  
    11require 'autotest' 
    22 
    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 
    45 
    56class RspecCommandError < StandardError; end 
    67 
    78class 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     
    1113    @kernel, @separator, @alt_separator = kernel, separator, alt_separator 
    1214    @spec_command = spec_command 
    13  
     15     
    1416    # watch out: Ruby bug (1.8.6): 
    1517    # %r(/) != /\// 
    1618    # since Ruby compares the REGEXP source, not the resulting pattern 
    1719    @test_mappings = { 
    18       %r%^spec/.*_spec\.rb$% => kernel.proc { |filename, _|  
    19         filename  
     20      %r{^spec/.*_spec\.rb$} => kernel.proc { |filename, _| 
     21        filename 
    2022      }, 
    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"] 
    2327      }, 
    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"] 
    2733      }, 
    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$} 
    3037      }, 
    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$} 
    3341      } 
    3442    } 
     
    4452    results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m) 
    4553  end 
    46  
     54   
    4755  def handle_results(results) 
    4856    @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 
    5464    @tainted = true unless @files_to_test.empty? 
    5565  end 
     
    5868    filters = Hash.new { |h,k| h[k] = [] } 
    5969    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| 
    6171        if failed_trace =~ Regexp.new(f) 
    6272          filters[f] << spec 
     
    6575      end 
    6676    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 
    7278  end 
    7379   
    74   def add_options_if_present 
    75     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(' ')}
    7682  end 
    77  
     83   
     84  def test_cmd_options 
     85    '-O specs/spec.opts' if File.exist?('specs/spec.opts') 
     86  end 
     87   
    7888  # Finds the proper spec command to use.  Precendence 
    7989  # is set in the lazily-evaluated method spec_commands.  Alias + Override 
     
    8191  # then the default paths provided. 
    8292  def spec_command 
    83     spec_commands.each do |command| 
    84       if File.exists?(command) 
    85         return @alt_separator ? (command.gsub @separator, @alt_separator) : command 
    86       end 
     93    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!' 
    8797    end 
    88      
    89     raise RspecCommandError, "No spec command could be found!" 
    9098  end 
    9199   
     
    96104  #   * default spec bin/loader installed in Rubygems 
    97105  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')] 
    102108  end 
    103  
    104109end