Sha256: 9bb3083989c58e133b395b60609b57f1204020451151afe4855330b2355377be

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 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_for_should
        "expected kind of #{@expected}, got #{@actual.inspect}"
      end
      
      def failure_message_for_should_not
        "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

4 entries across 4 versions & 2 rubygems

Version Path
dchelimsky-rspec-1.1.99.13 lib/spec/matchers/be_kind_of.rb
rspec-1.2.0 lib/spec/matchers/be_kind_of.rb
rspec-1.2.1 lib/spec/matchers/be_kind_of.rb
rspec-1.2.2 lib/spec/matchers/be_kind_of.rb