Module: CIHelper::Tools::SpecTimingsRecorder
- Defined in:
- lib/ci_helper/tools/spec_timings_recorder.rb
Overview
Records each example's run time to a flat JSON map ({ "./spec/a_spec.rb" => 0.42 }), the format RunSpecs consumes via --timings-file. RunSpecs wires it in through rspec's --require. It collects timings from an after(:suite) hook, so it writes even when examples fail; and, unlike a formatter, it never joins the formatter list, so rspec still installs the suite's own formatters — including its default progress formatter when none is set.
Class Method Summary collapse
-
.collect ⇒ Object
A node runs only the example ids it was given, but rspec loads the whole file, so all_examples also holds examples filtered out on this node; those never ran and have a nil run_time.
- .install(path) ⇒ Object
Class Method Details
.collect ⇒ Object
A node runs only the example ids it was given, but rspec loads the whole file, so all_examples also holds examples filtered out on this node; those never ran and have a nil run_time. Skip them, otherwise they land as 0.0 and can overwrite real timings on merge.
22 23 24 25 26 27 |
# File 'lib/ci_helper/tools/spec_timings_recorder.rb', line 22 def self.collect RSpec.world.all_examples.each_with_object({}) do |example, timings| run_time = example.execution_result.run_time timings[example.id] = run_time.to_f if run_time end end |
.install(path) ⇒ Object
13 14 15 16 17 |
# File 'lib/ci_helper/tools/spec_timings_recorder.rb', line 13 def self.install(path) RSpec.configure do |config| config.after(:suite) { File.write(path, JSON.dump(SpecTimingsRecorder.collect)) } end end |