From a1c575386b225bc4ec59ddcf02921e7886a585b2 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Wed, 26 Dec 2018 19:53:35 -0500 Subject: [PATCH] [Fix #6603] - Testing RescueEnsureAlignment Add a test to demonstrate the correct styles of a begin-rescue as the RHS of an assignment. --- .../layout/rescue_ensure_alignment_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb b/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb index 4c042370c41..fddf6b4bcc4 100644 --- a/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb +++ b/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb @@ -36,6 +36,40 @@ end RUBY end + + context 'as RHS of assignment' do + it 'accepts multi-line, aligned' do + expect_no_offenses(<<-RUBY.strip_indent) + x ||= begin + 1 + rescue + 2 + end + RUBY + end + + it 'accepts multi-line, indented' do + expect_no_offenses(<<-RUBY.strip_indent) + x ||= + begin + 1 + rescue + 2 + end + RUBY + end + + it 'registers offense for incorrect alignment' do + expect_offense(<<-RUBY.strip_indent) + x ||= begin + 1 + rescue + ^^^^^^ `rescue` at 3, 0 is not aligned with `begin` at 1, 6. + 2 + end + RUBY + end + end end context 'rescue with def' do