A failing spec with expect(value).to eq(1.0) throws a NoMethodError instead.
Closed this issue · 3 comments
ransombriggs commented
I get NoMethodError
when doing a diff against a float constant because of how ObjectSpace.dump(object)
treats floats.
# here is the problematic line in helpers.rb
address = JSON.parse(ObjectSpace.dump(object))["address"]
ObjectSpace.dump(1.0)
=> "1.00000"
# rough fix, not sure what you want to happen if JSON.parse is not a hash
def object_address_for(object)
# Sources: <https://bugs.ruby-lang.org/issues/15408> and <https://bugs.ruby-lang.org/issues/15626#Object-ID>
address = JSON.parse(ObjectSpace.dump(object)).try(:[], "address")
if address
"0x%016x" % Integer(address, 16)
else
# I am not certain what you would want here
end
end
mcmire commented
Hey! Thanks for the heads-up on this. I'm not sure why I haven't encountered it so far!
In terms of your patch, that seems like that could work. For the else
case, I think we'd want to just return an empty string.
If you're down to submit a PR with this patch and add a test or two close to here, then I can get this in!
ransombriggs commented
I pushed up a PR for this: #146