From bb93b0dfd8188c2a6b3bb18c4c571abc43e2b02b Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 21 Aug 2018 17:02:24 +1000 Subject: [PATCH] fix: ensure specified value of --pact-specification-version is written in pact file Fixes: https://github.com/pact-foundation/pact-mock_service/issues/93 --- lib/pact/mock_service/run.rb | 2 +- spec/integration/cli_spec.rb | 14 +++++++++++++- spec/support/integration_spec_support.rb | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/pact/mock_service/run.rb b/lib/pact/mock_service/run.rb index 6237d4f..1dd9bb5 100644 --- a/lib/pact/mock_service/run.rb +++ b/lib/pact/mock_service/run.rb @@ -59,7 +59,7 @@ def service_options consumer: options[:consumer], provider: options[:provider], cors_enabled: options[:cors], - pact_specification_version: Pact::SpecificationVersion::NIL_VERSION.to_s, + pact_specification_version: options[:pact_specification_version] || Pact::SpecificationVersion::NIL_VERSION.to_s, pactfile_write_mode: options[:pact_file_write_mode], stub_pactfile_paths: options[:stub_pactfile_paths] } diff --git a/spec/integration/cli_spec.rb b/spec/integration/cli_spec.rb index 9d470c3..5bde4fb 100644 --- a/spec/integration/cli_spec.rb +++ b/spec/integration/cli_spec.rb @@ -7,7 +7,7 @@ before :all do clear_dirs - @pid = start_server 1234 + @pid = start_server 1234, "--pact-specification-version 3.0.0" end it "starts up and responds with mocked responses" do @@ -40,9 +40,21 @@ end it "writes the pact to the specified directory" do + clear_interactions 1234 + setup_interaction 1234 + invoke_expected_request 1234 expect(File.exist?('tmp/pacts/consumer-provider.json')).to be true end + it "sets the pact specification version" do + clear_interactions 1234 + setup_interaction 1234 + invoke_expected_request 1234 + + write_pact 1234 + expect(File.read("tmp/pacts/consumer-provider.json")).to include "3.0.0" + end + after :all do kill_server @pid end diff --git a/spec/support/integration_spec_support.rb b/spec/support/integration_spec_support.rb index 23a0c89..64ae089 100644 --- a/spec/support/integration_spec_support.rb +++ b/spec/support/integration_spec_support.rb @@ -116,6 +116,10 @@ def setup_interaction port, interaction = expected_interaction mock_service_headers end + def clear_interactions port + Faraday.delete "http://localhost:#{port}/interactions" + end + def setup_another_interaction port Faraday.post "http://localhost:#{port}/interactions", another_expected_interaction,