Skip to content

Commit efdba96

Browse files
committed
fix: require pact_specification_version when spawning mock service through app manager
1 parent 165419b commit efdba96

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/pact/mock_service/app_manager.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def register_mock_service_for(name, url, options = {})
3030
name: name,
3131
log_file: create_log_file(name),
3232
pact_dir: pact_dir,
33-
pact_specification_version: options[:pact_specification_version]
33+
pact_specification_version: options.fetch(:pact_specification_version)
3434
)
3535
register(app, uri.port)
3636
end

spec/lib/pact/mock_service/app_manager_spec.rb

+12-7
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ module Pact::MockService
1212
end
1313

1414
let(:name) { 'some_service'}
15+
let(:options) { { pact_specification_version: '3' } }
1516

1617
context "for http://localhost" do
1718
let(:url) { 'http://localhost:1234'}
1819

1920
it "starts a mock service at the given port on localhost" do
2021
expect_any_instance_of(AppRegistration).to receive(:spawn)
21-
AppManager.instance.register_mock_service_for name, url
22+
AppManager.instance.register_mock_service_for name, url, options
2223
AppManager.instance.spawn_all
2324
end
2425

2526
it "registers the mock service as running on the given port" do
26-
AppManager.instance.register_mock_service_for name, url
27+
AppManager.instance.register_mock_service_for name, url, options
2728
expect(AppManager.instance.app_registered_on?(1234)).to eq true
2829
end
2930

@@ -32,37 +33,41 @@ module Pact::MockService
3233
expect(Pact::MockService).to receive(:new) do | options |
3334
expect(options[:pact_dir]).to eq 'pact_dir'
3435
end
35-
AppManager.instance.register_mock_service_for name, url
36+
AppManager.instance.register_mock_service_for name, url, options
3637
end
3738

3839
it "passes in the pact_specification_verson to the MockService" do
3940
expect(Pact::MockService).to receive(:new).with(hash_including(pact_specification_version: '3')).and_call_original
40-
AppManager.instance.register_mock_service_for name, url, pact_specification_version: '3'
41+
AppManager.instance.register_mock_service_for name, url, options
4142
end
4243
end
4344

4445
context "for https://" do
4546
let(:url) { 'https://localhost:1234'}
4647

4748
it "should throw an unsupported error" do
48-
expect { AppManager.instance.register_mock_service_for name, url }.to raise_error "Currently only http is supported"
49+
expect { AppManager.instance.register_mock_service_for name, url, options }.to raise_error "Currently only http is supported"
4950
end
5051
end
5152

5253
context "for a host other than localhost" do
5354
let(:url) { 'http://aserver:1234'}
5455

5556
it "should throw an unsupported error" do
56-
expect { AppManager.instance.register_mock_service_for name, url }.to raise_error "Currently only services on localhost are supported"
57+
expect { AppManager.instance.register_mock_service_for name, url, options }.to raise_error "Currently only services on localhost are supported"
5758
end
5859
end
5960

6061
describe "find_a_port option" do
6162
let(:url) { 'http://localhost' }
6263

64+
before do
65+
options[:find_available_port] = true
66+
end
67+
6368
it "builds AppRegistration with `nil` port" do
6469
expect(AppRegistration).to receive(:new).with(hash_including(port: nil)).and_call_original
65-
AppManager.instance.register_mock_service_for name, url, find_available_port: true
70+
AppManager.instance.register_mock_service_for name, url, options
6671
end
6772
end
6873
end

0 commit comments

Comments
 (0)