From 5842d2428703fbc9dc4b52e47fdb97e7ed8fc298 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 20 Nov 2020 10:59:49 +1100 Subject: [PATCH] feat(pact publish): strip new lines from version numbers and tags --- lib/pact_broker/client/publish_pacts.rb | 4 ++-- .../pact_broker/client/publish_pacts_spec.rb | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/pact_broker/client/publish_pacts.rb b/lib/pact_broker/client/publish_pacts.rb index 9af7d5f5..dd93e5f9 100644 --- a/lib/pact_broker/client/publish_pacts.rb +++ b/lib/pact_broker/client/publish_pacts.rb @@ -16,8 +16,8 @@ def self.call(pact_broker_base_url, pact_file_paths, consumer_version, tags, pac def initialize pact_broker_base_url, pact_file_paths, consumer_version, tags, pact_broker_client_options={} @pact_broker_base_url = pact_broker_base_url @pact_file_paths = pact_file_paths - @consumer_version = consumer_version - @tags = tags + @consumer_version = consumer_version.respond_to?(:strip) ? consumer_version.strip : consumer_version + @tags = tags ? tags.collect{ |tag| tag.respond_to?(:strip) ? tag.strip : tag } : tags @pact_broker_client_options = pact_broker_client_options end diff --git a/spec/lib/pact_broker/client/publish_pacts_spec.rb b/spec/lib/pact_broker/client/publish_pacts_spec.rb index ec417118..04740072 100644 --- a/spec/lib/pact_broker/client/publish_pacts_spec.rb +++ b/spec/lib/pact_broker/client/publish_pacts_spec.rb @@ -62,12 +62,12 @@ module Client end context "when publishing is successful" do - it "puts the location of the latest pact" do allow($stdout).to receive(:puts) expect($stdout).to receive(:puts).with(/#{latest_pact_url}/) subject.call end + it "returns true" do expect(subject.call).to be true end @@ -142,6 +142,15 @@ module Client end end + context "when consumer_version has a new line" do + let(:consumer_version) { "1\n" } + + it "strips the new line" do + expect(pacts_client).to receive(:publish).with(pact_hash: pact_hash, consumer_version: "1") + subject.call + end + end + context "when pact_broker_base_url is blank" do let(:pact_broker_base_url) { " " } it "raises a validation errror" do @@ -164,6 +173,16 @@ module Client subject.call end + context "when the tag has a new line on the end of it" do + let(:tags) { ["foo\n"] } + + it "strips the newline" do + expect(pact_versions_client).to receive(:tag).with({pacticipant: "Consumer", + version: consumer_version, tag: "foo"}) + subject.call + end + end + context "when an error occurs tagging the pact" do before do