Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float issue with object space dump #146

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 2.5.9
ruby 2.7.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change! Mind putting this in another PR? This seems like something someone may want to track down later and I don't want it to get lost in this one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, take that back — since we still support Ruby 2.5 as the minimum tested version, we probably want to leave this alone :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted it in 2450859

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this error in the test suite

            NoMethodError:
              undefined method `try' for #<Hash>
              Did you mean?  pry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 55d9dc2 should fix that issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remainder that are failing are probably due to an issue with ruby version + minitest version issues, I pushed up #148 to try and fix the issue

8 changes: 6 additions & 2 deletions lib/super_diff/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ def object_address_for(object)

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))["address"]
"0x%016x" % Integer(address, 16)
address = JSON.parse(ObjectSpace.dump(object)).try(:[], "address")
if address
"0x%016x" % Integer(address, 16)
else
""
end
end
else
def object_address_for(object)
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
end
end
end

describe "object_address_for" do
if SuperDiff::Helpers.ruby_version_matches?(">= 2.7.0")
it "returns an empty string for Floats" do
expect(helper.object_address_for(1.0)).to eq("")
end

it "returns an object address for Objects" do
object = Object.new
address = JSON.parse(ObjectSpace.dump(object))["address"]
expect(helper.object_address_for(object)).to eq("0x%016x" % Integer(address, 16))
end
end
end
end

describe 'as class methods' do
Expand Down