@@ -23,7 +23,6 @@ def initialize
23
23
def register_mock_service_for ( name , url , options = { } )
24
24
uri = URI ( url )
25
25
raise "Currently only http is supported" unless uri . scheme == 'http'
26
- raise "Currently only services on localhost are supported" unless uri . host == 'localhost'
27
26
uri . port = nil if options [ :find_available_port ]
28
27
29
28
app = Pact ::MockService . new (
@@ -32,21 +31,21 @@ def register_mock_service_for(name, url, options = {})
32
31
pact_dir : pact_dir ,
33
32
pact_specification_version : options . fetch ( :pact_specification_version )
34
33
)
35
- register ( app , uri . port )
34
+ register ( app , uri . host , uri . port )
36
35
end
37
36
38
- def register ( app , port = nil )
37
+ def register ( app , host , port = nil )
39
38
if port
40
- existing = existing_app_on_port ( port )
39
+ existing = existing_app_on_host_and_port ( host , port )
41
40
raise "Port #{ port } is already being used by #{ existing } " if existing and not existing == app
42
41
end
43
- app_registration = register_app ( app , port )
42
+ app_registration = register_app ( app , host , port )
44
43
app_registration . spawn
45
44
app_registration . port
46
45
end
47
46
48
- def ports_of_mock_services
49
- app_registrations . find_all ( &:is_a_mock_service? ) . collect ( & : port)
47
+ def urls_of_mock_services
48
+ app_registrations . find_all ( &:is_a_mock_service? ) . collect { | ar | "http:// #{ ar . host } : #{ ar . port } " }
50
49
end
51
50
52
51
def kill_all
@@ -70,13 +69,13 @@ def app_registered_on?(port)
70
69
71
70
private
72
71
73
- def existing_app_on_port ( port )
74
- app_registration = registration_on_port ( port )
72
+ def existing_app_on_host_and_port ( host , port )
73
+ app_registration = registration_on_host_and_port ( host , port )
75
74
app_registration ? app_registration . app : nil
76
75
end
77
76
78
- def registration_on_port ( port )
79
- @app_registrations . find { |app_registration | app_registration . port == port }
77
+ def registration_on_host_and_port ( host , port )
78
+ @app_registrations . find { |app_registration | app_registration . port == port && app_registration . host == host }
80
79
end
81
80
82
81
def pact_dir
@@ -107,20 +106,21 @@ def app_registrations
107
106
@app_registrations
108
107
end
109
108
110
- def register_app ( app , port )
111
- app_registration = AppRegistration . new ( app : app , port : port )
109
+ def register_app ( app , host , port )
110
+ app_registration = AppRegistration . new ( app : app , host : host , port : port )
112
111
app_registrations << app_registration
113
112
app_registration
114
113
end
115
114
end
116
115
117
116
class AppRegistration
118
117
include Pact ::Logging
119
- attr_accessor :port , :app
118
+ attr_accessor :host , : port, :app
120
119
121
120
def initialize ( opts )
122
121
@max_wait = 10
123
122
@port = opts [ :port ]
123
+ @host = opts [ :host ]
124
124
@app = opts [ :app ]
125
125
@spawned = false
126
126
end
@@ -148,7 +148,7 @@ def to_s
148
148
149
149
def spawn
150
150
logger . info "Starting app #{ self } ..."
151
- @server = Pact ::Server . new ( app , port ) . boot
151
+ @server = Pact ::Server . new ( app , host , port ) . boot
152
152
@port = @server . port
153
153
@spawned = true
154
154
logger . info "Started on port #{ port } "
0 commit comments