@@ -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 \t puts result\n end\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 \t unless foo\n \t \t x = 10\n \t \t \n \t \t y = 20\n \t end\n end\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 \t unless foo\n \t \t x = 10\n \t \n \t \t y = 20\n \t end\n end\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
768807end
0 commit comments