spec/plugins/pre_commit/message/extractor_spec.rb in java-checkstyle-1.0.3 vs spec/plugins/pre_commit/message/extractor_spec.rb in java-checkstyle-1.0.4

- old
+ new

@@ -8,43 +8,43 @@ describe PreCommit::Message::Extractor do let(:extractor) { PreCommit::Message::Extractor.new } context "When nil output" do it "should be good" do - result = extractor.extract nil - expect(result).to be_good + expect( extractor.extract(nil) ).to be_good end end context "When empty output" do it "should be good" do - result = extractor.extract '' - expect(result).to be_good + expect( extractor.extract('') ).to be_good end end context "When has one bad file" do # given let(:output) { IO.read(fixture_file("output_one_bad_file.log")) } + # when + before { @checkstyle = extractor.extract(output) } + + # then it "should not be good" do - result = extractor.extract output - expect(result).to_not be_good + expect( @checkstyle ).to_not be_good end it "should contain one single file" do - result = extractor.extract output - expect(result.bad_files).to be_a Array + expect( @checkstyle.bad_files ).to be_a Array end it "should contain its errors" do - result = extractor.extract output - expect(result.bad_files[0].errors.size).to eq 2 + expect( @checkstyle.bad_files[0].errors.size ).to be 2 end it "should extract error details" do - expected = [ + expect( @checkstyle.bad_files[0].errors ).to eq( + [ { "line"=>"1", "severity"=>"error", "message"=>"some error message", "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck" @@ -54,39 +54,38 @@ "column" => "1 ", "severity" => "warning", "message" => "some error message", "source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck" } - ] - - result = extractor.extract output - errors = result.bad_files[0].errors - expect(errors).to eq expected + ] + ) end end context "When has multiple bad files" do + # given let(:output) { IO.read(fixture_file("output_two_bad_files.log")) } + # when + before { @checkstyle = extractor.extract output } + + # then it "should not be good" do - result = extractor.extract output - expect(result).to_not be_good + expect( @checkstyle ).to_not be_good end it "should extract multiple files" do - result = extractor.extract output - expect(result.bad_files).to be_a Array + expect( @checkstyle.bad_files ).to be_a Array end it "should extract their errors" do - result = extractor.extract output - expect(result.bad_files[0].errors.size).to eq 2 - expect(result.bad_files[1].errors.size).to eq 2 + expect( @checkstyle.bad_files[0].errors.size ).to be 2 + expect( @checkstyle.bad_files[1].errors.size ).to be 2 end it "should extract error details" do - expected = [ + expect( @checkstyle.bad_files[0].errors ).to eq ([ { "line"=>"1", "severity"=>"error", "message"=>"some error message", "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck" @@ -96,13 +95,9 @@ "column" => "1 ", "severity" => "warning", "message" => "some error message", "source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck" } - ] - - result = extractor.extract output - - expect(result.bad_files[0].errors).to eq expected + ]) end end end