Sha256: 73f5b0d327254415574bef7fe8b5790ce73bf777f12f8ce3627cbdf685de36b5

Contents?: true

Size: 943 Bytes

Versions: 3

Compression:

Stored size: 943 Bytes

Contents

module Petitest
  class AssertionFailureError < ::StandardError
    # @return [String, nil]
    attr_reader :additional_message

    # @return [String]
    attr_reader :template

    # @return [Hash{Symbol => Object}]
    attr_reader :template_variables

    # @param additional_message [String, nil]
    # @param template [String]
    # @param template_variables [Hash, nil]
    def initialize(
      additional_message:,
      template:,
      template_variables:
    )
      @additional_message = additional_message
      @template = template
      @template_variables = template_variables
      super(assertion_type_message)
    end

    # @return [String]
    def assertion_type_message
      template % inspected_template_variables
    end

    private

    # @return [Hash{Symbol => String}]
    def inspected_template_variables
      template_variables.map do |key, value|
        [key, value.inspect]
      end.to_h
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
petitest-0.1.3 lib/petitest/assertion_failure_error.rb
petitest-0.1.2 lib/petitest/assertion_failure_error.rb
petitest-0.1.1 lib/petitest/assertion_failure_error.rb