Permalink
Browse files

refactoring: those syms are messages

  • Loading branch information...
1 parent 17c259e commit dce2d2cd1be7609edfd1e3ae3c7b7d6cd7ac9a57 @dchelimsky dchelimsky committed Feb 8, 2012
View
2 lib/rspec/mocks/argument_matchers.rb
@@ -87,7 +87,7 @@ def initialize(*methods_to_respond_to)
end
def ==(value)
- @methods_to_respond_to.all? {|sym| value.respond_to?(sym)}
+ @methods_to_respond_to.all? {|message| value.respond_to?(message)}
end
end
View
20 lib/rspec/mocks/error_generator.rb
@@ -16,37 +16,37 @@ def opts
end
# @private
- def raise_unexpected_message_error(sym, *args)
- __raise "#{intro} received unexpected message :#{sym}#{arg_message(*args)}"
+ def raise_unexpected_message_error(message, *args)
+ __raise "#{intro} received unexpected message :#{message}#{arg_message(*args)}"
end
# @private
def raise_unexpected_message_args_error(expectation, *args)
expected_args = format_args(*expectation.expected_args)
actual_args = format_args(*args)
- __raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
+ __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
end
# @private
def raise_similar_message_args_error(expectation, *args)
expected_args = format_args(*expectation.expected_args)
actual_args = args.collect {|a| format_args(*a)}.join(", ")
- __raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
+ __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
end
# @private
- def raise_expectation_error(sym, expected_received_count, actual_received_count, *args)
- __raise "(#{intro}).#{sym}#{format_args(*args)}\n expected: #{count_message(expected_received_count)}\n received: #{count_message(actual_received_count)}"
+ def raise_expectation_error(message, expected_received_count, actual_received_count, *args)
+ __raise "(#{intro}).#{message}#{format_args(*args)}\n expected: #{count_message(expected_received_count)}\n received: #{count_message(actual_received_count)}"
end
# @private
- def raise_out_of_order_error(sym)
- __raise "#{intro} received :#{sym} out of order"
+ def raise_out_of_order_error(message)
+ __raise "#{intro} received :#{message} out of order"
end
# @private
- def raise_block_failed_error(sym, detail)
- __raise "#{intro} received :#{sym} but passed block failed with: #{detail}"
+ def raise_block_failed_error(message, detail)
+ __raise "#{intro} received :#{message} but passed block failed with: #{detail}"
end
# @private
View
45 lib/rspec/mocks/message_expectation.rb
@@ -3,18 +3,18 @@ module Mocks
class MessageExpectation
# @private
- attr_reader :sym
+ attr_reader :message
attr_writer :expected_received_count, :method_block, :expected_from
protected :expected_received_count=, :method_block=, :expected_from=
attr_accessor :error_generator
protected :error_generator, :error_generator=
# @private
- def initialize(error_generator, expectation_ordering, expected_from, sym, method_block, expected_received_count=1, opts={}, &implementation)
+ def initialize(error_generator, expectation_ordering, expected_from, message, method_block, expected_received_count=1, opts={}, &implementation)
@error_generator = error_generator
@error_generator.opts = opts
@expected_from = expected_from
- @sym = sym
+ @message = message
@method_block = method_block
@return_block = nil
@actual_received_count = 0
@@ -163,16 +163,16 @@ def and_yield(*args, &block)
end
# @private
- def matches?(sym, *args)
- @sym == sym and @args_expectation.args_match?(*args)
+ def matches?(message, *args)
+ @message == message and @args_expectation.args_match?(*args)
end
# @private
def invoke(*args, &block)
if @expected_received_count == 0
@failed_fast = true
@actual_received_count += 1
- @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *args)
+ @error_generator.raise_expectation_error(@message, @expected_received_count, @actual_received_count, *args)
end
@order_group.handle_order_constraint self
@@ -215,8 +215,8 @@ def called_max_times?
end
# @private
- def matches_name_but_not_args(sym, *args)
- @sym == sym and not @args_expectation.args_match?(*args)
+ def matches_name_but_not_args(message, *args)
+ @message == message and not @args_expectation.args_match?(*args)
end
# @private
@@ -265,14 +265,14 @@ def advise(*args)
# @private
def generate_error
if similar_messages.empty?
- @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
+ @error_generator.raise_expectation_error(@message, @expected_received_count, @actual_received_count, *@args_expectation.args)
else
@error_generator.raise_similar_message_args_error(self, *@similar_messages)
end
end
def raise_out_of_order_error
- @error_generator.raise_out_of_order_error @sym
+ @error_generator.raise_out_of_order_error @message
end
# Constrains a stub or message expectation to invocations with specific
@@ -408,7 +408,7 @@ def ordered(&block)
end
# @private
- def negative_expectation_for?(sym)
+ def negative_expectation_for?(message)
return false
end
@@ -428,7 +428,7 @@ def invoke_method_block(*args, &block)
begin
@method_block.call(*args, &block)
rescue => detail
- @error_generator.raise_block_failed_error(@sym, detail.message)
+ @error_generator.raise_block_failed_error(@message, detail.message)
end
end
@@ -475,15 +475,12 @@ def failed_fast?
def set_expected_received_count(relativity, n)
@at_least = (relativity == :at_least)
- @at_most = (relativity == :at_most)
- @exactly = (relativity == :exactly)
+ @at_most = (relativity == :at_most)
+ @exactly = (relativity == :exactly)
@expected_received_count = case n
- when Numeric
- n
- when :once
- 1
- when :twice
- 2
+ when Numeric then n
+ when :once then 1
+ when :twice then 2
end
end
@@ -495,13 +492,13 @@ def clear_actual_received_count!
# @private
class NegativeMessageExpectation < MessageExpectation
# @private
- def initialize(message, expectation_ordering, expected_from, sym, method_block)
- super(message, expectation_ordering, expected_from, sym, method_block, 0)
+ def initialize(error_generator, expectation_ordering, expected_from, message, method_block)
+ super(error_generator, expectation_ordering, expected_from, message, method_block, 0)
end
# @private
- def negative_expectation_for?(sym)
- return @sym == sym
+ def negative_expectation_for?(message)
+ return @message == message
end
end
end
View
4 lib/rspec/mocks/methods.rb
@@ -107,8 +107,8 @@ def null_object?
end
# @private
- def received_message?(sym, *args, &block)
- __mock_proxy.received_message?(sym.to_sym, *args, &block)
+ def received_message?(message, *args, &block)
+ __mock_proxy.received_message?(message, *args, &block)
end
# @private
View
12 lib/rspec/mocks/mock.rb
@@ -37,19 +37,19 @@ def to_s
alias_method :to_str, :to_s
# @private
- def respond_to?(sym, incl_private=false)
- __mock_proxy.null_object? && sym != :to_ary ? true : super
+ def respond_to?(message, incl_private=false)
+ __mock_proxy.null_object? && message != :to_ary ? true : super
end
private
- def method_missing(sym, *args, &block)
- raise NoMethodError if sym == :to_ary
- __mock_proxy.record_message_received(sym, *args, &block)
+ def method_missing(message, *args, &block)
+ raise NoMethodError if message == :to_ary
+ __mock_proxy.record_message_received(message, *args, &block)
begin
__mock_proxy.null_object? ? self : super
rescue NameError
- __mock_proxy.raise_unexpected_message_error(sym, *args)
+ __mock_proxy.raise_unexpected_message_error(message, *args)
end
end
View
28 lib/rspec/mocks/proxy.rb
@@ -34,7 +34,7 @@ def initialize(object, name=nil, options={})
@name = name
@error_generator = ErrorGenerator.new object, name, options
@expectation_ordering = RSpec::Mocks::space.expectation_ordering
- @messages_received = []
+ @messages_received = []
@options = options
@already_proxied_respond_to = false
@null_object = false
@@ -101,38 +101,38 @@ def received_message?(method_name, *args, &block)
end
# @private
- def has_negative_expectation?(method_name)
- method_double[method_name].expectations.detect {|expectation| expectation.negative_expectation_for?(method_name)}
+ def has_negative_expectation?(message)
+ method_double[message].expectations.detect {|expectation| expectation.negative_expectation_for?(message)}
end
# @private
- def record_message_received(method_name, *args, &block)
- @messages_received << [method_name, args, block]
+ def record_message_received(message, *args, &block)
+ @messages_received << [message, args, block]
end
# @private
- def message_received(method_name, *args, &block)
- expectation = find_matching_expectation(method_name, *args)
- stub = find_matching_method_stub(method_name, *args)
+ def message_received(message, *args, &block)
+ expectation = find_matching_expectation(message, *args)
+ stub = find_matching_method_stub(message, *args)
if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
- if expectation = find_almost_matching_expectation(method_name, *args)
+ if expectation = find_almost_matching_expectation(message, *args)
expectation.advise(*args) unless expectation.expected_messages_received?
end
stub.invoke(*args, &block)
elsif expectation
expectation.invoke(*args, &block)
- elsif expectation = find_almost_matching_expectation(method_name, *args)
+ elsif expectation = find_almost_matching_expectation(message, *args)
expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
- raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(method_name) or null_object?)
- elsif stub = find_almost_matching_stub(method_name, *args)
+ raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(message) or null_object?)
+ elsif stub = find_almost_matching_stub(message, *args)
stub.advise(*args)
raise_unexpected_message_args_error(stub, *args)
elsif @object.is_a?(Class)
- @object.superclass.__send__(method_name, *args, &block)
+ @object.superclass.__send__(message, *args, &block)
else
- @object.__send__(:method_missing, method_name, *args, &block)
+ @object.__send__(:method_missing, message, *args, &block)
end
end
View
4 spec/rspec/mocks/bug_report_11545_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
class LiarLiarPantsOnFire
- def respond_to?(sym, incl_private=false)
+ def respond_to?(message, incl_private=false)
true
end
- def self.respond_to?(sym, incl_private=false)
+ def self.respond_to?(message, incl_private=false)
true
end
end
View
10 spec/rspec/mocks/bug_report_8165_spec.rb
@@ -1,16 +1,16 @@
require 'spec_helper'
describe "An object where respond_to? is true and does not have method" do
- # When should_receive(:sym) is sent to any object, the Proxy sends
- # respond_to?(:sym) to that object to see if the method should be proxied.
+ # When should_receive(message) is sent to any object, the Proxy sends
+ # respond_to?(message) to that object to see if the method should be proxied.
#
# If respond_to? itself is proxied, then when the Proxy sends respond_to?
# to the object, the proxy is invoked and responds yes (if so set in the spec).
- # When the object does NOT actually respond to :sym, an exception is thrown
+ # When the object does NOT actually respond to `message`, an exception is thrown
# when trying to proxy it.
#
- # The fix was to keep track of whether :respond_to? had been proxied and, if
- # so, call the munged copy of :respond_to? on the object.
+ # The fix was to keep track of whether `respond_to?` had been proxied and, if
+ # so, call the munged copy of `respond_to?` on the object.
it "does not raise an exception for Object" do
obj = Object.new

0 comments on commit dce2d2c

Please sign in to comment.