PageRenderTime 30ms CodeModel.GetById 19ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/lib/autotest/rspec2.rb

https://github.com/delowong/logstash
Ruby | 73 lines | 51 code | 12 blank | 10 comment | 1 complexity | b0cdc2834771141d5b792d5e5339a10c MD5 | raw file
 1require 'autotest'
 2require 'rspec/core/deprecation'
 3
 4# Derived from the `Autotest` class, extends the `autotest` command to work
 5# with RSpec.
 6#
 7# @note this will be extracted to a separate gem when we release rspec-3.
 8class Autotest::Rspec2 < Autotest
 9
10  RSPEC_EXECUTABLE = File.expand_path('../../../exe/rspec', __FILE__)
11
12  def initialize
13    super()
14    clear_mappings
15    setup_rspec_project_mappings
16
17    # Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
18    # Example for Ruby 1.9: http://rubular.com/r/85ag5AZ2jP
19    self.failed_results_re = /^\s*\d+\).*\n\s+(?:\e\[\d*m)?Failure.*(\n(?:\e\[\d*m)?\s+#\s(.*)?:\d+(?::.*)?(?:\e\[\d*m)?)+$/m
20    self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
21  end
22
23  # Adds conventional spec-to-file mappings to Autotest configuation.
24  def setup_rspec_project_mappings
25    add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
26      filename
27    }
28    add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
29      ["spec/#{m[1]}_spec.rb"]
30    }
31    add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
32      files_matching %r%^spec/.*_spec\.rb$%
33    }
34  end
35
36  # Overrides Autotest's implementation to read rspec output
37  def consolidate_failures(failed)
38    filters = new_hash_of_arrays
39    failed.each do |spec, trace|
40      if trace =~ /(.*spec\.rb)/
41        filters[$1] << spec
42      end
43    end
44    return filters
45  end
46
47  # Overrides Autotest's implementation to generate the rspec command to run
48  def make_test_cmd(files_to_test)
49    files_to_test.empty? ? '' :
50      %|#{prefix}"#{ruby}"#{suffix} -S "#{RSPEC_EXECUTABLE}" --tty #{normalize(files_to_test).keys.flatten.map { |f| %|"#{f}"|}.join(' ')}|
51  end
52
53  # Generates a map of filenames to Arrays for Autotest
54  def normalize(files_to_test)
55    files_to_test.keys.inject({}) do |result, filename|
56      result.merge!(File.expand_path(filename) => [])
57    end
58  end
59
60  private
61
62  def suffix
63    using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : ""
64  end
65
66  def using_bundler?
67    prefix =~ /bundle exec/
68  end
69
70  def gemfile?
71    File.exist?('./Gemfile')
72  end
73end