Sha256: f0f1b3e5497456c4f35e2b8594244d59b8739f8f586d39683a3bcf465d77d42e

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module Spec
  module Matchers
    class BeKindOf
      def initialize(expected)
        @expected = expected
      end
      
      def matches?(actual)
        @actual = actual
        @actual.kind_of?(@expected)
      end
      
      def description
        "be a kind of #{@expected}"
      end
      
      def failure_message
        "expected kind of #{@expected}, got #{@actual.inspect}"
      end
      
      def negative_failure_message
        "expected #{@actual.inspect} not to be a kind of #{@expected}"
      end
    end

    # :call-seq:
    #   should be_kind_of(expected)
    #   should be_a_kind_of(expected)
    #   should_not be_kind_of(expected)
    #   should_not be_a_kind_of(expected)
    #
    # Passes if actual.kind_of?(expected)
    #
    # == Examples
    #
    #   5.should be_kind_of(Fixnum)
    #   5.should be_kind_of(Numeric)
    #   5.should_not be_kind_of(Float)
    def be_kind_of(expected)
      BeKindOf.new(expected)
    end
    
    alias_method :be_a_kind_of, :be_kind_of
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dchelimsky-rspec-1.1.99.7 lib/spec/matchers/be_kind_of.rb
dchelimsky-rspec-1.1.99.8 lib/spec/matchers/be_kind_of.rb
dchelimsky-rspec-1.1.99.9 lib/spec/matchers/be_kind_of.rb