Skip to content

Instantly share code, notes, and snippets.

@gwik
Created January 22, 2014 17:31
Show Gist options
  • Save gwik/8563158 to your computer and use it in GitHub Desktop.
Save gwik/8563158 to your computer and use it in GitHub Desktop.
Spec demonstrating broken weakref as hash key in rubymotion.
describe "WeakRef hash support" do
before do
@k = "key"
@w = WeakRef.new(@k)
@h = {@w => :value}
end
it "can be accessed with the original object" do
@h[@k].should == :value
end
it "can be accessed with the equal string" do
@h["key"].should == :value
end
it "can be accessed with an other weakref to the same string" do
k2 = "key"
w2 = WeakRef.new(k2)
@h[w2].should == :value
end
it "can be accessed with the weakref" do
@h[@w].should == :value
end
it "string is eql? to weakref" do
@k.should.eql?(@w)
end
it "weakref is eql? to string" do
@w.should.eql?(@k)
end
it "has the same hash" do
@k.hash.should == @w.hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment