Skip to content

Commit

Permalink
Add spec for Style/RescueModifier
Browse files Browse the repository at this point in the history
The following syntax changes in Ruby 2.7, so the offense highlight range
of `Style/RescueModifier` was changed.
ruby/ruby@53b3be5

For the role of `Style/RescueModifier`, it seems reasonable to have different
offense highlight ranges between Ruby 2.6 and 2.7 against these syntax.
So just adding a test should be enough I think.
  • Loading branch information
koic authored and bbatsov committed Apr 12, 2023
1 parent 2d20ed2 commit 67c5ab5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion spec/rubocop/cop/style/rescue_modifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
RUBY
end

it 'registers an offense for modifier rescue around parallel assignment' do
it 'registers an offense for modifier rescue around parallel assignment', :ruby26 do
expect_offense(<<~RUBY)
a, b = 1, 2 rescue nil
^^^^^^^^^^^^^^^^^^^^^^ Avoid using `rescue` in its modifier form.
RUBY
end

it 'registers an offense for modifier rescue around parallel assignment', :ruby27 do
expect_offense(<<~RUBY)
a, b = 1, 2 rescue nil
^^^^^^^^^^^^^^^ Avoid using `rescue` in its modifier form.
RUBY
end

it 'handles more complex expression with modifier rescue' do
expect_offense(<<~RUBY)
method1 or method2 rescue handle
Expand Down

0 comments on commit 67c5ab5

Please sign in to comment.