Skip to content

Commit

Permalink
fix: correctly read local windows pact file paths with backslashes
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 21, 2018
1 parent ff0ce2d commit e27bd38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pact/consumer_contract/pact_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def save_pactfile_to_tmp pact, name
end

def render_pact(uri_string, options)
uri_obj = URI(uri_string)
uri_obj = URI(windows_safe(uri_string))
if uri_obj.userinfo
options[:username] = uri_obj.user unless options[:username]
options[:password] = uri_obj.password unless options[:password]
Expand Down Expand Up @@ -104,5 +104,9 @@ def abort_retry?(count, options)
def delay_retry(count)
Kernel.sleep(2 ** count * 0.3)
end

def windows_safe(uri)
uri.start_with?("http") ? uri : uri.gsub("\\", File::SEPARATOR)
end
end
end
9 changes: 9 additions & 0 deletions spec/lib/pact/consumer_contract/pact_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ module Pact
end
end

describe 'with backslashes to a local path' do
let(:windows_path) { 'spec\support\a_consumer-a_provider.json' }
let(:unix_path) { 'spec/support/a_consumer-a_provider.json' }

it 'transforms them to forward slashes' do
expect(PactFile.read(windows_path)).to eq PactFile.read(unix_path)
end
end

context 'without basic authentication' do
before do
stub_request(:get, uri_without_userinfo).to_return(body: pact_content)
Expand Down

0 comments on commit e27bd38

Please sign in to comment.