Skip to content

Commit 7668bd7

Browse files
committed
Add more specs for Struct#hash
1 parent 4a944fc commit 7668bd7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spec/ruby/core/struct/hash_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
car.hash.should == similar_car.hash
2020
end
2121

22+
it "returns different hashes for structs with different values" do
23+
s1 = StructClasses::Ruby.new('2.7.0', 'linux')
24+
s2 = StructClasses::Ruby.new('2.7.0', 'macos')
25+
s1.hash.should_not == s2.hash
26+
end
27+
28+
it "returns different hashes for structs with different values when using keyword_init: true" do
29+
key = :"1 non symbol member"
30+
struct_class = Struct.new(key, keyword_init: true)
31+
t1 = struct_class.new(key => 1)
32+
t2 = struct_class.new(key => 2)
33+
t1.hash.should_not == t2.hash
34+
end
35+
2236
it "allows for overriding methods in an included module" do
2337
mod = Module.new do
2438
def hash

0 commit comments

Comments
 (0)