Sha256: 2fc490b5fa6e8cbfc4807c3562ef64a87308730c306357529126825a3d1e4ac2

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

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

module Matchi
  module Matchers
    # **Equivalence** matcher.
    module Eql
      # The matcher.
      class Matcher
        include MatchersBase

        # Initialize the matcher with an object.
        #
        # @example The string 'foo' matcher.
        #   Matchi::Matchers::Eql::Matcher.new('foo')
        #
        # @param expected [#eql?] An expected equivalent object.
        def initialize(expected)
          @expected = expected
        end

        # Boolean comparison between the actual value and the expected value.
        #
        # @example Is it equivalent to 'foo'?
        #   eql = Matchi::Matchers::Eql::Matcher.new('foo')
        #   eql.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.eql?(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/eql.rb