Sha256: 4e88b607c258c84d8107e45f131ffcdbf562e045003e5f4bf4fab7f3f3b6b51b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require_relative ::File.join('..', 'matchers_base') unless
  defined?(::Matchi::MatchersBase)

module Matchi
  module Matchers
    # **Identity** matcher.
    module Equal
      # The matcher.
      class Matcher
        include MatchersBase

        # Initialize the matcher with an object.
        #
        # @example The number 42 matcher.
        #   Matchi::Matchers::Equal::Matcher.new(42)
        #
        # @param expected [#equal?] An expected object.
        def initialize(expected)
          @expected = expected
        end

        # Boolean comparison between the actual value and the expected value.
        #
        # @example Is it equal to :foo?
        #   equal = Matchi::Matchers::Equal::Matcher.new(:foo)
        #   equal.matches? { :foo } # => true
        #
        # @yieldreturn [#object_id] the actual value to compare to the expected
        #   one.
        #
        # @return [Boolean] Comparison between actual and expected values.
        def matches?
          @expected.equal?(yield)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
matchi-1.0.5 lib/matchi/matchers/equal.rb