Skip to content

Commit

Permalink
Refactored to not use the Pact rake tasks. Traveling Ruby does not li…
Browse files Browse the repository at this point in the history
…ke shelling out to a Ruby process (where's my Gems?)
  • Loading branch information
mefellows committed May 12, 2016
1 parent 85b215f commit 0aca507
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/me-they.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"headers": {
},
"body": {
"greeting": "Hello"
"greeting": "Oh yes!"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion examples/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ sleep 2

puts "=> Running Pact"
res = `ruby -I../lib ../bin/pact-provider-verifier --provider-base-url http://localhost:4567 --pact-urls ./me-they.json --provider_states_setup_url http://localhost:4567/provider-state --provider_states_url http://localhost:4567/provider-states`

# Test the actual gem
# res = `../pkg/pact-provider-verifier-0.0.2-1-osx/bin/pact-provider-verifier --provider-base-url http://localhost:4567 --pact-urls ./me-they.json --provider_states_setup_url http://localhost:4567/provider-state --provider_states_url http://localhost:4567/provider-states`
code = $?

puts "=> Shutting down API"
Process.kill 'TERM', pipe.pid

puts "#{res}"
exit code.to_i
exit code.exitstatus
33 changes: 25 additions & 8 deletions lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,33 @@ def verify_pacts
proxy_pact_helper = File.expand_path(File.join(File.dirname(__FILE__), "pact_helper.rb"))
ENV['provider_states_url'] = @options.provider_states_url
ENV['provider_states_setup_url'] = @options.provider_states_setup_url
provider_base_url = @options.provider_base_url

pacts.each do |pact_url|
Pact::ProxyVerificationTask.new :"#{pact_url}" do | task |
ENV['pact_consumer'] = get_pact_consumer_name(pact_url)
task.pact_url pact_url, :pact_helper => proxy_pact_helper
task.provider_base_url @options.provider_base_url
require 'pact/provider/rspec'
require 'rack/reverse_proxy'

Pact.service_provider "Running Provider Application" do
app do
Rack::ReverseProxy.new do
reverse_proxy '/', provider_base_url
end
task_name = "pact:verify:#{pact_url}"
Rake::Task[task_name].invoke
Rake::Task[task_name].reenable
end
end

require ENV['PACT_PROJECT_PACT_HELPER'] if ENV.fetch('PACT_PROJECT_PACT_HELPER','') != ''

exit_statuses = pacts.collect do |pact_url|
options = {
:pact_helper => proxy_pact_helper,
:pact_uri => pact_url,
:backtrace => false
}
require 'pact/cli/run_pact_verification'
Cli::RunPactVerification.call(options)
end

Pact::Provider::Proxy::TaskHelper.handle_verification_failure do
exit_statuses.count{ | status | status != 0 }
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/pact/provider_verifier/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CLI < Thor

def verify
app = Pact::ProviderVerifier::App.new(options)
app.verify_pacts
end

default_task :verify
Expand Down
2 changes: 1 addition & 1 deletion packaging/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export BUNDLE_GEMFILE="$LIBDIR/vendor/Gemfile"
unset BUNDLE_IGNORE_CONFIG

# Run the actual app using the bundled Ruby interpreter, with Bundler activated.
exec "$LIBDIR/ruby/bin/ruby" -rbundler/setup -I$LIBDIR/app/lib "$LIBDIR/app/pact-provider-verifier.rb" $@
exec "$LIBDIR/ruby/bin/ruby" -rbundler/setup -rreadline -I$LIBDIR/app/lib "$LIBDIR/app/pact-provider-verifier.rb" $@

0 comments on commit 0aca507

Please sign in to comment.