Class: TestProf::FactoryDoctor::RSpecListener
- Inherits:
-
Object
- Object
- TestProf::FactoryDoctor::RSpecListener
- Includes:
- Logging
- Defined in:
- lib/test_prof/factory_doctor/rspec.rb
Overview
:nodoc:
Constant Summary collapse
- SUCCESS_MESSAGE =
'FactoryDoctor says: "Looks good to me!"'- NOTIFICATIONS =
i[ example_started example_finished ].freeze
Constants included from Logging
Instance Method Summary collapse
- #example_finished(notification) ⇒ Object
- #example_started(_notification) ⇒ Object
-
#initialize ⇒ RSpecListener
constructor
A new instance of RSpecListener.
- #print ⇒ Object
- #stamp! ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ RSpecListener
Returns a new instance of RSpecListener.
19 20 21 22 23 |
# File 'lib/test_prof/factory_doctor/rspec.rb', line 19 def initialize @count = 0 @time = 0.0 @example_groups = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#example_finished(notification) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/test_prof/factory_doctor/rspec.rb', line 29 def example_finished(notification) FactoryDoctor.stop return if notification.example.pending? result = FactoryDoctor.result return unless result.bad? group = notification.example.example_group.parent_groups.last notification.example..merge!( factories: result.count, time: result.time ) @example_groups[group] << notification.example @count += 1 @time += result.time end |
#example_started(_notification) ⇒ Object
25 26 27 |
# File 'lib/test_prof/factory_doctor/rspec.rb', line 25 def example_started(_notification) FactoryDoctor.start end |
#print ⇒ Object
47 48 49 50 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 77 78 79 80 |
# File 'lib/test_prof/factory_doctor/rspec.rb', line 47 def print 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 group_time = examples.sum { |ex| ex.metadata[:time] }\n group_count = examples.sum { |ex| ex.metadata[:factories] }\n\n msgs << \"\#{group.description} (\#{group.metadata[:location]}) \" \\\n \"(\#{pluralize_records(group_count)} created, \" \\\n \"\#{group_time.duration})\\n\"\n\n examples.each do |ex|\n msgs << \" \#{ex.description} (\#{ex.metadata[:location]}) \" \\\n \"\u2013 \#{pluralize_records(ex.metadata[:factories])} created, \" \\\n \"\#{ex.metadata[:time].duration}\\n\"\n end\n msgs << \"\\n\"\n end\n\n log :info, msgs.join\n\n stamp! if FactoryDoctor.stamp?\nend\n" |
#stamp! ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/test_prof/factory_doctor/rspec.rb', line 82 def stamp! stamper = RSpecStamp::Stamper.new examples = Hash.new { |h, k| h[k] = [] } @example_groups.each_value do |bad_examples| bad_examples.each do |example| file, line = example.[:location].split(":") examples[file] << line.to_i end end examples.each do |file, lines| stamper.stamp_file(file, lines.uniq) end msgs = [] msgs << " RSpec Stamp results\n\n Total patches: \#{stamper.total}\n Total files: \#{examples.keys.size}\n\n Failed patches: \#{stamper.failed}\n Ignored files: \#{stamper.ignored}\n MSG\n\n log :info, msgs.join\nend\n" |