Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

removed inconsistent hash accessor #67

Closed
wants to merge 1 commit into from

2 participants

@seancaffery

The #hash algorithm in Ruby is not consistent across Rubies. This causes a problem when running the specs (specifically hotspots_spec.rb)
I have added some specs that test the equality function of MetricFu::Location without using actual hash values to ensure that I don't break anything.

@bf4 bf4 referenced this pull request in metricfu/metric_fu
Closed

removed inconsistent hash accessor #19

@bf4
Collaborator
bf4 commented

Gem no longer maintained, See https://github.com/metricfu/metric_fu

@bf4 bf4 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 1 deletion.
  1. +1 −1  lib/base/location.rb
  2. +28 −0 spec/base/location_spec.rb
View
2  lib/base/location.rb
@@ -31,7 +31,7 @@ def initialize(file_path, class_name, method_name)
# TODO - we need this method (and hash accessor above) as a temporary hack where we're using Location as a hash key
def eql?(other)
- [self.file_path.to_s, self.class_name.to_s, self.method_name.to_s] == [other.file_path.to_s, other.class_name.to_s, other.method_name.to_s]
+ @hash == other.hash
end
# END we need these methods as a temporary hack where we're using Location as a hash key
View
28 spec/base/location_spec.rb
@@ -94,5 +94,33 @@
end
end
+ context "testing equality" do
+ before :each do
+ @location1 = MetricFu::Location.get('/some/path','some_class','some_method')
+
+ # ensure that we get a new object
+ @location2 = MetricFu::Location.new('/some/path','some_class','some_method')
+ end
+ it "should match two locations with the same paths as equal" do
+
+ hsh1 = {}
+ hsh1[@location1] = 1
+
+ hsh2 = {}
+ hsh2[@location2] = 1
+
+ hsh1.should == hsh2
+ hsh1.eql?(hsh2).should be_true
+
+ @location1.eql?(@location2).should be_true
+ end
+
+
+ it "should produce the same hash value given the same paths" do
+
+ @location1.hash.should == @location2.hash
+ end
+
+ end
end
Something went wrong with that request. Please try again.