From c77da67341cf78278c3e3435b9f0716b65a72ef6 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 23 Oct 2022 21:56:37 -0600 Subject: [PATCH] Hide splat label in certain situations Undefined double methods were reporting splat arguments, which is technically correct. But for output in these cases, it makes more sense to show the exact calling args. --- spec/spectator/mocks/arguments_spec.cr | 8 ++++++++ src/spectator/mocks/arguments.cr | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/spectator/mocks/arguments_spec.cr b/spec/spectator/mocks/arguments_spec.cr index 8b43b95..cd92010 100644 --- a/spec/spectator/mocks/arguments_spec.cr +++ b/spec/spectator/mocks/arguments_spec.cr @@ -97,6 +97,14 @@ Spectator.describe Spectator::Arguments do is_expected.to eq("(no args)") end end + + context "with a splat and no arguments" do + let(arguments) { Spectator::Arguments.build(NamedTuple.new, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) } + + it "omits the splat name" do + is_expected.to eq("(:x, :y, :z, bar: \"baz\", qux: 123)") + end + end end describe "#==" do diff --git a/src/spectator/mocks/arguments.cr b/src/spectator/mocks/arguments.cr index 17567e3..003875f 100644 --- a/src/spectator/mocks/arguments.cr +++ b/src/spectator/mocks/arguments.cr @@ -107,14 +107,14 @@ module Spectator # Add the splat arguments. if (splat = @splat) && !splat.empty? io << ", " unless args.empty? - if name = @splat_name - io << '*' << name << ": {" + if splat_name = !args.empty? && @splat_name + io << '*' << splat_name << ": {" end splat.each_with_index do |arg, i| io << ", " if i > 0 arg.inspect(io) end - io << '}' if @splat_name + io << '}' if splat_name end # Add the keyword arguments.