Module: AggregateAssertions::AssertionAggregator

Defined in:
lib/aggregate_assertions/assertion_aggregator.rb

Overview

Main entry-point for the interacting with the state of aggregation.

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/aggregate_assertions/assertion_aggregator.rb', line 11

def active?
  !store.nil? && !store.empty?
end

.add_error(error) ⇒ Object



15
16
17
# File 'lib/aggregate_assertions/assertion_aggregator.rb', line 15

def add_error(error)
  store.last.add_error(error)
end

.close_failure_groupObject



23
24
25
# File 'lib/aggregate_assertions/assertion_aggregator.rb', line 23

def close_failure_group
  store.pop
end

.open_failure_group(label = nil) ⇒ Object



19
20
21
# File 'lib/aggregate_assertions/assertion_aggregator.rb', line 19

def open_failure_group(label = nil)
  initialize_store << FailureGroup.new(label: label, location: location)
end

.wrap(label = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aggregate_assertions/assertion_aggregator.rb', line 27

def wrap(label = nil)
  AssertionAggregator.open_failure_group(label)

  begin
    yield
  rescue Minitest::Assertion, StandardError => e
    AssertionAggregator.add_error(e)
  ensure
    failure_group = AssertionAggregator.close_failure_group
  end

  return if failure_group.success?

  raise failure_group.error unless AssertionAggregator.active?

  AssertionAggregator.add_error(failure_group.error)
end