From fbe877690d1e01ac887abe6022d859b728a305b8 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 29 Nov 2022 22:31:22 -0700 Subject: [PATCH] Adjust call argument matching Reenable test for https://github.com/icy-arctic-fox/spectator/issues/44 and https://github.com/icy-arctic-fox/spectator/issues/47 --- spec/issues/github_issue_44_spec.cr | 11 +++++++---- src/spectator/mocks/arguments.cr | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/issues/github_issue_44_spec.cr b/spec/issues/github_issue_44_spec.cr index d1b9716..da6cbf3 100644 --- a/spec/issues/github_issue_44_spec.cr +++ b/spec/issues/github_issue_44_spec.cr @@ -26,12 +26,15 @@ Spectator.describe "GitHub Issue #44" do # Original issue uses keyword arguments in place of positional arguments. context "keyword arguments in place of positional arguments" do before_each do - expect(Process).to receive(:run).with(command, shell: true, output: :pipe).and_raise(exception) + pipe = Process::Redirect::Pipe + expect(Process).to receive(:run).with(command, shell: true, output: pipe).and_raise(exception) end - it "must stub Process.run", skip: "Keyword arguments in place of positional arguments not supported with expect-receive" do - Process.run(command, shell: true, output: :pipe) do |_process| - end + it "must stub Process.run" do + expect do + Process.run(command, shell: true, output: :pipe) do |_process| + end + end.to raise_error(File::NotFoundError, "File not found") end end end diff --git a/src/spectator/mocks/arguments.cr b/src/spectator/mocks/arguments.cr index f9c6e19..fcb74f4 100644 --- a/src/spectator/mocks/arguments.cr +++ b/src/spectator/mocks/arguments.cr @@ -90,9 +90,10 @@ module Spectator i = 0 other.args.each do |k, v2| + break if i >= positional.size next if kwargs.has_key?(k) # Covered by named arguments. - v1 = positional.fetch(i) { return false } + v1 = positional[i] i += 1 return false unless v1 === v2 end