diff --git a/spec/rubocop/cop/performance/unfreeze_string_spec.rb b/spec/rubocop/cop/performance/unfreeze_string_spec.rb index c782e7896..204e028e0 100644 --- a/spec/rubocop/cop/performance/unfreeze_string_spec.rb +++ b/spec/rubocop/cop/performance/unfreeze_string_spec.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::Performance::UnfreezeString, :config do + context 'when Ruby >= 3.3', :ruby33 do + it 'does not register an offense and corrects for an empty string with `.dup`' do + expect_no_offenses(<<~RUBY) + "".dup + RUBY + end + end + context 'when Ruby <= 3.2', :ruby32 do it 'registers an offense and corrects for an empty string with `.dup`' do expect_offense(<<~RUBY) @@ -12,53 +20,45 @@ +"" RUBY end - end - context 'when Ruby >= 3.3', :ruby33 do - it 'does not register an offense and corrects for an empty string with `.dup`' do - expect_no_offenses(<<~RUBY) - "".dup + it 'registers an offense and corrects for a string with `.dup`' do + expect_offense(<<~RUBY) + "foo".dup + ^^^^^^^^^ Use unary plus to get an unfrozen string literal. RUBY - end - end - it 'registers an offense and corrects for a string with `.dup`' do - expect_offense(<<~RUBY) - "foo".dup - ^^^^^^^^^ Use unary plus to get an unfrozen string literal. - RUBY - - expect_correction(<<~RUBY) - +"foo" - RUBY - end + expect_correction(<<~RUBY) + +"foo" + RUBY + end - it 'registers an offense and corrects for a heredoc with `.dup`' do - expect_offense(<<~RUBY) - <