Sha256: 6a599585620e208daf754ad7db980916509c3c215bd1f3a7f7f3fb093c229c4c

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Matchi
  # *Equivalence* matcher.
  class Eq
    # Initialize the matcher with an object.
    #
    # @example
    #   require "matchi/eq"
    #
    #   Matchi::Eq.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
    #   require "matchi/eq"
    #
    #   matcher = Matchi::Eq.new("foo")
    #   matcher.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

    # A string containing a human-readable representation of the matcher.
    def inspect
      "#{self.class}(#{@expected.inspect})"
    end

    # Returns a string representing the matcher.
    def to_s
      "eq #{@expected.inspect}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
matchi-3.0.0 lib/matchi/eq.rb