Created
April 21, 2015 23:21
-
-
Save bethesque/08d4c4cca2e76653420b to your computer and use it in GitHub Desktop.
Ordered provider verification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pact/provider/proxy/tasks' | |
Pact::ProxyVerificationTask.new :userapi_service do | task | | |
task.pact_url './spec/pacts/userapi_service_consumer-userapi_service_provider.json' | |
task.provider_base_url 'https://userapi.com/' | |
end | |
Pact::ProxyVerificationTask.new :otherapi_service do | task | | |
task.pact_url './spec/pacts/otherapi_service_consumer-otherapi_service_provider.json' | |
task.provider_base_url 'https://otherapi.com' | |
end | |
desc('Run the provider integration tests, in the specified order, ') | |
task(:provider_verify_ordered) do | |
interactions_to_verify= [['registration success','user'],['get_offer','other'],['issue offer','offer'],['payment','user'],['get extra offers','other']] | |
error = false | |
interactions_to_verify.each do |interaction, s| | |
begin | |
service = (s == 'user' ? 'userapi_service' : 'otherapi_service') | |
puts "Checking interaction #{interaction} on #{service}" | |
ENV['PACT_DESCRIPTION'] = interaction | |
Rake::Task["pact:verify:#{service}"].execute | |
rescue StandardError => e | |
error = true | |
puts e.inspect | |
puts "Checking interaction #{interaction} failed\n\n" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few pointers: Catching Exception in Ruby can cause problems, it's better to catch StandardError, because catching Exception will stop you being able to send signals to the script like Ctl+C to stop it. See this post here for more information: http://daniel.fone.net.nz/blog/2013/05/28/why-you-should-never-rescue-exception-in-ruby/
Also, the script you had would not return an error code if it failed, because it was catching the SystemExit exception when one of the tasks failed. One way to fix this, if you actually wanted to continue would be to have an error flag that got set to true, and then
fail if error
at the end of the script. But having changed the script to not rescue Exception, this will now stop if one of the tasks fails - I assume there is no point continuing with a later step if the first step has failed.