Class: AggregateAssertions::FailureGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/aggregate_assertions/failure_group.rb

Overview

This class is used to aggregates the failures/errors for an aggregate block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:, label: nil) ⇒ FailureGroup

Returns a new instance of FailureGroup.



10
11
12
13
14
15
# File 'lib/aggregate_assertions/failure_group.rb', line 10

def initialize(location:, label: nil)
  @location = location
  @label = label
  @failures = []
  @other_errors = []
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/aggregate_assertions/failure_group.rb', line 8

def label
  @label
end

#locationObject (readonly)

Returns the value of attribute location.



8
9
10
# File 'lib/aggregate_assertions/failure_group.rb', line 8

def location
  @location
end

Instance Method Details

#add_error(error) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/aggregate_assertions/failure_group.rb', line 17

def add_error(error)
  if error.is_a?(Minitest::Assertion)
    @failures << error
  else
    @other_errors << error
  end
end

#errorObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/aggregate_assertions/failure_group.rb', line 25

def error
  case @failures.size + @other_errors.size
  when 0
    nil
  when 1
    @failures.first || @other_errors.first
  else
    group_error
  end
end

#success?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/aggregate_assertions/failure_group.rb', line 36

def success?
  @failures.empty? && @other_errors.empty?
end