Class: Autotest::Rspec2
Constant Summary collapse
- SPEC_PROGRAM =
File.(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec'))
Instance Method Summary collapse
- #bundle_exec ⇒ Object
- #consolidate_failures(failed) ⇒ Object
-
#initialize ⇒ Rspec2
constructor
A new instance of Rspec2.
- #make_test_cmd(files_to_test) ⇒ Object
- #normalize(files_to_test) ⇒ Object
- #require_rubygems ⇒ Object
- #setup_rspec_project_mappings ⇒ Object
- #using_bundler? ⇒ Boolean
Constructor Details
#initialize ⇒ Rspec2
Returns a new instance of Rspec2.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/autotest/rspec2.rb', line 9 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+Failure.*(\n\s+#\s(.*)?:\d+(?::.*)?)+$/m self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m end |
Instance Method Details
#bundle_exec ⇒ Object
47 48 49 |
# File 'lib/autotest/rspec2.rb', line 47 def bundle_exec using_bundler? ? "bundle exec " : "" end |
#consolidate_failures(failed) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/autotest/rspec2.rb', line 32 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 |
#make_test_cmd(files_to_test) ⇒ Object
42 43 44 45 |
# File 'lib/autotest/rspec2.rb', line 42 def make_test_cmd(files_to_test) files_to_test.empty? ? '' : "#{bundle_exec}#{ruby} #{require_rubygems}-S #{SPEC_PROGRAM} --tty #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}" end |
#normalize(files_to_test) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/autotest/rspec2.rb', line 55 def normalize(files_to_test) files_to_test.keys.inject({}) do |result, filename| result[File.(filename)] = [] result end end |
#require_rubygems ⇒ Object
51 52 53 |
# File 'lib/autotest/rspec2.rb', line 51 def require_rubygems using_bundler? ? "" : defined?(:Gem) ? "-rrubygems " : " " end |
#setup_rspec_project_mappings ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/autotest/rspec2.rb', line 20 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 |
#using_bundler? ⇒ Boolean
62 63 64 |
# File 'lib/autotest/rspec2.rb', line 62 def using_bundler? File.exists?('./Gemfile') end |