Class: FlakyTester::ResultsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky_tester/results_parser.rb

Constant Summary collapse

FAILED_SUITE_REGEX =
/^Failures:$/.freeze
FAILED_TEST_REGEX =
/^rspec (.+:\d+) # .+$/.freeze

Instance Method Summary collapse

Constructor Details

#initializeResultsParser

Returns a new instance of ResultsParser.



6
7
8
9
# File 'lib/flaky_tester/results_parser.rb', line 6

def initialize
  @failed_suite_count = 0
  @failed_test_counts = {}
end

Instance Method Details

#parse(results) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/flaky_tester/results_parser.rb', line 11

def parse(results)
  File.open(results) do |file|
    file.each do |line|
      failed_suite_match_data = FAILED_SUITE_REGEX.match(line)

      if failed_suite_match_data
        @failed_suite_count += 1
        next
      end

      failed_test_match_data = FAILED_TEST_REGEX.match(line)

      if failed_test_match_data
        failed_test = failed_test_match_data[1]
        @failed_test_counts[failed_test] ||= 0
        @failed_test_counts[failed_test] += 1
      end
    end
  end

  message
ensure
  results.close
  results.unlink
end