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.
This commit is contained in:
Michael Miller 2022-10-23 21:56:37 -06:00
parent 8959d28b38
commit c77da67341
No known key found for this signature in database
GPG Key ID: 32B47AE8F388A1FF
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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.