Permalink
Browse files

make BaseMatcher a module

  • Loading branch information...
1 parent 6ef7b16 commit 175873e9db827317370d7484e833b56d02e87344 @dchelimsky dchelimsky committed Oct 20, 2011
@@ -1,6 +1,14 @@
module RSpec
module Matchers
- class BaseMatcher
+ # Used _internally_ as a base class for matchers that ship with
+ # rspec-expectations.
+ #
+ # == Warning
+ #
+ # This class is for internal use, and subject to change without notice. We
+ # strongly recommend that you do not base your custom matchers on this
+ # class. If/when this changes, we will announce it and remove this warning.
+ module BaseMatcher
include RSpec::Matchers::Pretty
attr_reader :actual, :expected
@@ -16,21 +24,6 @@ def failure_message_for_should
def failure_message_for_should_not
"expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"
end
-
-
- # from matcher.rb
- def name_to_sentence
- split_words(name)
- end
-
- def expected_to_sentence
- to_sentence(@expected)
- end
-
- def name
- defined?(@name) ? @name : self.class.name.split("::").last.downcase
- end
-
end
end
end
View
@@ -1,7 +1,8 @@
module RSpec
module Matchers
- class Eq < BaseMatcher
- attr_reader :actual
+ class Eq
+ include BaseMatcher
+
def matches?(actual)
@actual = actual
@actual == @expected
@@ -1,7 +1,8 @@
module RSpec
module Matchers
- class Eql < BaseMatcher
- attr_reader :actual
+ class Eql
+ include BaseMatcher
+
def matches?(actual)
@actual = actual
@actual.eql?(@expected)
@@ -1,7 +1,8 @@
module RSpec
module Matchers
- class Equal < BaseMatcher
- attr_reader :actual
+ class Equal
+ include BaseMatcher
+
def matches?(actual)
@actual = actual
@actual.equal?(@expected)
@@ -1,14 +1,8 @@
module RSpec
module Matchers
- # Used _internally_ as a base class for matchers that ship with
- # rspec-expectations.
- #
- # == Warning
- #
- # This class is for internal use, and subject to change without notice. We
- # strongly recommend that you do not base your custom matchers on this
- # class. If/when this changes, we will announce it and remove this warning.
- class Include < BaseMatcher
+ class Include
+ include BaseMatcher
+
def initialize(*expected)
super(expected)
end
@@ -147,14 +147,6 @@ def call_cached(key)
@messages[key].arity == 1 ? @messages[key].call(@actual) : @messages[key].call
end
- def name_to_sentence
- split_words(@name)
- end
-
- def expected_to_sentence
- to_sentence(@expected)
- end
-
unless method_defined?(:singleton_class)
def singleton_class
class << self; self; end
@@ -32,6 +32,18 @@ def _pretty_print(array)
end
result
end
+
+ def name_to_sentence
+ split_words(name)
+ end
+
+ def expected_to_sentence
+ to_sentence(@expected)
+ end
+
+ def name
+ defined?(@name) ? @name : self.class.name.split("::").last.downcase
+ end
end
end
-end
+end

0 comments on commit 175873e

Please sign in to comment.