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

- old
+ new

@@ -1,36 +1,46 @@ require 'spec_helper' -require 'plugins/pre_commit/message/extractor' +require 'plugins/pre-commit/message/extractor' +require 'plugins/pre-commit/domain/checkstyle' +require 'plugins/pre-commit/domain/bad_file' + ## # Tests for PreCommit::Message::Extractor describe PreCommit::Message::Extractor do let(:extractor) { PreCommit::Message::Extractor.new } - context "empty output" do - it "should return empty file for nil output" do + context "When nil output" do + it "should be good" do result = extractor.extract nil - expect(result['checkstyle']['file']).to be_empty + expect(result).to be_good end + end - it "should return empty file for empty output" do + context "When empty output" do + it "should be good" do result = extractor.extract '' - expect(result['checkstyle']['file']).to be_empty + expect(result).to be_good end end - context "has one bad file" do + context "When has one bad file" do # given let(:output) { IO.read(fixture_file("output_one_bad_file.log")) } + it "should not be good" do + result = extractor.extract output + expect(result).to_not be_good + end + it "should contain one single file" do result = extractor.extract output - expect(result['checkstyle']['file']).to be_a Hash + expect(result.bad_files).to be_a Array end it "should contain its errors" do result = extractor.extract output - expect(result['checkstyle']['file']['error'].size).to eq 2 + expect(result.bad_files[0].errors.size).to eq 2 end it "should extract error details" do expected = [ { @@ -47,27 +57,32 @@ "source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck" } ] result = extractor.extract output - errors = result['checkstyle']['file']['error'] + errors = result.bad_files[0].errors expect(errors).to eq expected end end - context "has multiple bad files" do + context "When has multiple bad files" do let(:output) { IO.read(fixture_file("output_two_bad_files.log")) } + it "should not be good" do + result = extractor.extract output + expect(result).to_not be_good + end + it "should extract multiple files" do result = extractor.extract output - expect(result['checkstyle']['file']).to be_a Array + expect(result.bad_files).to be_a Array end it "should extract their errors" do result = extractor.extract output - expect(result['checkstyle']['file'][0]['error'].size).to eq 2 - expect(result['checkstyle']['file'][1]['error'].size).to eq 2 + expect(result.bad_files[0].errors.size).to eq 2 + expect(result.bad_files[1].errors.size).to eq 2 end it "should extract error details" do expected = [ { @@ -84,10 +99,10 @@ "source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck" } ] result = extractor.extract output - errors = result['checkstyle']['file'][0]['error'] - expect(errors).to eq expected + + expect(result.bad_files[0].errors).to eq expected end end end