Skip to content

Commit 43d34c0

Browse files
authored
Merge pull request pact-foundation#155 from iamvery/quote-path-to-support-spaces
fix: escape --pact-helper CLI option
2 parents a94d4e1 + 92b9a6b commit 43d34c0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/pact/tasks/task_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def verify_command pact_helper, pact_uri, rspec_opts
2626
command_parts << "SPEC_OPTS=#{Shellwords.escape(rspec_opts || '')}"
2727
command_parts << FileUtils::RUBY
2828
command_parts << "-S pact verify"
29-
command_parts << "--pact-helper" << (pact_helper.end_with?(".rb") ? pact_helper : pact_helper + ".rb")
29+
command_parts << "--pact-helper" << Shellwords.escape(pact_helper.end_with?(".rb") ? pact_helper : pact_helper + ".rb")
3030
(command_parts << "--pact-uri" << pact_uri) if pact_uri
3131
command_parts << "--pact-broker-username" << ENV['PACT_BROKER_USERNAME'] if ENV['PACT_BROKER_USERNAME']
3232
command_parts << "--pact-broker-password" << ENV['PACT_BROKER_PASSWORD'] if ENV['PACT_BROKER_PASSWORD']
@@ -53,4 +53,4 @@ def temporarily_set_env_var name, value
5353
ENV[name] = original_value
5454
end
5555
end
56-
end
56+
end

spec/lib/pact/tasks/task_helper_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ module Pact
9090
end
9191
end
9292

93+
context "with a pact_helper with whitespace in its path" do
94+
let(:custom_pact_helper_path) { '/path/to the/pact_helper.rb' }
95+
let(:escaped_custom_pact_helper_path) { '/path/to\\ the/pact_helper.rb' }
96+
let(:command) { "SPEC_OPTS='' #{ruby_path} -S pact verify --pact-helper #{escaped_custom_pact_helper_path} --pact-uri #{pact_uri}" }
97+
it "executes the command" do
98+
expect(TaskHelper).to receive(:execute_cmd).with(command)
99+
TaskHelper.execute_pact_verify(pact_uri, custom_pact_helper_path)
100+
end
101+
end
102+
93103
context "with a pact_helper with no .rb on the end" do
94104
let(:custom_pact_helper_path) { '/custom/pact_helper' }
95105
let(:command) { "SPEC_OPTS='' #{ruby_path} -S pact verify --pact-helper #{custom_pact_helper_path}.rb --pact-uri #{pact_uri}" }

0 commit comments

Comments
 (0)