Skip to content

Commit a1b5013

Browse files
committed
fix: replace backslashes in pact dir path with forward slashes
Closes: pact-foundation/pact-js#150
1 parent 7469b1c commit a1b5013

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/pact/consumer_contract/file_name.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ def file_name consumer_name, provider_name, options = {}
88
end
99

1010
def file_path consumer_name, provider_name, pact_dir = Pact.configuration.pact_dir, options = {}
11-
File.join(pact_dir, file_name(consumer_name, provider_name, options))
11+
File.join(windows_safe(pact_dir), file_name(consumer_name, provider_name, options))
1212
end
1313

1414
def filenamify name
1515
name.downcase.gsub(/\s/, '_')
1616
end
17+
18+
def windows_safe(pact_dir)
19+
pact_dir.gsub("\\", "/")
20+
end
1721
end
1822
end

spec/lib/pact/consumer_contract/file_name_spec.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
module Pact
44
describe FileName do
55
describe "file_path" do
6-
let(:subject) { FileName.file_path 'foo', 'bar', 'tmp/pacts' }
6+
7+
subject { FileName.file_path 'foo', 'bar', 'tmp/pacts' }
78
it { is_expected.to eq 'tmp/pacts/foo-bar.json' }
89

910
context "when unique is true" do
10-
let(:subject) { FileName.file_path 'foo', 'bar', 'tmp/pacts', unique: true }
11+
subject { FileName.file_path 'foo', 'bar', 'tmp/pacts', unique: true }
1112
it { is_expected.to match %r{tmp/pacts/foo-bar-\d+.json} }
1213
end
14+
15+
context "when the path includes backslashes" do
16+
subject { FileName.file_path 'foo', 'bar', 'c:\tmp\pacts' }
17+
18+
it "changes them to forward slashes" do
19+
expect(subject).to eq "c:/tmp/pacts/foo-bar.json"
20+
end
21+
end
1322
end
1423
end
1524
end

0 commit comments

Comments
 (0)