Class: Autotest::Rspec2
- Inherits:
-
Autotest
- Object
- Autotest
- Autotest::Rspec2
- Defined in:
- lib/autotest/rspec2.rb
Constant Summary collapse
- RSPEC_EXECUTABLE =
File.('../../../exe/rspec', __FILE__)
Instance Method Summary collapse
-
#consolidate_failures(failed) ⇒ Object
Overrides Autotest’s implementation to read rspec output.
- #gemfile? ⇒ Boolean
-
#initialize ⇒ Rspec2
constructor
A new instance of Rspec2.
-
#make_test_cmd(files_to_test) ⇒ Object
Overrides Autotest’s implementation to generate the rspec command to run.
-
#normalize(files_to_test) ⇒ Object
Generates a map of filenames to Arrays for Autotest.
-
#setup_rspec_project_mappings ⇒ Object
Adds conventional spec-to-file mappings to Autotest configuation.
- #suffix ⇒ Object
- #using_bundler? ⇒ Boolean
Constructor Details
#initialize ⇒ Rspec2
Returns a new instance of Rspec2.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/autotest/rspec2.rb', line 10 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 |
Instance Method Details
#consolidate_failures(failed) ⇒ Object
Overrides Autotest’s implementation to read rspec output
35 36 37 38 39 40 41 42 43 |
# File 'lib/autotest/rspec2.rb', line 35 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 |
#gemfile? ⇒ Boolean
69 70 71 |
# File 'lib/autotest/rspec2.rb', line 69 def gemfile? File.exist?('./Gemfile') end |
#make_test_cmd(files_to_test) ⇒ Object
Overrides Autotest’s implementation to generate the rspec command to run
46 47 48 49 |
# File 'lib/autotest/rspec2.rb', line 46 def make_test_cmd(files_to_test) files_to_test.empty? ? '' : "#{prefix}#{ruby}#{suffix} -S #{RSPEC_EXECUTABLE} --tty #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}" end |
#normalize(files_to_test) ⇒ Object
Generates a map of filenames to Arrays for Autotest
52 53 54 55 56 |
# File 'lib/autotest/rspec2.rb', line 52 def normalize(files_to_test) files_to_test.keys.inject({}) do |result, filename| result.merge!(File.(filename) => []) end end |
#setup_rspec_project_mappings ⇒ Object
Adds conventional spec-to-file mappings to Autotest configuation.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/autotest/rspec2.rb', line 22 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 |
#suffix ⇒ Object
59 60 61 |
# File 'lib/autotest/rspec2.rb', line 59 def suffix using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : "" end |
#using_bundler? ⇒ Boolean
64 65 66 |
# File 'lib/autotest/rspec2.rb', line 64 def using_bundler? prefix =~ /bundle exec/ end |