Class: FastCov::FixtureKitTracker
- Inherits:
-
AbstractTracker
- Object
- AbstractTracker
- FastCov::FixtureKitTracker
- Defined in:
- lib/fast_cov/trackers/fixture_kit_tracker.rb
Overview
Tracks FixtureKit fixture definition files when fixtures are used.
Fixture definitions run once during cache generation (before(:context)), then every test replays cached SQL without executing Ruby. This tracker uses FixtureKit’s callback hooks to:
-
Connect the fixture file to all source files touched during generation
-
Record the fixture definition file when a test mounts a fixture
Requires fixture_kit >= 0.14.0 (Event-based callbacks).
Register via: coverage_map.use(FastCov::FixtureKitTracker)
Instance Attribute Summary
Attributes inherited from AbstractTracker
Instance Method Summary collapse
Methods inherited from AbstractTracker
#initialize, #on_record, #on_start, #on_stop, #record, record, reset, #root, #start, #stop
Constructor Details
This class inherits a constructor from FastCov::AbstractTracker
Instance Method Details
#install ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fast_cov/trackers/fixture_kit_tracker.rb', line 19 def install gem "fixture_kit", ">= 0.14.0" tracker = self FixtureKit.configure do |config| # When a fixture is about to be generated, start the coverage map # to track what files the fixture definition touches. # This runs in before(:context), before the formatter starts coverage. config.on_cache_save do |_fixture| tracker.coverage_map.start end # After generation, stop coverage and connect the fixture file # to everything it touched. config.on_cache_saved do |fixture, _duration| files = tracker.coverage_map.stop files.each do |file| tracker.coverage_map.connect(from: fixture.path, to: file) end end # When a test mounts a fixture, record the fixture definition file # and any parent fixture files in the chain. config.on_cache_mount do |event| tracker.class.record(event.path) parent = event.fixture.parent while parent tracker.class.record(parent.definition.path) parent = parent.parent end end end end |