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
213 213
    len = args.length
214 214
    if mname = mid[/.*(?==\z)/m]
215 215
      if len != 1
216
        raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
216
        raise ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1)
217 217
      end
218 218
      modifiable?[new_ostruct_member!(mname)] = args[0]
219 219
    elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
......
221 221
        new_ostruct_member!(mid) unless frozen?
222 222
        @table[mid]
223 223
      end
224
    elsif @table.key?(mid)
225
      raise ArgumentError, "wrong number of arguments (given #{len}, expected 0)"
224 226
    else
225 227
      begin
226 228
        super
spec/ruby/library/openstruct/method_missing_spec.rb
36 36
    os = OpenStruct.new
37 37
    lambda { os.method_missing(:test, 1, 2, 3) }.should raise_error(NoMethodError)
38 38
  end
39

  
40
  it "raises an ArgumentError when the key exists" do
41
    os = OpenStruct.new(test: 20)
42
    lambda { os.method_missing(:test, 1, 2, 3) }.should raise_error(ArgumentError)
43
  end
39 44
end
40 45

  
41 46
describe "OpenStruct#method_missing when not passed any additional arguments" do