Class: RakeTasks::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_tasks/parser.rb

Overview

This class will handle parsing duties.

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



38
39
40
41
42
43
44
45
46
# File 'lib/rake_tasks/parser.rb', line 38

def initialize
  @data = {
    tests:      0,
    assertions: 0,
    failures:   0,
    errors:     0,
    skips:      0,
  }
end

Instance Method Details

#parse(line) ⇒ Object

Parse a given line. It will be sent to standard out if it meets appropriate criteria. Summary lines are split to provide sums of tests, assertions, etc.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rake_tasks/parser.rb', line 51

def parse(line)
  case line
    when /^[\.EF]+$/, /^Using /, /^Finished (tests )?in \d+/
      puts line.strip #unless line.strip.empty?
    when /^\d+ tests, \d+ assertions, /
      puts line.strip

      data = line.split(', ').map { |x| x.to_i }

      @data[:tests]      += data[0]
      @data[:assertions] += data[1]
      @data[:failures]   += data[2]
      @data[:errors]     += data[3]
      @data[:skips]      += data[4]
  end
end

#summarizeObject

Calculate the summary and send it to standard out.



69
70
71
72
# File 'lib/rake_tasks/parser.rb', line 69

def summarize
  puts "%d tests, %d assertions, %d failures, %d errors, %d skips" %
    @data.values
end