Class: Autotest::Rspec

Inherits:
Autotest
  • Object
show all
Defined in:
lib/autotest/rspec.rb

Constant Summary collapse

SPEC_PROGRAM =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec'))

Instance Method Summary collapse

Constructor Details

#initializeRspec

Returns a new instance of Rspec.


23
24
25
26
27
# File 'lib/autotest/rspec.rb', line 23

def initialize
  super
  self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n\n?(.*?(\n\n\(.*?)?)\n\n/m
  self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
end

Instance Method Details

#add_options_if_presentObject

:nodoc:


51
52
53
# File 'lib/autotest/rspec.rb', line 51

def add_options_if_present # :nodoc:
  File.exist?("spec/spec.opts") ? "-O #{File.join('spec','spec.opts')} " : ""
end

#consolidate_failures(failed) ⇒ Object


29
30
31
32
33
34
35
36
37
# File 'lib/autotest/rspec.rb', line 29

def consolidate_failures(failed)
  filters = new_hash_of_arrays
  failed.each do |spec, trace|
    if trace =~ /\n(\.\/)?(.*spec\.rb):[\d]+:/
      filters[$2] << spec
    end
  end
  return filters
end

#make_test_cmd(files_to_test) ⇒ Object


39
40
41
42
# File 'lib/autotest/rspec.rb', line 39

def make_test_cmd(files_to_test)
  files_to_test.empty? ? '' :
    "#{ruby} #{SPEC_PROGRAM} --autospec #{normalize(files_to_test).keys.flatten.join(' ')} #{add_options_if_present}"
end

#normalize(files_to_test) ⇒ Object


44
45
46
47
48
49
# File 'lib/autotest/rspec.rb', line 44

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