Class: TurboTests::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_tests/reporter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, seed, seed_used) ⇒ Reporter

Returns a new instance of Reporter.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/turbo_tests/reporter.rb', line 26

def initialize(start_time, seed, seed_used)
  @formatters = []
  @pending_examples = []
  @failed_examples = []
  @all_examples = []
  @messages = []
  @start_time = start_time
  @seed = seed
  @seed_used = seed_used
  @load_time = 0
  @errors_outside_of_examples_count = 0
end

Instance Attribute Details

#failed_examplesObject (readonly)

Returns the value of attribute failed_examples.



24
25
26
# File 'lib/turbo_tests/reporter.rb', line 24

def failed_examples
  @failed_examples
end

#load_time=(value) ⇒ Object (writeonly)

Sets the attribute load_time

Parameters:

  • value

    the value to set the attribute load_time to.



5
6
7
# File 'lib/turbo_tests/reporter.rb', line 5

def load_time=(value)
  @load_time = value
end

#pending_examplesObject (readonly)

Returns the value of attribute pending_examples.



23
24
25
# File 'lib/turbo_tests/reporter.rb', line 23

def pending_examples
  @pending_examples
end

Class Method Details

.from_config(formatter_config, start_time, seed, seed_used) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/turbo_tests/reporter.rb', line 7

def self.from_config(formatter_config, start_time, seed, seed_used)
  reporter = new(start_time, seed, seed_used)

  formatter_config.each do |config|
    name, outputs = config.values_at(:name, :outputs)

    outputs.map! do |filename|
      filename == "-" ? $stdout : File.open(filename, "w")
    end

    reporter.add(name, outputs)
  end

  reporter
end

Instance Method Details

#add(name, outputs) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/turbo_tests/reporter.rb', line 39

def add(name, outputs)
  outputs.each do |output|
    formatter_class =
      case name
      when "p", "progress"
        RSpec::Core::Formatters::ProgressFormatter
      when "d", "documentation"
        RSpec::Core::Formatters::DocumentationFormatter
      else
        Kernel.const_get(name)
      end

    @formatters << formatter_class.new(output)
  end
end

#error_outside_of_examples(error_message) ⇒ Object



120
121
122
123
# File 'lib/turbo_tests/reporter.rb', line 120

def error_outside_of_examples(error_message)
  @errors_outside_of_examples_count += 1
  message error_message
end

#example_failed(example) ⇒ Object



108
109
110
111
112
113
# File 'lib/turbo_tests/reporter.rb', line 108

def example_failed(example)
  delegate_to_formatters(:example_failed, example.notification)

  @all_examples << example
  @failed_examples << example
end

#example_passed(example) ⇒ Object



95
96
97
98
99
# File 'lib/turbo_tests/reporter.rb', line 95

def example_passed(example)
  delegate_to_formatters(:example_passed, example.notification)

  @all_examples << example
end

#example_pending(example) ⇒ Object



101
102
103
104
105
106
# File 'lib/turbo_tests/reporter.rb', line 101

def example_pending(example)
  delegate_to_formatters(:example_pending, example.notification)

  @all_examples << example
  @pending_examples << example
end

#finishObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/turbo_tests/reporter.rb', line 125

def finish
  end_time = RSpec::Core::Time.now

  @duration = end_time - @start_time
  delegate_to_formatters :stop, RSpec::Core::Notifications::ExamplesNotification.new(self)

  delegate_to_formatters :start_dump, RSpec::Core::Notifications::NullNotification
  delegate_to_formatters(:dump_pending,
    RSpec::Core::Notifications::ExamplesNotification.new(
      self
    ))
  delegate_to_formatters(:dump_failures,
    RSpec::Core::Notifications::ExamplesNotification.new(
      self
    ))
  delegate_to_formatters(:dump_summary,
    RSpec::Core::Notifications::SummaryNotification.new(
      end_time - @start_time,
      @all_examples,
      @failed_examples,
      @pending_examples,
      @load_time,
      @errors_outside_of_examples_count
    ))
  delegate_to_formatters(:seed,
    RSpec::Core::Notifications::SeedNotification.new(
      @seed,
      @seed_used,
    ))
ensure
  delegate_to_formatters :close, RSpec::Core::Notifications::NullNotification
end

#group_finishedObject



91
92
93
# File 'lib/turbo_tests/reporter.rb', line 91

def group_finished
  delegate_to_formatters(:example_group_finished, nil)
end

#group_started(notification) ⇒ Object



87
88
89
# File 'lib/turbo_tests/reporter.rb', line 87

def group_started(notification)
  delegate_to_formatters(:example_group_started, notification)
end

#message(message) ⇒ Object



115
116
117
118
# File 'lib/turbo_tests/reporter.rb', line 115

def message(message)
  delegate_to_formatters(:message, RSpec::Core::Notifications::MessageNotification.new(message))
  @messages << message
end

#report(example_groups) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/turbo_tests/reporter.rb', line 57

def report(example_groups)
  start(example_groups)
  begin
    yield self
  ensure
    finish
  end
end

#report_number_of_tests(groups) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/turbo_tests/reporter.rb', line 77

def report_number_of_tests(groups)
  name = ParallelTests::RSpec::Runner.test_file_name

  num_processes = groups.size
  num_tests = groups.map(&:size).sum
  tests_per_process = (num_processes == 0 ? 0 : num_tests.to_f / num_processes).round

  puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process"
end

#start(example_groups, time = RSpec::Core::Time.now) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/turbo_tests/reporter.rb', line 66

def start(example_groups, time=RSpec::Core::Time.now)
  @start = time
  @load_time = (@start - @start_time).to_f

  report_number_of_tests(example_groups)
  expected_example_count = example_groups.flatten(1).count

  delegate_to_formatters(:seed, RSpec::Core::Notifications::SeedNotification.new(@seed, @seed_used))
  delegate_to_formatters(:start, RSpec::Core::Notifications::StartNotification.new(expected_example_count, @load_time))
end