Sha256: 4662a3ab603e99afafa506538b27dc0499c88713058963c5ad8cb1449a3d88d4

Contents?: true

Size: 1.63 KB

Versions: 13

Compression:

Stored size: 1.63 KB

Contents

require 'autotest'
require 'rspec/core/deprecation'

class RSpecCommandError < StandardError; end

class Autotest::Rspec2 < Autotest

  SPEC_PROGRAM = File.expand_path('../../../bin/rspec', __FILE__)

  def initialize
    super()
    clear_mappings
    setup_rspec_project_mappings

    # Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
    # Example for Ruby 1.9: http://rubular.com/r/85ag5AZ2jP
    self.failed_results_re = /^\s*\d+\).*\n\s+(?:\e\[\d*m)?Failure.*(\n(?:\e\[\d*m)?\s+#\s(.*)?:\d+(?::.*)?(?:\e\[\d*m)?)+$/m
    self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
  end

  def setup_rspec_project_mappings
    add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
      filename
    }
    add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
      ["spec/#{m[1]}_spec.rb"]
    }
    add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
      files_matching %r%^spec/.*_spec\.rb$%
    }
  end

  def consolidate_failures(failed)
    filters = new_hash_of_arrays
    failed.each do |spec, trace|
      if trace =~ /(.*spec\.rb)/
        filters[$1] << spec
      end
    end
    return filters
  end

  def make_test_cmd(files_to_test)
    files_to_test.empty? ? '' :
      "#{prefix}#{ruby}#{suffix} -S #{SPEC_PROGRAM} --tty #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
  end

  def normalize(files_to_test)
    files_to_test.keys.inject({}) do |result, filename|
      result[File.expand_path(filename)] = []
      result
    end
  end

  def suffix
    using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : ""
  end

  def using_bundler?
    prefix =~ /bundle exec/
  end

  def gemfile?
    File.exist?('./Gemfile')
  end

end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
rspec-core-2.7.0.rc1 lib/autotest/rspec2.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rspec-core-2.5.1/lib/autotest/rspec2.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rspec-core-2.5.1/lib/autotest/rspec2.rb
rspec-core-2.6.4 lib/autotest/rspec2.rb
rspec-core-2.6.3 lib/autotest/rspec2.rb
rspec-core-2.6.3.beta1 lib/autotest/rspec2.rb
rspec-core-2.6.2.rc lib/autotest/rspec2.rb
rspec-core-2.6.0 lib/autotest/rspec2.rb
rspec-core-2.6.0.rc6 lib/autotest/rspec2.rb
rspec-core-2.5.2 lib/autotest/rspec2.rb
rspec-core-2.6.0.rc4 lib/autotest/rspec2.rb
rspec-core-2.6.0.rc2 lib/autotest/rspec2.rb
rspec-core-2.5.1 lib/autotest/rspec2.rb