Skip to content

Commit 490a311

Browse files
committed
More tests.
1 parent 66f728d commit 490a311

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/rubocop/socketry/layout/consistent_blank_line_indentation.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,4 +765,43 @@ def foo
765765
end
766766
end
767767
end
768+
769+
with "a blank line inside a block with chained method call receiver" do
770+
let(:source) {"obj.method.tap do |result|\n\t\n\tputs result\nend\n"}
771+
772+
it "does not register an offense when blank line in block with chained method call is properly indented" do
773+
processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION.to_f)
774+
investigator = RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
775+
report = investigator.investigate(processed_source)
776+
offenses = report.offenses
777+
expect(offenses).to be(:empty?)
778+
end
779+
end
780+
781+
# This test case specifically demonstrates the issue described by the user
782+
with "a blank line inside nested unless block" do
783+
let(:source) {"def hello(foo)\n\tunless foo\n\t\tx = 10\n\t\t\n\t\ty = 20\n\tend\nend\n"}
784+
785+
it "should properly indent blank line with two tabs inside nested unless block" do
786+
processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION.to_f)
787+
investigator = RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
788+
report = investigator.investigate(processed_source)
789+
offenses = report.offenses
790+
expect(offenses).to be(:empty?)
791+
end
792+
end
793+
794+
# This test case shows the current incorrect behavior
795+
with "a blank line inside nested unless block with incorrect indentation" do
796+
let(:source) {"def hello(foo)\n\tunless foo\n\t\tx = 10\n\t\n\t\ty = 20\n\tend\nend\n"}
797+
798+
it "should register an offense when blank line has only one tab instead of two" do
799+
processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION.to_f)
800+
investigator = RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
801+
report = investigator.investigate(processed_source)
802+
offenses = report.offenses
803+
expect(offenses).not.to be(:empty?)
804+
expect(offenses.first.message).to be(:include?, message)
805+
end
806+
end
768807
end

0 commit comments

Comments
 (0)