Class: Result

Inherits:
Object
  • Object
show all
Defined in:
lib/autotest/growl/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(autotest) ⇒ Result

Analyze test result lines and return the numbers in a hash.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/autotest/growl/result.rb', line 5

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.



48
49
50
# File 'lib/autotest/growl/result.rb', line 48

def [](kind)
  @numbers[kind]
end

#exists?Boolean

Determine whether a result exists at all.

Returns:

  • (Boolean)


36
37
38
# File 'lib/autotest/growl/result.rb', line 36

def exists?
  !@numbers.empty?
end

#fatal_errorObject

Get the fatal error if any.



60
61
62
# File 'lib/autotest/growl/result.rb', line 60

def fatal_error
  
end

#frameworkObject

Determine the testing framework used.



26
27
28
29
30
31
32
# File 'lib/autotest/growl/result.rb', line 26

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.



54
55
56
# File 'lib/autotest/growl/result.rb', line 54

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.

Returns:

  • (Boolean)


42
43
44
# File 'lib/autotest/growl/result.rb', line 42

def has?(kind)
  @numbers.has_key?(kind)
end