Class: Autotest::ResultsParser
- Inherits:
-
Object
- Object
- Autotest::ResultsParser
- Defined in:
- lib/autotest/results_parser.rb
Instance Method Summary collapse
-
#[](kind) ⇒ Object
Get a plain result number.
-
#exists? ⇒ Boolean
Determine whether a result exists at all.
-
#framework ⇒ Object
Determine the testing framework used.
-
#get(kind) ⇒ Object
Get a labelled result number.
-
#has?(kind) ⇒ Boolean
Check whether a specific result is present.
-
#initialize(autotest) ⇒ ResultsParser
constructor
Analyze test result lines and return the numbers in a hash.
Constructor Details
#initialize(autotest) ⇒ ResultsParser
Analyze test result lines and return the numbers in a hash.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/autotest/results_parser.rb', line 9 def initialize(autotest) @numbers = {} lines = autotest.results.map {|s| s.gsub(/(\e.*?m|\n)/, '') } # remove escape sequences lines.reject! {|line| !line.match(/\d+\s+(example|test|scenario|step)s?/) } # isolate result numbers lines.each do |line| prefix = nil line.scan(/([1-9]\d*)\s(\w+)/) do |number, kind| kind.sub!(/s$/, '') # singularize kind.sub!(/failure/, 'failed') # homogenize if prefix @numbers["#{prefix}-#{kind}"] = number.to_i else @numbers[kind] = number.to_i prefix = kind end end end end |
Instance Method Details
#[](kind) ⇒ Object
Get a plain result number.
52 53 54 |
# File 'lib/autotest/results_parser.rb', line 52 def [](kind) @numbers[kind] end |
#exists? ⇒ Boolean
Determine whether a result exists at all.
40 41 42 |
# File 'lib/autotest/results_parser.rb', line 40 def exists? !@numbers.empty? end |
#framework ⇒ Object
Determine the testing framework used.
30 31 32 33 34 35 36 |
# File 'lib/autotest/results_parser.rb', line 30 def framework case when @numbers['test'] then 'test-unit' when @numbers['example'] then 'rspec' when @numbers['scenario'] then 'cucumber' end end |
#get(kind) ⇒ Object
Get a labelled result number. The prefix is removed and the label pluralized if necessary.
58 59 60 |
# File 'lib/autotest/results_parser.rb', line 58 def get(kind) "#{@numbers[kind]} #{kind.sub(/^.*-/, '')}#{'s' if @numbers[kind] != 1 && !kind.match(/(ed|ing)$/)}" if @numbers[kind] end |
#has?(kind) ⇒ Boolean
Check whether a specific result is present.
46 47 48 |
# File 'lib/autotest/results_parser.rb', line 46 def has?(kind) @numbers.has_key?(kind) end |