Skip to content

Commit

Permalink
feat(monkeypatch): allow a ruby file to be loaded in order to perform…
Browse files Browse the repository at this point in the history
… at monkeypatch
  • Loading branch information
bethesque committed Nov 6, 2017
1 parent c617321 commit 96bb549
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def set_environment_variables
ENV['PROVIDER_STATES_SETUP_URL'] = options.provider_states_setup_url
ENV['VERBOSE_LOGGING'] = options.verbose if options.verbose
ENV['CUSTOM_PROVIDER_HEADER'] = custom_provider_headers_for_env_var if custom_provider_headers_for_env_var
ENV['MONKEYPATCH'] = options.monkeypatch.join("\n") if options.monkeypatch && options.monkeypatch.any?
end

def configure_service_provider
Expand Down
1 change: 1 addition & 0 deletions lib/pact/provider_verifier/cli/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Verify < CustomThor
method_option :broker_username, aliases: "-n", desc: "Pact Broker basic auth username", :required => false
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password", :required => false
method_option :custom_provider_header, type: :array, banner: 'CUSTOM_PROVIDER_HEADER', desc: "Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.", :required => false
method_option :monkeypatch, hide: true, type: :array, :required => false
method_option :verbose, aliases: "-v", desc: "Verbose output", :required => false
method_option :provider_states_url, aliases: "-s", :required => false, hide: true
method_option :format, banner: "FORMATTER", aliases: "-f", desc: "RSpec formatter. Defaults to custom Pact formatter. [j]son may also be used."
Expand Down
11 changes: 11 additions & 0 deletions lib/pact/provider_verifier/pact_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@
config.provider_state_set_up = Pact::ProviderVerifier::SetUpProviderState
config.provider_state_tear_down = -> (*args){ }
end

if ENV['MONKEYPATCH']
ENV['MONKEYPATCH'].split("\n").each do | file |
$stdout.puts "DEBUG: Requiring monkeypatch file #{file}" if ENV['VERBOSE_LOGGING']
begin
require file
rescue LoadError => e
$stderr.puts "ERROR: #{e.class} - #{e.message}. Ensure you have specified the absolute path."
end
end
end
24 changes: 24 additions & 0 deletions spec/integration_with_monkeypatch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe "pact-provider-verifier with monkeypatch" do
before(:all) do
@pipe = IO.popen({}, %w{bundle exec rackup -p 4870 spec/support/config.ru})
sleep 2
end

subject { `bundle exec bin/pact-provider-verifier ./test/me-they.json --monkeypatch #{Dir.pwd}/spec/support/monkeypatch.rb --monkeypatch #{Dir.pwd}/spec/support/another_monkeypatch.rb -a 1.0.100 --provider-base-url http://localhost:4870 --provider_states_setup_url http://localhost:4870/provider-state 2>&1` }

it "exits with a 0 exit code" do
subject
puts subject
expect($?).to eq 0
end

it "loads the monkeypatch file" do
expect(subject).to include "THIS IS A MONKEYPATCHING FILE!!!"
expect(subject).to include "THIS IS ANOTHER MONKEYPATCHING FILE!!!"
end


after(:all) do
Process.kill 'KILL', @pipe.pid
end
end
1 change: 1 addition & 0 deletions spec/support/another_monkeypatch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "THIS IS ANOTHER MONKEYPATCHING FILE!!!"
1 change: 1 addition & 0 deletions spec/support/monkeypatch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "THIS IS A MONKEYPATCHING FILE!!!"

0 comments on commit 96bb549

Please sign in to comment.