Sha256: e43ae0d32040736f8e76cbde8238676cf6629864889ba19cb9bfc38368b6333b

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require 'autotest'

class Autotest::Rspec < Autotest

  def initialize # :nodoc:
    super
    @spec_command = "spec"
    @test_mappings = {
      %r%^spec/.*\.rb$% => proc { |filename, _|
        filename
      },
      %r%^lib/(.*)\.rb$% => proc { |_, m|
        ["spec/#{m[1]}_spec.rb"]
      },
      %r%^spec/(spec_helper|shared/.*)\.rb$% => proc {
        files_matching %r%^spec/.*_spec\.rb$%
      },
    }
  end
  
  def tests_for_file(filename)
    super.select { |f| @files.has_key? f }
  end

  def handle_results(results)
    failed = results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
    @files_to_test = consolidate_failures failed
    unless @files_to_test.empty? then
      hook :red
    else
      hook :green
    end unless $TESTING
    @tainted = true unless @files_to_test.empty?
  end

  def consolidate_failures(failed)
    filters = Hash.new { |h,k| h[k] = [] }
    failed.each do |spec, failed_trace|
      @files.keys.select{|f| f =~ /spec\//}.each do |f|
        if failed_trace =~ Regexp.new(f)
          filters[f] << spec
          break
        end
      end
    end
    return filters
  end

  def make_test_cmd(files_to_test)
    return "#{ruby} -S #{@spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
  end
  
  def add_options_if_present
    File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
  end

  def spec_command
    spec = File.join(Config::CONFIG['bindir'], 'spec')

    unless File::ALT_SEPARATOR.nil? then
      spec.gsub! File::SEPARATOR, File::ALT_SEPARATOR
    end

    return spec
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
has_finder-0.1.2 spec/rails/vendor/plugins/rspec/lib/autotest/rspec.rb
has_finder-0.1.1 spec/rails/vendor/plugins/rspec/lib/autotest/rspec.rb
has_finder-0.1.3 spec/rails/vendor/plugins/rspec/lib/autotest/rspec.rb
rspec-1.0.5 lib/autotest/rspec.rb