summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/matchers/be_an_instance_of.rb
blob: 6e31afcddd031baafa60a6f282ade62fce8c9c99 (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
25
26
class BeAnInstanceOfMatcher
  def initialize(expected)
    @expected = expected
  end

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

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

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

class Object
  def be_an_instance_of(expected)
    BeAnInstanceOfMatcher.new(expected)
  end
end