Commit 6308be63

6308be6334bbMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Make struct_to_h_block test independent of Hash#inspect spacing

The test compared Hash#inspect output, which Ruby 3.4 changed to put spaces around => ({"k" => v}) while Spinel still emits the older {"k"=>v}. CI (Ruby 3.4) therefore failed the test even though the Struct#to_h block transformation is correct. Assert the values via key lookup and size instead, so the test passes regardless of the inspect spacing. No behavior change.

Refs #1222

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
6308be6334bb
Parent
acf4c4704ffb

test/struct_to_h_block.rbmodifiedView file

@@ -1,19 +1,30 @@
11 # Struct#to_h with a block yields each (member_symbol, value) pair and
2-# builds a hash from the [k, v] arrays the block returns. The block keys
3-# below are stringified so the output is independent of the symbol-key
4-# inspect format (which differs across Ruby versions).
2+# builds a hash from the [k, v] arrays the block returns. Values are
3+# asserted via key lookup rather than Hash#inspect so the test does not
4+# depend on the `=>` inspect spacing, which differs across Ruby versions.
55 Person = Struct.new(:name, :age)
66 p = Person.new("Alice", 30)
7-puts(p.to_h { |name, val| [name.to_s, val] }.inspect)
7+h = p.to_h { |name, val| [name.to_s, val] }
8+puts h["name"]
9+puts h["age"]
10+puts h.size
811
912 Point = Struct.new(:x, :y)
1013 pt = Point.new(3, 4)
1114 # transform the value too
12-puts(pt.to_h { |k, v| [k.to_s, v * 2] }.inspect)
15+h2 = pt.to_h { |k, v| [k.to_s, v * 2] }
16+puts h2["x"]
17+puts h2["y"]
18+
1319 # both elements stringified (block returns a str_array)
14-puts(pt.to_h { |k, v| [k.to_s, v.to_s] }.inspect)
20+h3 = pt.to_h { |k, v| [k.to_s, v.to_s] }
21+puts h3["x"]
22+puts h3["y"]
1523
1624 # heterogeneous members (string, int, bool)
1725 Rec = Struct.new(:label, :count, :on)
1826 r = Rec.new("widget", 7, true)
19-puts(r.to_h { |k, v| [k.to_s, v] }.inspect)
27+h4 = r.to_h { |k, v| [k.to_s, v] }
28+puts h4["label"]
29+puts h4["count"]
30+puts h4["on"]