Sha256: bbc551f969fa7c8647aaccab5c1c57abf8bac936f36537c9ac5c3150a205fc03

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "minitest"
require_relative "aggregate_assertions/version"
require_relative "aggregate_assertions/assertion_aggregator"

module AggregateAssertions
  # Contains patches to the Minitest::Test class
  module TestPatch
    def assert(test, msg = nil)
      super
    rescue Minitest::Assertion, StandardError => ex
      raise unless AssertionAggregator.active?

      AssertionAggregator.add_error(ex)
    end

    def aggregate_assertions(label = nil)
      flunk "aggregate_assertions requires a block" unless block_given?

      AssertionAggregator.open_failure_group(label)

      begin
        yield
      rescue Minitest::Assertion, StandardError => ex
        AssertionAggregator.add_error(ex)
      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
  end
end

Minitest::Test.prepend(AggregateAssertions::TestPatch)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aggregate_assertions-0.1.0.pre0 lib/aggregate_assertions.rb