Class: Polyrun::Timing::RSpecExampleFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- Polyrun::Timing::RSpecExampleFormatter
- Defined in:
- lib/polyrun/timing/rspec_example_formatter.rb
Overview
Experimental: records absolute_path:line_number => wall seconds per example for Partition::Plan timing_granularity: :example and merge-timing.
Use after RSpec is loaded:
require "polyrun/timing/rspec_example_formatter"
RSpec.configure { |c| c.add_formatter Polyrun::Timing::RSpecExampleFormatter }
Or RSpec.install_example_timing! (output_path: avoids touching ENV).
Default output path: ENV if set, else polyrun_timing_examples.json.
Instance Method Summary collapse
- #close(_notification) ⇒ Object
- #example_finished(notification) ⇒ Object
-
#initialize(output) ⇒ RSpecExampleFormatter
constructor
A new instance of RSpecExampleFormatter.
-
#timing_output_path ⇒ Object
Override in a subclass from …).
Constructor Details
#initialize(output) ⇒ RSpecExampleFormatter
Returns a new instance of RSpecExampleFormatter.
19 20 21 22 |
# File 'lib/polyrun/timing/rspec_example_formatter.rb', line 19 def initialize(output) super @times = {} end |
Instance Method Details
#close(_notification) ⇒ Object
43 44 45 |
# File 'lib/polyrun/timing/rspec_example_formatter.rb', line 43 def close(_notification) File.write(timing_output_path, JSON.pretty_generate(@times)) end |
#example_finished(notification) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/polyrun/timing/rspec_example_formatter.rb', line 24 def example_finished(notification) ex = notification.example result = ex.execution_result return if result.pending? t = result.run_time return unless t path = ex.[:absolute_path] return unless path line = ex.[:line_number] return unless line key = "#{File.(path)}:#{line}" cur = @times[key] @times[key] = cur ? [cur, t].max : t end |
#timing_output_path ⇒ Object
Override in a subclass from …).
48 49 50 |
# File 'lib/polyrun/timing/rspec_example_formatter.rb', line 48 def timing_output_path ENV["POLYRUN_EXAMPLE_TIMING_OUT"] || "polyrun_timing_examples.json" end |