Class: Minitest::TestProf::FactoryDoctorReporter
- Inherits:
-
BaseReporter
- Object
- AbstractReporter
- BaseReporter
- Minitest::TestProf::FactoryDoctorReporter
- Defined in:
- lib/test_prof/factory_doctor/minitest.rb
Overview
:nodoc:
Constant Summary collapse
- SUCCESS_MESSAGE =
'FactoryDoctor says: "Looks good to me!"'.freeze
Constants included from TestProf::Logging
Instance Attribute Summary
Attributes inherited from BaseReporter
Instance Method Summary collapse
-
#initialize(io = $stdout, options = {}) ⇒ FactoryDoctorReporter
constructor
A new instance of FactoryDoctorReporter.
- #prerecord(_group, _example) ⇒ Object
- #record(example) ⇒ Object
- #report ⇒ Object
Methods inherited from BaseReporter
#after_test, #before_test, #start
Methods included from TestProf::Logging
#build_log_msg, #colorize, #log
Constructor Details
#initialize(io = $stdout, options = {}) ⇒ FactoryDoctorReporter
Returns a new instance of FactoryDoctorReporter.
16 17 18 19 20 21 22 |
# File 'lib/test_prof/factory_doctor/minitest.rb', line 16 def initialize(io = $stdout, = {}) 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
24 25 26 |
# File 'lib/test_prof/factory_doctor/minitest.rb', line 24 def prerecord(_group, _example) ::TestProf::FactoryDoctor.start end |
#record(example) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/test_prof/factory_doctor/minitest.rb', line 28 def record(example) ::TestProf::FactoryDoctor.stop return if example.skipped? || example.fd_ignore? result = ::TestProf::FactoryDoctor.result return unless result.bad? group = { description: example.class.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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/test_prof/factory_doctor/minitest.rb', line 51 def report return log(:info, SUCCESS_MESSAGE) if @example_groups.empty? msgs = [] msgs << <<-MSG.strip_heredoc FactoryDoctor report Total (potentially) bad examples: #{@count} Total wasted time: #{@time.duration} MSG @example_groups.each do |group, examples| msgs << "#{group[:description]} (#{group[:location]})\n" examples.each do |ex| msgs << " #{ex[:description]} (#{ex[:location]}) "\ "– #{pluralize_records(ex[:factories])} created, "\ "#{ex[:time].duration}\n" end msgs << "\n" end log :info, msgs.join end |