summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/matchers/be_kind_of.rb
blob: a734f6159caced2fdf0e645e71feb5d714b5203d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class BeKindOfMatcher
  def initialize(expected)
    @expected = expected
  end

  def matches?(actual)
    @actual = actual
    @actual.is_a?(@expected)
  end

  def failure_message
    ["Expected #{@actual.inspect} (#{@actual.class})", "to be kind of #{@expected}"]
  end

  def negative_failure_message
    ["Expected #{@actual.inspect} (#{@actual.class})", "not to be kind of #{@expected}"]
  end
end

class Object
  def be_kind_of(expected)
    BeKindOfMatcher.new(expected)
  end
end