spec/swiftformat/plugin_spec.rb in danger-swiftformat-0.4.0 vs spec/swiftformat/plugin_spec.rb in danger-swiftformat-0.5.0

- old
+ new

@@ -52,9 +52,51 @@ expect(status[:errors]).to be_empty expect(status[:markdowns]).to be_empty end end + context "with additional_message" do + let(:additional_message) { "I'm the additional message." } + let(:error_output) { { errors: [{ file: "Modified.swift", rules: %w(firstRule secondRule) }], stats: { run_time: "0.16s" } } } + + it "should include the additional message in the report" do + allow(@sut.git).to receive(:added_files).and_return(["Added.swift"]) + allow(@sut.git).to receive(:modified_files).and_return(["Modified.swift"]) + allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"]) + allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true) + allow_any_instance_of(SwiftFormat).to receive(:check_format).with(%w(Added.swift Modified.swift), nil).and_return(error_output) + @sut.additional_message = additional_message + @sut.check_format(fail_on_error: true) + + status = @sut.status_report + markdown = status[:markdowns].first.message + expect(markdown).to include(additional_message) + end + end + + context "with exclude" do + let(:exclude) { %w(**/Modified.swift Pods/** Carthage/** **/*_autogenerated.swift) } + let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } } + + it "should filter the files passed to swiftformat" do + allow(@sut.git).to receive(:added_files).and_return(%w(Added.swift Pods/Test.swift Carthage/SQLite.swift Sources/Module/JSONParsing_autogenerated.swift)) + allow(@sut.git).to receive(:modified_files).and_return(["Source/Modified.swift"]) + allow(@sut.git).to receive(:deleted_files).and_return(["Deleted.swift"]) + allow_any_instance_of(SwiftFormat).to receive(:installed?).and_return(true) + allow_any_instance_of(SwiftFormat).to receive(:check_format) + .with(%w(Added.swift), nil) + .and_return(success_output) + + @sut.exclude = exclude + + @sut.check_format(fail_on_error: true) + + status = @sut.status_report + expect(status[:errors]).to be_empty + expect(status[:markdowns]).to be_empty + end + end + describe "#check_format" do let(:success_output) { { errors: [], stats: { run_time: "0.08s" } } } let(:error_output) { { errors: [{ file: "Modified.swift", rules: %w(firstRule secondRule) }], stats: { run_time: "0.16s" } } } context "when there are no swift files to check" do