Class: Autotest::Rspec2

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initializeRspec2

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_execObject



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.expand_path(filename)] = []
    result
  end
end

#require_rubygemsObject



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

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

#setup_rspec_project_mappingsObject



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

Returns:

  • (Boolean)


62
63
64
# File 'lib/autotest/rspec2.rb', line 62

def using_bundler?
  File.exists?('./Gemfile')
end