diff --git a/spec/rubocop/cop/style/sole_nested_conditional_spec.rb b/spec/rubocop/cop/style/sole_nested_conditional_spec.rb index 4e0ad4bceb5..d3aadf73ea2 100644 --- a/spec/rubocop/cop/style/sole_nested_conditional_spec.rb +++ b/spec/rubocop/cop/style/sole_nested_conditional_spec.rb @@ -178,6 +178,38 @@ RUBY end + it 'registers an offense and corrects when using `unless` and `||` and parens in the outer condition' \ + 'and nested modifier condition ' do + expect_offense(<<~RUBY) + unless (foo || bar) + do_something if baz + ^^ Consider merging nested conditions into outer `unless` conditions. + end + RUBY + + expect_correction(<<~RUBY) + if !(foo || bar) && baz + do_something + end + RUBY + end + + it 'registers an offense and corrects when using `unless` and `||` without parens in the outer condition' \ + 'and nested modifier condition ' do + expect_offense(<<~RUBY) + unless foo || bar + do_something if baz + ^^ Consider merging nested conditions into outer `unless` conditions. + end + RUBY + + expect_correction(<<~RUBY) + if !(foo || bar) && baz + do_something + end + RUBY + end + it 'registers an offense and corrects for multiple nested conditionals' do expect_offense(<<~RUBY) if foo