summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb
blob: 05f72099e424d111d9eee73ed6f39d534455b15f (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 BeAncestorOfMatcher
  def initialize(expected)
    @expected = expected
  end

  def matches?(actual)
    @actual = actual
    @expected.ancestors.include? @actual
  end

  def failure_message
    ["Expected #{@actual}", "to be an ancestor of #{@expected}"]
  end

  def negative_failure_message
    ["Expected #{@actual}", "not to be an ancestor of #{@expected}"]
  end
end

module MSpecMatchers
  private def be_ancestor_of(expected)
    BeAncestorOfMatcher.new(expected)
  end
end