Fix ArgumentError after invoking setter#1
Conversation
Fix `add_accessors': wrong number of arguments (given 1, expected 0) (ArgumentError)`. The issue was the lack of `[]=` operator method definition which resulted in the `method_missing` hook redefining `[]` method.
|
Oh I approved but please add tests |
|
@fonji I’ve added a spec. I’ve stated the spec in a positive way even though the change was motivated by a lack of behavior leading to an exception. Open to feedback if you think there’s a better way to express the spec. |
fonji
left a comment
There was a problem hiding this comment.
I’ve stated the spec in a positive way even though the change was motivated by a lack of behavior leading to an exception. Open to feedback if you think there’s a better way to express the spec.
Oh it's nice like that, don't worry.
What would be cool but very optional is to have the path leading to the exception covered.
Technically, the steps from the spec are exactly the path formerly triggering the behavior! Here’s an example before this change: Though I guess I could add the following to mimic the previous behavior but at that point I’m basically testing Ruby: resource = Hubspot::Resource.from_result({ id: 1, firstname: "Test" })
resource.send :method_missing, :[]=, :firstname, "Test"
resource[:firstname]
/home/ur5us/dev/repos/hubspot-api-ruby/lib/hubspot/resource.rb:239:in `block (3 levels) in add_accessors': wrong number of arguments (given 1, expected 0) (ArgumentError)
from (irb):8:in `<main>'
from <internal:kernel>:187:in `loop'
from bin/console:30:in `<main>'The real issue: |
fonji
left a comment
There was a problem hiding this comment.
Thanks!
Yeah no need to go further with the specs
Fix
add_accessors': wrong number of arguments (given 1, expected 0) (ArgumentError). The issue was the lack of[]=operator method definition which resulted in themethod_missinghook redefining[]method.