Sha256: 72485f5747d104f2960ef039f4624169a2f43b5f560e46f9b60d3373bca323b4

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'matchi/matchers_base' unless defined?(::Matchi::MatchersBase)

# Namespace for the Matchi library.
module Matchi
  # Collection of matchers.
  module Matchers
    # **Type/class** matcher.
    module BeInstanceOf
      # The matcher.
      class Matcher
        include MatchersBase

        # Initialize the matcher with an object.
        #
        # @example A string matcher
        #   Matchi::BeInstanceOf.new(String)
        #
        # @param expected [#object_id] An expected class.
        def initialize(expected)
          @expected = expected
        end

        # @example Is it an instance of string?
        #   be_instance_of = Matchi::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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
matchi-rspec-0.1.1 lib/matchi/rspec/be_instance_of.rb
matchi-rspec-0.1.0 lib/matchi/rspec/be_instance_of.rb