Project

General

Profile

Bug #15515 » 0001-ostruct.rb-refine-arity-failure-message.patch

Fixed patch with test - lugray (Lisa Ugray), 01/07/2019 02:52 PM

View differences:

lib/ostruct.rb
len = args.length
if mname = mid[/.*(?==\z)/m]
if len != 1
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
raise ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1)
end
modifiable?[new_ostruct_member!(mname)] = args[0]
elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
......
new_ostruct_member!(mid) unless frozen?
@table[mid]
end
elsif @table.key?(mid)
raise ArgumentError, "wrong number of arguments (given #{len}, expected 0)"
else
begin
super
spec/ruby/library/openstruct/method_missing_spec.rb
os = OpenStruct.new
lambda { os.method_missing(:test, 1, 2, 3) }.should raise_error(NoMethodError)
end
it "raises an ArgumentError when the key exists" do
os = OpenStruct.new(test: 20)
lambda { os.method_missing(:test, 1, 2, 3) }.should raise_error(ArgumentError)
end
end
describe "OpenStruct#method_missing when not passed any additional arguments" do
(2-2/2)