Sha256: 7bf042c35142d2b868b73743dc256d0150f1ce7aa8973bd062d72c346b04f250

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Matchi
  # *Identity* matcher.
  class Be
    # Initialize the matcher with an object.
    #
    # @example
    #   require "matchi/be"
    #
    #   Matchi::Be.new(:foo)
    #
    # @param expected [#equal?] The expected identical object.
    def initialize(expected)
      @expected = expected
    end

    # Boolean comparison between the actual value and the expected value.
    #
    # @example
    #   require "matchi/be"
    #
    #   matcher = Matchi::Be.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.equal?(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
      "be #{@expected.inspect}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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