diff options
Diffstat (limited to 'spec/mspec/lib/mspec/matchers/be_ancestor_of.rb')
-rw-r--r-- | spec/mspec/lib/mspec/matchers/be_ancestor_of.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb b/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb new file mode 100644 index 0000000000..792c64089a --- /dev/null +++ b/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb @@ -0,0 +1,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 + +class Object + def be_ancestor_of(expected) + BeAncestorOfMatcher.new(expected) + end +end |