aboutsummaryrefslogtreecommitdiffstats
path: root/spec/mspec/lib/mspec/matchers/respond_to.rb
blob: 6b35ae2d3caa4c6bf0ac00dbaa6a20cc64e2443f (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 RespondToMatcher
  def initialize(expected)
    @expected = expected
  end

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

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

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

module MSpecMatchers
  private def respond_to(expected)
    RespondToMatcher.new(expected)
  end
end