@@ -11,13 +11,14 @@ class MockService
1111
1212 extend Pact ::DSL
1313
14- attr_accessor :port , :standalone , :verify , :provider_name , :consumer_name , :pact_specification_version
14+ attr_accessor :port , :host , : standalone, :verify , :provider_name , :consumer_name , :pact_specification_version
1515
1616 def initialize name , consumer_name , provider_name
1717 @name = name
1818 @consumer_name = consumer_name
1919 @provider_name = provider_name
2020 @port = nil
21+ @host = "localhost"
2122 @standalone = false
2223 @verify = true
2324 @pact_specification_version = '2'
@@ -29,6 +30,10 @@ def port port
2930 self . port = port
3031 end
3132
33+ def host host
34+ self . host = host
35+ end
36+
3237 def standalone standalone
3338 self . standalone = standalone
3439 end
@@ -53,7 +58,7 @@ def finalize
5358
5459 def register_mock_service
5560 unless standalone
56- url = "http://localhost #{ port . nil? ? '' : ":#{ port } " } "
61+ url = "http://#{ host } #{ port . nil? ? '' : ":#{ port } " } "
5762 ret = Pact ::MockService ::AppManager . instance . register_mock_service_for ( provider_name , url , mock_service_options )
5863 raise "pact-mock_service(v#{ Pact ::MockService ::VERSION } ) does not support 'find available port' feature" unless ret
5964 @port = ret
@@ -73,6 +78,7 @@ def create_consumer_contract_builder
7378 :provider_name => provider_name ,
7479 :pactfile_write_mode => Pact . configuration . pactfile_write_mode ,
7580 :port => port ,
81+ :host => host ,
7682 :pact_dir => Pact . configuration . pact_dir
7783 }
7884 Pact ::Consumer ::ConsumerContractBuilder . new consumer_contract_builder_fields
0 commit comments