Class: Crystalball::MapGenerator::AllocatedObjectsStrategy

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
BaseStrategy
Defined in:
lib/crystalball/map_generator/allocated_objects_strategy.rb,
lib/crystalball/map_generator/allocated_objects_strategy/object_tracker.rb

Overview

Map generator strategy to get paths to files contains definition for all objects and its ancestors allocated during test example.

Defined Under Namespace

Classes: ObjectTracker

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseStrategy

#after_register, #after_start, #before_finalize

Constructor Details

#initialize(execution_detector:, object_tracker:) ⇒ AllocatedObjectsStrategy

Returns a new instance of AllocatedObjectsStrategy.

Parameters:

  • execution_detector (#detect)
  • object_tracker (#created_during)


28
29
30
31
# File 'lib/crystalball/map_generator/allocated_objects_strategy.rb', line 28

def initialize(execution_detector:, object_tracker:)
  @object_tracker = object_tracker
  @execution_detector = execution_detector
end

Instance Attribute Details

#execution_detectorObject (readonly)

Returns the value of attribute execution_detector.



15
16
17
# File 'lib/crystalball/map_generator/allocated_objects_strategy.rb', line 15

def execution_detector
  @execution_detector
end

#object_trackerObject (readonly)

Returns the value of attribute object_tracker.



15
16
17
# File 'lib/crystalball/map_generator/allocated_objects_strategy.rb', line 15

def object_tracker
  @object_tracker
end

Class Method Details

.build(only: [], root: Dir.pwd) ⇒ Object



19
20
21
22
23
24
# File 'lib/crystalball/map_generator/allocated_objects_strategy.rb', line 19

def self.build(only: [], root: Dir.pwd)
  hierarchy_fetcher = ObjectSourcesDetector::HierarchyFetcher.new(only)
  execution_detector = ObjectSourcesDetector.new(root_path: root, hierarchy_fetcher: hierarchy_fetcher)

  new(execution_detector: execution_detector, object_tracker: ObjectTracker.new(only_of: only))
end

Instance Method Details

#call(example_map, example) ⇒ Object

Adds to the used files every file which contain the definition of the classes of the objects allocated during the spec execution.

Parameters:

  • example_map (Crystalball::ExampleGroupMap)
    • object holding example metadata and used files

  • example (RSpec::Core::Example)
    • a RSpec example



37
38
39
40
41
42
# File 'lib/crystalball/map_generator/allocated_objects_strategy.rb', line 37

def call(example_map, example)
  classes = object_tracker.used_classes_during do
    yield example_map, example
  end
  example_map.push(*execution_detector.detect(classes))
end