Sha256: ba11fb21a0f79124bda60d5d7cca3fb7f324859cac3a129e3455b8e92a81cb15

Contents?: true

Size: 829 Bytes

Versions: 2

Compression:

Stored size: 829 Bytes

Contents

# frozen_string_literal: true

require_relative("error")
require_relative("failure_group")

module AggregateAssertions
  # Main entry-point for the interacting with the state of aggregation.
  module AssertionAggregator
    class << self
      def active?
        !store.nil? && !store.empty?
      end

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

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

      def close_failure_group
        store.pop
      end

      private

      def store
        Thread.current[:__mt_aggregate]
      end

      def initialize_store
        Thread.current[:__mt_aggregate] ||= []
      end

      def location
        caller(3, 1).first.sub(/:in .*$/, "")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aggregate_assertions-0.1.1 lib/aggregate_assertions/assertion_aggregator.rb
aggregate_assertions-0.1.0 lib/aggregate_assertions/assertion_aggregator.rb