diff options
Diffstat (limited to 'spec/mspec/lib/mspec/matchers/have_singleton_method.rb')
-rw-r--r-- | spec/mspec/lib/mspec/matchers/have_singleton_method.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/mspec/lib/mspec/matchers/have_singleton_method.rb b/spec/mspec/lib/mspec/matchers/have_singleton_method.rb new file mode 100644 index 0000000000..5f3acb84e2 --- /dev/null +++ b/spec/mspec/lib/mspec/matchers/have_singleton_method.rb @@ -0,0 +1,24 @@ +require 'mspec/matchers/method' + +class HaveSingletonMethodMatcher < MethodMatcher + def matches?(obj) + @obj = obj + obj.singleton_methods(@include_super).include? @method + end + + def failure_message + ["Expected #{@obj} to have singleton method '#{@method.to_s}'", + "but it does not"] + end + + def negative_failure_message + ["Expected #{@obj} NOT to have singleton method '#{@method.to_s}'", + "but it does"] + end +end + +class Object + def have_singleton_method(method, include_super=true) + HaveSingletonMethodMatcher.new method, include_super + end +end |