Sha256: a218d24b3f71c18ded3bda9cd31ecaf7872c764cef8b1155b6f6b8c81f3dd02c

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

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

3 entries across 3 versions & 1 rubygems

Version Path
matchi-1.0.2 lib/matchi/matchers/equal.rb
matchi-1.0.1 lib/matchi/matchers/equal.rb
matchi-1.0.0 lib/matchi/matchers/equal.rb