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, files, parallel_options) ⇒ Reporter

Returns a new instance of Reporter.



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

def initialize(start_time, seed, seed_used, files, parallel_options)
  @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
  @files = files
  @parallel_options = parallel_options
end

Instance Attribute Details

#failed_examplesObject (readonly)

Returns the value of attribute failed_examples.



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

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.



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

def pending_examples
  @pending_examples
end

Class Method Details

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



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

def from_config(formatter_config, start_time, seed, seed_used, files, parallel_options)
  reporter = new(start_time, seed, seed_used, files, parallel_options)

  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



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

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



125
126
127
128
# File 'lib/turbo_tests/reporter.rb', line 125

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

#example_failed(example) ⇒ Object



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

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

  @all_examples << example
  @failed_examples << example
end

#example_passed(example) ⇒ Object



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

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

  @all_examples << example
end

#example_pending(example) ⇒ Object



106
107
108
109
110
111
# File 'lib/turbo_tests/reporter.rb', line 106

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

  @all_examples << example
  @pending_examples << example
end

#finishObject



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
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/turbo_tests/reporter.rb', line 130

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



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

def group_finished
  delegate_to_formatters(:example_group_finished, nil)
end

#group_started(notification) ⇒ Object



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

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

#message(message) ⇒ Object



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

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

#report(example_groups) ⇒ Object



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

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

#report_number_of_tests(groups) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/turbo_tests/reporter.rb', line 82

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



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/turbo_tests/reporter.rb', line 68

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