diff --git a/.rspec b/.rspec index 16f9cdb0..b83d9b7a 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ --color --format documentation +--require spec_helper diff --git a/lib/pact_broker/client/versions.rb b/lib/pact_broker/client/versions.rb index 40a2a3aa..02097d99 100644 --- a/lib/pact_broker/client/versions.rb +++ b/lib/pact_broker/client/versions.rb @@ -1,4 +1,5 @@ require_relative 'base_client' +require 'pact_broker/client/pacts' module PactBroker module Client @@ -38,7 +39,7 @@ def pacts private def tag_url options - "#{version_base_url(options)}/tags/#{options.fetch(:tag)}" + "#{version_base_url(options)}/tags/#{encode_param(options.fetch(:tag))}" end def versions_base_url options diff --git a/pact-broker-client.gemspec b/pact-broker-client.gemspec index bf258f79..647f487d 100644 --- a/pact-broker-client.gemspec +++ b/pact-broker-client.gemspec @@ -30,4 +30,5 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'fakefs', '~> 0.4' gem.add_development_dependency 'rspec-fire' gem.add_development_dependency 'appraisal' + gem.add_development_dependency 'webmock', '~> 3.0' end diff --git a/spec/lib/pact_broker/client/versions_spec.rb b/spec/lib/pact_broker/client/versions_spec.rb index bae609bd..681fe159 100644 --- a/spec/lib/pact_broker/client/versions_spec.rb +++ b/spec/lib/pact_broker/client/versions_spec.rb @@ -5,12 +5,28 @@ module Client let(:client_options) do { some_option: 'option value'} end - let(:base_url) { 'https://blah' } + let(:base_url) { 'http://blah' } + let(:pacticipant_name) { 'Foo' } + let(:version_number) { '1.2.3' } + + subject { Versions.new(base_url: base_url, client_options: client_options) } describe 'pacts' do it 'initializes versions with base url and client options' do expect(PactBroker::Client::Pacts).to receive(:new).with(base_url: base_url, client_options: client_options) - Versions.new(base_url: base_url, client_options: client_options).pacts + subject.pacts + end + end + + describe 'tag' do + context "when the tag has a / in it" do + let(:tag) { 'feat/foo' } + let!(:request) { stub_request(:put, "http://blah/pacticipants/Foo/versions/1.2.3/tags/feat%2Ffoo").to_return(status: 200) } + + it "URL encodes the /" do + subject.tag(pacticipant: pacticipant_name, version: version_number, tag: tag) + expect(request).to have_been_made + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cef584ef..6553b688 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,7 @@ require 'rspec/fire' +require 'webmock/rspec' + +WebMock.disable_net_connect!(allow_localhost: true) RSpec.configure do | config | config.include RSpec::Fire