Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor matcher messages for unsupported operations

  • Loading branch information...
commit 35cce72320939fbd2710abb4ed4193ef8560c58e 1 parent 4f9a9e5
Jon Rowe JonRowe authored
4 lib/rspec/mocks/matchers/have_received.rb
View
@@ -13,6 +13,10 @@ def initialize(method_name, &block)
@subject = nil
end
+ def name
+ "have_received"
+ end
+
def matches?(subject, &block)
@block ||= block
@subject = subject
4 lib/rspec/mocks/matchers/receive.rb
View
@@ -14,6 +14,10 @@ def initialize(message, block)
@backtrace_line = CallerFilter.first_non_rspec_line
end
+ def name
+ "receive"
+ end
+
def setup_expectation(subject, &block)
setup_mock_proxy_method_substitute(subject, :add_message_expectation, block)
end
4 lib/rspec/mocks/matchers/receive_messages.rb
View
@@ -8,6 +8,10 @@ def initialize(message_return_value_hash)
@backtrace_line = CallerFilter.first_non_rspec_line
end
+ def name
+ "receive_messages"
+ end
+
def setup_expectation(subject, &block)
each_message_on( proxy_on(subject) ) do |host, message, return_value|
host.add_simple_expectation(message, return_value, @backtrace_line)
24 lib/rspec/mocks/targets.rb
View
@@ -12,25 +12,33 @@ def self.delegate_to(matcher_method, options = {})
method_name = options.fetch(:from) { :to }
define_method(method_name) do |matcher, &block|
unless Matchers::Receive === matcher || Matchers::ReceiveMessages === matcher
- raise UnsupportedMatcherError,
- "only the `receive` or `receive_messages` matchers are supported " +
- "with `#{expression}(...).#{method_name}`, but you have provided: #{matcher}"
+ raise_unsupported_matcher(:to, matcher)
end
matcher.__send__(matcher_method, @target, &block)
end
end
- def self.disallow_negation(method)
- define_method method do |*args|
- raise NegationUnsupportedError,
- "`#{expression}(...).#{method} receive` is not supported since it " +
- "doesn't really make sense. What would it even mean?"
+ def self.disallow_negation(method_name)
+ define_method(method_name) do |matcher, *args|
+ raise_negation_unsupported(method_name, matcher)
end
end
private
+ def raise_unsupported_matcher(method_name, matcher)
+ raise UnsupportedMatcherError,
+ "only the `receive` or `receive_messages` matchers are supported " +
+ "with `#{expression}(...).#{method_name}`, but you have provided: #{matcher}"
+ end
+
+ def raise_negation_unsupported(method_name, matcher)
+ raise NegationUnsupportedError,
+ "`#{expression}(...).#{method_name} #{matcher.name}` is not supported since it " +
+ "doesn't really make sense. What would it even mean?"
+ end
+
def expression
self.class::EXPRESSION
end
Please sign in to comment.
Something went wrong with that request. Please try again.