Class: Klenod::Test::Suite

Inherits:
Object
  • Object
show all
Defined in:
lib/klenod/test/suite.rb

Instance Method Summary collapse

Constructor Details

#initialize(context:, plugin:) ⇒ Suite

Returns a new instance of Suite.



12
13
14
15
16
17
# File 'lib/klenod/test/suite.rb', line 12

def initialize(context:, plugin:)
  @context = context
  @plugin = plugin
  @dependency_ids = {}
  @failed_test_ids = Set.new
end

Instance Method Details

#collect ⇒ Object



19
20
21
22
23
# File 'lib/klenod/test/suite.rb', line 19

def collect
  test_ids = discover
  test_ids.each { |test_id| index(test_id) }
  selection(test_ids)
end

#update(event) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/klenod/test/suite.rb', line 25

def update(event)
  previous_test_ids = @dependency_ids.keys.to_set
  current_test_ids = discover.to_set
  removed_test_ids = previous_test_ids - current_test_ids
  added_test_ids = current_test_ids - previous_test_ids
  affected_module_ids = update_module_ids(event)
  affected_test_ids =
    @dependency_ids.filter_map do |test_id, dependency_ids|
      test_id if current_test_ids.include?(test_id) && dependency_ids.intersect?(affected_module_ids)
    end

  test_ids = (added_test_ids + affected_test_ids + @failed_test_ids).select { |test_id| current_test_ids.include?(test_id) }
  removed_test_ids.each { |test_id| remove(test_id) }
  test_ids.each { |test_id| index(test_id) }

  selection(test_ids, removed_test_ids)
end