Class: Minitest::TestProf::FactoryDoctorReporter
- Inherits:
-
BaseReporter
- Object
- AbstractReporter
- BaseReporter
- Minitest::TestProf::FactoryDoctorReporter
show all
- Defined in:
- lib/test_prof/factory_doctor/minitest.rb
Overview
Constant Summary
collapse
- SUCCESS_MESSAGE =
'FactoryDoctor says: "Looks good to me!"'
TestProf::Logging::COLORS
Instance Attribute Summary
Attributes inherited from BaseReporter
#io
Instance Method Summary
collapse
#after_test, #before_test, #start
#log
Constructor Details
22
23
24
25
26
27
28
|
# File 'lib/test_prof/factory_doctor/minitest.rb', line 22
def initialize(io = $stdout, options = {})
super
::TestProf::FactoryDoctor.init
@count = 0
@time = 0.0
@example_groups = Hash.new { |h, k| h[k] = [] }
end
|
Instance Method Details
#prerecord(_group, _example) ⇒ Object
30
31
32
|
# File 'lib/test_prof/factory_doctor/minitest.rb', line 30
def prerecord(_group, _example)
::TestProf::FactoryDoctor.start
end
|
#record(example) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/test_prof/factory_doctor/minitest.rb', line 34
def record(example)
::TestProf::FactoryDoctor.stop
return if example.skipped? || ::TestProf::FactoryDoctor.ignore?
result = ::TestProf::FactoryDoctor.result
return unless result.bad?
group_name = example.respond_to?(:klass) ? example.klass : example.class.name
group = {
description: group_name,
location: location_without_line_number(example)
}
@example_groups[group] << {
description: example.name.gsub(/^test_(?:\d+_)?/, ""),
location: location_with_line_number(example),
factories: result.count,
time: result.time
}
@count += 1
@time += result.time
end
|
#report ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/test_prof/factory_doctor/minitest.rb', line 60
def report
return log(:info, SUCCESS_MESSAGE) if @example_groups.empty?
msgs = []
msgs <<
" FactoryDoctor report\n\n Total (potentially) bad examples: \#{@count}\n Total wasted time: \#{@time.duration}\n\n MSG\n\n @example_groups.each do |group, examples|\n msgs << \"\#{group[:description]} (\#{group[:location]})\\n\"\n examples.each do |ex|\n msgs << \" \#{ex[:description]} (\#{ex[:location]}) \" \\\n \"\u2013 \#{pluralize_records(ex[:factories])} created, \" \\\n \"\#{ex[:time].duration}\\n\"\n end\n msgs << \"\\n\"\n end\n\n log :info, msgs.join\nend\n"
|