Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ruby-head/2.8 #1316

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/rspec/mocks/any_instance/recorder.rb
Expand Up @@ -129,10 +129,10 @@ def already_observing?(method_name)
end

# @private
def notify_received_message(_object, message, args, _blk)
def notify_received_message(_object, message, args, opts, _blk)
has_expectation = false

message_chains.each_unfulfilled_expectation_matching(message, *args) do |expectation|
message_chains.each_unfulfilled_expectation_matching(message, *args, **opts) do |expectation|
has_expectation = true
expectation.expectation_fulfilled!
end
Expand Down Expand Up @@ -257,9 +257,9 @@ def observe!(method_name)
@observed_methods << method_name
backup_method!(method_name)
recorder = self
@klass.__send__(:define_method, method_name) do |*args, &blk|
@klass.__send__(:define_method, method_name) do |*args, **opts, &blk|
recorder.playback!(self, method_name)
__send__(method_name, *args, &blk)
__send__(method_name, *args, **opts, &blk)
end
end

Expand Down
19 changes: 10 additions & 9 deletions lib/rspec/mocks/message_expectation.rb
Expand Up @@ -97,8 +97,8 @@ def and_return(first_value, *values)
# counter.increment
# expect(counter.count).to eq(original_count + 1)
def and_call_original
wrap_original(__method__) do |original, *args, &block|
original.call(*args, &block)
wrap_original(__method__) do |original, *args, **opts, &block|
original.call(*args, **opts, &block)
end
end

Expand Down Expand Up @@ -423,8 +423,8 @@ def safe_invoke(parent_stub, *args, &block)
invoke_incrementing_actual_calls_by(1, false, parent_stub, *args, &block)
end

def invoke(parent_stub, *args, &block)
invoke_incrementing_actual_calls_by(1, true, parent_stub, *args, &block)
def invoke(parent_stub, *args, **opts, &block)
invoke_incrementing_actual_calls_by(1, true, parent_stub, *args, **opts, &block)
end

def invoke_without_incrementing_received_count(parent_stub, *args, &block)
Expand Down Expand Up @@ -552,7 +552,7 @@ def exception_source_id
@exception_source_id ||= "#{self.class.name} #{__id__}"
end

def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub, *args, &block)
def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub, *args, **opts, &block)
args.unshift(orig_object) if yield_receiver_to_implementation_block?

if negative? || (allowed_to_fail && (@exactly || @at_most) && (@actual_received_count == @expected_received_count))
Expand All @@ -562,16 +562,17 @@ def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub,
@message, @expected_received_count,
@argument_list_matcher,
@actual_received_count + increment,
# TODO handle opts
expectation_count_type, args, nil, exception_source_id
)
end

@order_group.handle_order_constraint self

if implementation.present?
implementation.call(*args, &block)
implementation.call(*args, **opts, &block)
elsif parent_stub
parent_stub.invoke(nil, *args, &block)
parent_stub.invoke(nil, *args, **opts, &block)
end
ensure
@actual_received_count_write_mutex.synchronize do
Expand Down Expand Up @@ -736,8 +737,8 @@ def inner_action
true
end

def call(*args, &block)
@block.call(@method, *args, &block)
def call(*args, **opts, &block)
@block.call(@method, *args, **opts, &block)
end

private
Expand Down
8 changes: 4 additions & 4 deletions lib/rspec/mocks/method_double.rb
Expand Up @@ -60,8 +60,8 @@ def define_proxy_method

save_original_implementation_callable!
definition_target.class_exec(self, method_name, @original_visibility || visibility) do |method_double, method_name, visibility|
define_method(method_name) do |*args, &block|
method_double.proxy_method_invoked(self, *args, &block)
define_method(method_name) do |*args, **opts, &block|
method_double.proxy_method_invoked(self, *args, **opts, &block)
end
__send__(visibility, method_name)
end
Expand All @@ -73,8 +73,8 @@ def define_proxy_method
# method to perform additional operations.
#
# @private
def proxy_method_invoked(_obj, *args, &block)
@proxy.message_received method_name, *args, &block
def proxy_method_invoked(_obj, *args, **opts, &block)
@proxy.message_received method_name, *args, **opts, &block
end

# @private
Expand Down
35 changes: 19 additions & 16 deletions lib/rspec/mocks/proxy.rb
Expand Up @@ -184,34 +184,37 @@ def record_message_received(message, *args, &block)
end

# @private
def message_received(message, *args, &block)
record_message_received message, *args, &block
def message_received(message, *args, **opts, &block)
Byebug.byebug
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover.

record_message_received message, *args, **opts, &block

expectation = find_matching_expectation(message, *args)
stub = find_matching_method_stub(message, *args)
expectation = find_matching_expectation(message, *args, **opts)
stub = find_matching_method_stub(message, *args, **opts)

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(message, *args))
expectation.advise(*args) unless expectation.expected_messages_received?
if (expectation = find_almost_matching_expectation(message, *args, **opts))
expectation.advise(*args, **opts) unless expectation.expected_messages_received?
end
stub.invoke(nil, *args, &block)
stub.invoke(nil, *args, **opts, &block)
elsif expectation
expectation.unadvise(messages_arg_list)
expectation.invoke(stub, *args, &block)
elsif (expectation = find_almost_matching_expectation(message, *args))
expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
expectation.invoke(stub, *args, **opts, &block)
elsif (expectation = find_almost_matching_expectation(message, *args, **opts))
expectation.advise(*args, **opts) if null_object? unless expectation.expected_messages_received?

if null_object? || !has_negative_expectation?(message)
# TODO handle opts
expectation.raise_unexpected_message_args_error([args])
end
elsif (stub = find_almost_matching_stub(message, *args))
stub.advise(*args)
elsif (stub = find_almost_matching_stub(message, *args, **opts))
stub.advise(*args, **opts)
# TODO handle opts
raise_missing_default_stub_error(stub, [args])
elsif Class === @object
@object.superclass.__send__(message, *args, &block)
@object.superclass.__send__(message, *args, **opts, &block)
else
@object.__send__(:method_missing, message, *args, &block)
@object.__send__(:method_missing, message, *args, **opts, &block)
end
end

Expand Down Expand Up @@ -338,9 +341,9 @@ def reset
super
end

def message_received(message, *args, &block)
def message_received(message, *args, **opts, &block)
RSpec::Mocks.space.any_instance_recorders_from_ancestry_of(object).each do |subscriber|
subscriber.notify_received_message(object, message, args, block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we can pass block as &block and get rid of _block parameter in the notify_received_message method signature.

subscriber.notify_received_message(object, message, args, opts, block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe pass it as *args, **opts here as well?

end
super
end
Expand Down