Skip to content

Commit

Permalink
fix: replace backslashes in pact dir path with forward slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 16, 2018
1 parent 7469b1c commit a1b5013
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/pact/consumer_contract/file_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions spec/lib/pact/consumer_contract/file_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a1b5013

Please sign in to comment.