From a1b5013fd5a2875bad1ebf55d49b0c453c9b6f47 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 16 Feb 2018 11:54:35 +1100 Subject: [PATCH] fix: replace backslashes in pact dir path with forward slashes Closes: https://github.com/pact-foundation/pact-js/issues/150 --- lib/pact/consumer_contract/file_name.rb | 6 +++++- spec/lib/pact/consumer_contract/file_name_spec.rb | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/pact/consumer_contract/file_name.rb b/lib/pact/consumer_contract/file_name.rb index 92c91da..bfc1f8e 100644 --- a/lib/pact/consumer_contract/file_name.rb +++ b/lib/pact/consumer_contract/file_name.rb @@ -8,11 +8,15 @@ def file_name consumer_name, provider_name, options = {} end def file_path consumer_name, provider_name, pact_dir = Pact.configuration.pact_dir, options = {} - File.join(pact_dir, file_name(consumer_name, provider_name, options)) + File.join(windows_safe(pact_dir), file_name(consumer_name, provider_name, options)) end def filenamify name name.downcase.gsub(/\s/, '_') end + + def windows_safe(pact_dir) + pact_dir.gsub("\\", "/") + end end end diff --git a/spec/lib/pact/consumer_contract/file_name_spec.rb b/spec/lib/pact/consumer_contract/file_name_spec.rb index 9a1f12a..e4a24cc 100644 --- a/spec/lib/pact/consumer_contract/file_name_spec.rb +++ b/spec/lib/pact/consumer_contract/file_name_spec.rb @@ -3,13 +3,22 @@ module Pact describe FileName do describe "file_path" do - let(:subject) { FileName.file_path 'foo', 'bar', 'tmp/pacts' } + + subject { FileName.file_path 'foo', 'bar', 'tmp/pacts' } it { is_expected.to eq 'tmp/pacts/foo-bar.json' } context "when unique is true" do - let(:subject) { FileName.file_path 'foo', 'bar', 'tmp/pacts', unique: true } + subject { FileName.file_path 'foo', 'bar', 'tmp/pacts', unique: true } it { is_expected.to match %r{tmp/pacts/foo-bar-\d+.json} } end + + context "when the path includes backslashes" do + subject { FileName.file_path 'foo', 'bar', 'c:\tmp\pacts' } + + it "changes them to forward slashes" do + expect(subject).to eq "c:/tmp/pacts/foo-bar.json" + end + end end end end