class AggregateAssertions::FailureGroup
This class is used to aggregates the failures/errors for an aggregate block.
Attributes
label[R]
location[R]
Public Class Methods
new(location:, label: nil)
click to toggle source
# File lib/aggregate_assertions/failure_group.rb, line 10 def initialize(location:, label: nil) @location = location @label = label @failures = [] @other_errors = [] end
Public Instance Methods
add_error(error)
click to toggle source
# 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
error()
click to toggle source
# 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?()
click to toggle source
# File lib/aggregate_assertions/failure_group.rb, line 36 def success? @failures.empty? && @other_errors.empty? end
Private Instance Methods
group_error()
click to toggle source
# File lib/aggregate_assertions/failure_group.rb, line 42 def group_error Minitest::MultipleAssertionError.new(message_for_errors, location: location, result_label: result_label) end
group_label()
click to toggle source
# File lib/aggregate_assertions/failure_group.rb, line 60 def group_label label ? " in group #{label.inspect}" : "" end
indent(string, size: 6)
click to toggle source
# File lib/aggregate_assertions/failure_group.rb, line 68 def indent(string, size: 6) prefix = (" " * size) string.split("\n").map { |str| "#{prefix}#{str}" }.join("\n") end
message_for_errors()
click to toggle source
# File lib/aggregate_assertions/failure_group.rb, line 48 def message_for_errors errors = @failures + @other_errors "There were #{errors.size} errors#{group_label}:\n" + errors.map.with_index do |error, index| if error.is_a?(Minitest::Assertion) " #{index + 1}) #{error.location}:\n#{indent(error.message)}\n" else " #{index + 1}) #{error.class}: #{error.message}\n#{indent(error.backtrace.first)}\n" end end.join("\n") end
result_label()
click to toggle source
# File lib/aggregate_assertions/failure_group.rb, line 64 def result_label @other_errors.any? ? "Error" : nil end