Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit c316afd

Browse files
authored
Merge pull request #616 from rspec/ruby-34-fixes
Fix hash formatting in specs on Ruby 3.4
2 parents a3e3c3d + c4364ea commit c316afd

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

spec/rspec/support/differ_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ def inspect; "<BrokenObject>"; end
306306
|
307307
EOD
308308

309+
expected_diff.gsub!('=>',' => ') if RUBY_VERSION.to_f > 3.3
310+
309311
diff = differ.diff(expected,actual)
310312
expect(diff).to be_diffed_as(expected_diff)
311313
end
@@ -375,6 +377,7 @@ def inspect; "<BrokenObject>"; end
375377
|+"c" => {"key_1"=>#{formatted_time}},
376378
|
377379
EOD
380+
expected_diff.gsub!('"=>','" => ') if RUBY_VERSION.to_f > 3.3
378381

379382
left_side_hash = {'c' => {'key_1' => time}}
380383
right_side_hash = {'b' => {'key_1' => time}}
@@ -408,6 +411,7 @@ def inspect; "<BrokenObject>"; end
408411
|+[{"a"=>#{formatted_time}}, "c"]
409412
|
410413
EOD
414+
expected_diff.gsub!('=>',' => ') if RUBY_VERSION.to_f > 3.3
411415

412416
left_side_array = [{'a' => time}, 'c']
413417
right_side_array = [{'b' => time}, 'c']

spec/rspec/support/object_formatter_spec.rb

+17-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Support
2727
# We can't count on the ordering of the hash on 1.8.7...
2828
expect(formatted).to include(%Q{"key"=>#{formatted_time}}, %Q{#{formatted_time}=>"value"}, %Q{"nested"=>{"key"=>#{formatted_time}}})
2929
else
30-
expect(formatted).to eq(%Q{{"key"=>#{formatted_time}, #{formatted_time}=>"value", "nested"=>{"key"=>#{formatted_time}}}})
30+
expect(formatted).to eq_hash_syntax(%Q{{"key"=>#{formatted_time}, #{formatted_time}=>"value", "nested"=>{"key"=>#{formatted_time}}}})
3131
end
3232
end
3333
end
@@ -39,7 +39,7 @@ module Support
3939

4040
it 'sorts keys to ensure objects are always displayed the same way' do
4141
formatted = ObjectFormatter.format(input)
42-
expect(formatted).to eq expected
42+
expect(formatted).to eq_hash_syntax expected
4343
end
4444
end
4545
end
@@ -269,7 +269,7 @@ def self.to_s
269269
let(:formatted_time) { ObjectFormatter.format(time) }
270270

271271
it 'formats the recursive element as {...} and other elements with custom formatting' do
272-
expect(output).to eq("{{...}=>#{formatted_time}}")
272+
expect(output).to eq_hash_syntax("{{...}=>#{formatted_time}}")
273273
end
274274
end
275275

@@ -289,7 +289,7 @@ def self.to_s
289289
let(:formatted_time) { ObjectFormatter.format(time) }
290290

291291
it 'formats the recursive element as {...} and other elements with custom formatting' do
292-
expect(output).to eq("{#{formatted_time}=>{...}}")
292+
expect(output).to eq_hash_syntax("{#{formatted_time}=>{...}}")
293293
end
294294
end
295295

@@ -305,7 +305,7 @@ def self.to_s
305305
end
306306

307307
it 'formats the recursive element as [...]' do
308-
expect(output).to eq('[{:recursive_array=>[...]}]')
308+
expect(output).to eq_hash_syntax('[{:recursive_array=>[...]}]')
309309
end
310310
end
311311

@@ -321,7 +321,7 @@ def self.to_s
321321
end
322322

323323
it 'formats the recursive element as {...}' do
324-
expect(output).to eq('{:array=>[:next_is_recursive_hash, {...}]}')
324+
expect(output).to eq_hash_syntax('{:array=>[:next_is_recursive_hash, {...}]}')
325325
end
326326
end
327327

@@ -336,7 +336,7 @@ def self.to_s
336336
end
337337

338338
it 'does not omit them' do
339-
expect(output).to eq('[{:key=>"value"}, {:key=>"value"}]')
339+
expect(output).to eq_hash_syntax('[{:key=>"value"}, {:key=>"value"}]')
340340
end
341341
end
342342

@@ -370,6 +370,16 @@ def inspect
370370
expect(formatter.format('Test String Of A Longer Length')).to eq('"Test String Of A Longer Length"')
371371
end
372372
end
373+
374+
if RUBY_VERSION.to_f > 3.3
375+
def eq_hash_syntax(string)
376+
eq string.gsub('=>', ' => ')
377+
end
378+
else
379+
def eq_hash_syntax(string)
380+
eq string
381+
end
382+
end
373383
end
374384
end
375385
end

0 commit comments

Comments
 (0)