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

Commit

Permalink
Handle Ruby 3.4 hash syntax changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Oct 18, 2024
1 parent a3e3c3d commit 3b539d0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions spec/rspec/support/object_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Support
# We can't count on the ordering of the hash on 1.8.7...
expect(formatted).to include(%Q{"key"=>#{formatted_time}}, %Q{#{formatted_time}=>"value"}, %Q{"nested"=>{"key"=>#{formatted_time}}})
else
expect(formatted).to eq(%Q{{"key"=>#{formatted_time}, #{formatted_time}=>"value", "nested"=>{"key"=>#{formatted_time}}}})
expect(formatted).to eq_hash_syntax(%Q{{"key"=>#{formatted_time}, #{formatted_time}=>"value", "nested"=>{"key"=>#{formatted_time}}}})
end
end
end
Expand All @@ -39,7 +39,7 @@ module Support

it 'sorts keys to ensure objects are always displayed the same way' do
formatted = ObjectFormatter.format(input)
expect(formatted).to eq expected
expect(formatted).to eq_hash_syntax expected
end
end
end
Expand Down Expand Up @@ -269,7 +269,7 @@ def self.to_s
let(:formatted_time) { ObjectFormatter.format(time) }

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

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

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

Expand All @@ -305,7 +305,7 @@ def self.to_s
end

it 'formats the recursive element as [...]' do
expect(output).to eq('[{:recursive_array=>[...]}]')
expect(output).to eq_hash_syntax('[{:recursive_array=>[...]}]')
end
end

Expand All @@ -321,7 +321,7 @@ def self.to_s
end

it 'formats the recursive element as {...}' do
expect(output).to eq('{:array=>[:next_is_recursive_hash, {...}]}')
expect(output).to eq_hash_syntax('{:array=>[:next_is_recursive_hash, {...}]}')
end
end

Expand All @@ -336,7 +336,7 @@ def self.to_s
end

it 'does not omit them' do
expect(output).to eq('[{:key=>"value"}, {:key=>"value"}]')
expect(output).to eq_hash_syntax('[{:key=>"value"}, {:key=>"value"}]')
end
end

Expand Down Expand Up @@ -370,6 +370,16 @@ def inspect
expect(formatter.format('Test String Of A Longer Length')).to eq('"Test String Of A Longer Length"')
end
end

if RUBY_VERSION.to_f > 3.3
def eq_hash_syntax(string)
eq string.gsub('=>', ' => ')
end
else
def eq_hash_syntax(string)
eq string
end
end
end
end
end

0 comments on commit 3b539d0

Please sign in to comment.