Sha256: 2d2e31425b801527bc49c9a8272633bad1f4430fce645690fe7c2292bd7cdb41

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'matchi/matcher/base'

# Namespace for the Matchi library.
module Matchi
  # Collection of matcher classes.
  module Matcher
    # **Type/class** matcher.
    class BeInstanceOf < ::Matchi::Matcher::Base
      # Initialize the matcher with an object.
      #
      # @example A string matcher
      #   Matchi::Matcher::BeInstanceOf.new(String)
      #
      # @param expected [#object_id] An expected class.
      def initialize(expected)
        @expected = expected
      end

      # @todo For security reasons, instead of comparing actual with expected,
      #   we should compare expected with actual.  Using something such as:
      #   `expected.class_of?(actual)`.
      #
      # @example Is it an instance of string?
      #   be_instance_of = Matchi::Matcher::BeInstanceOf.new(String)
      #   be_instance_of.matches? { 'foo' } # => true
      #
      # @yieldreturn [#instance_of?] the actual value to compare to the
      #   expected one.
      #
      # @return [Boolean] Comparison between actual and expected values.
      def matches?
        yield.instance_of?(expected)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
matchi-rspec-1.0.1 lib/matchi/matcher/be_instance_of.rb
matchi-rspec-1.0.0 lib/matchi/matcher/be_instance_of.rb