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.