Module: Polyrun::SpecQuality::RspecHook
- Defined in:
- lib/polyrun/spec_quality/rspec_hook.rb
Overview
RSpec hooks for per-example spec quality recording.
Class Method Summary collapse
- .ensure_started!(root: nil, output_path: nil) ⇒ Object
- .infer_root ⇒ Object
- .install!(only_if: nil, root: nil, output_path: nil) ⇒ Object
Class Method Details
.ensure_started!(root: nil, output_path: nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/polyrun/spec_quality/rspec_hook.rb', line 32 def ensure_started!(root: nil, output_path: nil) return if Polyrun::SpecQuality.started? Polyrun::SpecQuality.start!( root: root || infer_root, output_path: output_path ) end |
.infer_root ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/polyrun/spec_quality/rspec_hook.rb', line 41 def infer_root if defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root return ::Rails.root.to_s end caller_locations.each do |loc| inferred = Polyrun::Coverage::Rails.infer_root_from_path(loc.path) return inferred if inferred end Dir.pwd end |
.install!(only_if: nil, root: nil, output_path: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/polyrun/spec_quality/rspec_hook.rb', line 7 def install!(only_if: nil, root: nil, output_path: nil) pred = only_if || -> { Polyrun::SpecQuality.enabled? } return unless pred.call require "rspec/core" ensure_started!(root: root, output_path: output_path) ::RSpec.configure do |config| config.before(:each) do |example| next if example.pending? Polyrun::SpecQuality.start_example!( location: example.[:location] || example.location ) end config.after(:each) do |example| Polyrun::SpecQuality.finish_example!( location: example.[:location] || example.location, pending: example.pending? ) end end end |