Module: Pact::TaskHelper
Constant Summary collapse
- PACT_INTERACTION_RERUN_COMMAND =
"bundle exec rake pact:verify:at[<PACT_URI>] PACT_DESCRIPTION=\"<PACT_DESCRIPTION>\" PACT_PROVIDER_STATE=\"<PACT_PROVIDER_STATE>\""
- PACT_INTERACTION_RERUN_COMMAND_FOR_BROKER =
"bundle exec rake pact:verify:at[<PACT_URI>] PACT_BROKER_INTERACTION_ID=\"<PACT_BROKER_INTERACTION_ID>\""
Instance Method Summary collapse
- #execute_cmd(command) ⇒ Object
- #execute_pact_verify(pact_uri = nil, pact_helper = nil, rspec_opts = nil, verification_opts = {}) ⇒ Object
- #handle_verification_failure ⇒ Object
- #temporarily_set_env_var(name, value) ⇒ Object
- #verify_command(pact_helper, pact_uri, rspec_opts, verification_opts) ⇒ Object
Instance Method Details
#execute_cmd(command) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pact/tasks/task_helper.rb', line 43 def execute_cmd command Pact.configuration.output_stream.puts command temporarily_set_env_var 'PACT_EXECUTING_LANGUAGE', 'ruby' do temporarily_set_env_var 'PACT_INTERACTION_RERUN_COMMAND', PACT_INTERACTION_RERUN_COMMAND do temporarily_set_env_var 'PACT_INTERACTION_RERUN_COMMAND_FOR_BROKER', PACT_INTERACTION_RERUN_COMMAND_FOR_BROKER do exit_status = system(command) ? 0 : 1 end end end end |
#execute_pact_verify(pact_uri = nil, pact_helper = nil, rspec_opts = nil, verification_opts = {}) ⇒ Object
14 15 16 |
# File 'lib/pact/tasks/task_helper.rb', line 14 def execute_pact_verify pact_uri = nil, pact_helper = nil, rspec_opts = nil, verification_opts = {} execute_cmd verify_command(pact_helper || Pact::Provider::PactHelperLocater.pact_helper_path, pact_uri, rspec_opts, verification_opts) end |
#handle_verification_failure ⇒ Object
18 19 20 21 |
# File 'lib/pact/tasks/task_helper.rb', line 18 def handle_verification_failure exit_status = yield abort if exit_status != 0 end |
#temporarily_set_env_var(name, value) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/pact/tasks/task_helper.rb', line 54 def temporarily_set_env_var name, value original_value = ENV[name] ENV[name] ||= value yield ensure ENV[name] = original_value end |
#verify_command(pact_helper, pact_uri, rspec_opts, verification_opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pact/tasks/task_helper.rb', line 23 def verify_command pact_helper, pact_uri, rspec_opts, verification_opts command_parts = [] # Clear SPEC_OPTS, otherwise we can get extra formatters, creating duplicate output eg. CI Reporting. # Allow deliberate configuration using rspec_opts in VerificationTask. command_parts << "SPEC_OPTS=#{Shellwords.escape(rspec_opts || '')}" command_parts << FileUtils::RUBY command_parts << "-S pact verify" command_parts << "--pact-helper" << Shellwords.escape(pact_helper.end_with?(".rb") ? pact_helper : pact_helper + ".rb") (command_parts << "--pact-uri" << pact_uri) if pact_uri command_parts << "--ignore-failures" if verification_opts[:ignore_failures] command_parts << "--pact-broker-username" << ENV['PACT_BROKER_USERNAME'] if ENV['PACT_BROKER_USERNAME'] command_parts << "--pact-broker-password" << ENV['PACT_BROKER_PASSWORD'] if ENV['PACT_BROKER_PASSWORD'] command_parts << "--backtrace" if ENV['BACKTRACE'] == 'true' command_parts << "--description #{Shellwords.escape(ENV['PACT_DESCRIPTION'])}" if ENV['PACT_DESCRIPTION'] command_parts << "--provider-state #{Shellwords.escape(ENV['PACT_PROVIDER_STATE'])}" if ENV['PACT_PROVIDER_STATE'] command_parts << "--pact-broker-interaction-id #{Shellwords.escape(ENV['PACT_BROKER_INTERACTION_ID'])}" if ENV['PACT_BROKER_INTERACTION_ID'] command_parts << "--interaction-index #{Shellwords.escape(ENV['PACT_INTERACTION_INDEX'])}" if ENV['PACT_INTERACTION_INDEX'] command_parts.flatten.join(" ") end |