Fix splat argument expansion in method redefinition

The constructed previous_def call was malformed for stub methods.
Resolves the original issue in
https://github.com/icy-arctic-fox/spectator/issues/49
This commit is contained in:
Michael Miller 2023-01-23 11:55:52 -07:00
parent fd372226ab
commit abbd6ffd71
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
2 changed files with 9 additions and 5 deletions

View file

@ -0,0 +1,6 @@
require "../spec_helper"
# https://github.com/icy-arctic-fox/spectator/issues/49
Spectator.describe "GitHub Issue #49" do
mock File
end

View file

@ -133,13 +133,12 @@ module Spectator
if method.splat_index if method.splat_index
method.args.each_with_index do |arg, i| method.args.each_with_index do |arg, i|
if i == method.splat_index if i == method.splat_index
original += '*'
if arg.internal_name && arg.internal_name.size > 0 if arg.internal_name && arg.internal_name.size > 0
original += "#{arg.internal_name}, " original += "*#{arg.internal_name}, "
end end
original += "**#{method.double_splat}, " if method.double_splat original += "**#{method.double_splat}, " if method.double_splat
elsif i > method.splat_index elsif i > method.splat_index
original += "#{arg.name}: #{arg.internal_name}" original += "#{arg.name}: #{arg.internal_name}, "
else else
original += "#{arg.internal_name}, " original += "#{arg.internal_name}, "
end end
@ -283,9 +282,8 @@ module Spectator
if method.splat_index if method.splat_index
method.args.each_with_index do |arg, i| method.args.each_with_index do |arg, i|
if i == method.splat_index if i == method.splat_index
original += '*'
if arg.internal_name && arg.internal_name.size > 0 if arg.internal_name && arg.internal_name.size > 0
original += "#{arg.internal_name}, " original += "*#{arg.internal_name}, "
end end
original += "**#{method.double_splat}, " if method.double_splat original += "**#{method.double_splat}, " if method.double_splat
elsif i > method.splat_index elsif i > method.splat_index