Skip to content

Commit

Permalink
feat(pact publish): strip new lines from version numbers and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 19, 2020
1 parent 9b849d3 commit 5842d24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/pact_broker/client/publish_pacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion spec/lib/pact_broker/client/publish_pacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5842d24

Please sign in to comment.