@@ -32,22 +32,23 @@ module Selenium
32
32
end
33
33
34
34
it 'uses the given jar file and port' do
35
- expect ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
36
-
37
- expect ( ChildProcess ) . to receive ( :build )
35
+ allow ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
36
+ allow ( ChildProcess ) . to receive ( :build )
38
37
. with ( 'java' , '-jar' , 'selenium_server_deploy.jar' , 'standalone' , '--port' , '1234' )
39
38
. and_return ( mock_process )
40
39
41
40
server = Selenium ::Server . new ( 'selenium_server_deploy.jar' , port : 1234 , background : true )
42
41
allow ( server ) . to receive ( :socket ) . and_return ( mock_poller )
43
42
44
43
server . start
44
+ expect ( File ) . to have_received ( :exist? ) . with ( 'selenium_server_deploy.jar' )
45
+ expect ( ChildProcess ) . to have_received ( :build )
46
+ . with ( 'java' , '-jar' , 'selenium_server_deploy.jar' , 'standalone' , '--port' , '1234' )
45
47
end
46
48
47
49
it 'waits for the server process by default' do
48
- expect ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
49
-
50
- expect ( ChildProcess ) . to receive ( :build )
50
+ allow ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
51
+ allow ( ChildProcess ) . to receive ( :build )
51
52
. with ( 'java' , '-jar' , 'selenium_server_deploy.jar' , 'standalone' , '--port' , '4444' )
52
53
. and_return ( mock_process )
53
54
@@ -56,12 +57,14 @@ module Selenium
56
57
57
58
expect ( mock_process ) . to receive ( :wait )
58
59
server . start
60
+ expect ( File ) . to have_received ( :exist? ) . with ( 'selenium_server_deploy.jar' )
61
+ expect ( ChildProcess ) . to have_received ( :build )
62
+ . with ( 'java' , '-jar' , 'selenium_server_deploy.jar' , 'standalone' , '--port' , '4444' )
59
63
end
60
64
61
65
it 'adds additional args' do
62
- expect ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
63
-
64
- expect ( ChildProcess ) . to receive ( :build )
66
+ allow ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
67
+ allow ( ChildProcess ) . to receive ( :build )
65
68
. with ( 'java' , '-jar' , 'selenium_server_deploy.jar' , 'standalone' , '--port' , '4444' , 'foo' , 'bar' )
66
69
. and_return ( mock_process )
67
70
@@ -71,12 +74,15 @@ module Selenium
71
74
server << %w[ foo bar ]
72
75
73
76
server . start
77
+ expect ( File ) . to have_received ( :exist? ) . with ( 'selenium_server_deploy.jar' )
78
+ expect ( ChildProcess ) . to have_received ( :build )
79
+ . with ( 'java' , '-jar' , 'selenium_server_deploy.jar' , 'standalone' ,
80
+ '--port' , '4444' , 'foo' , 'bar' )
74
81
end
75
82
76
83
it 'adds additional JAVA options args' do
77
- expect ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
78
-
79
- expect ( ChildProcess ) . to receive ( :build )
84
+ allow ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
85
+ allow ( ChildProcess ) . to receive ( :build )
80
86
. with ( 'java' ,
81
87
'-Dwebdriver.chrome.driver=/bin/chromedriver' ,
82
88
'-jar' , 'selenium_server_deploy.jar' ,
@@ -93,6 +99,15 @@ module Selenium
93
99
server << '-Dwebdriver.chrome.driver=/bin/chromedriver'
94
100
95
101
server . start
102
+ expect ( File ) . to have_received ( :exist? ) . with ( 'selenium_server_deploy.jar' )
103
+ expect ( ChildProcess ) . to have_received ( :build )
104
+ . with ( 'java' ,
105
+ '-Dwebdriver.chrome.driver=/bin/chromedriver' ,
106
+ '-jar' , 'selenium_server_deploy.jar' ,
107
+ 'standalone' ,
108
+ '--port' , '4444' ,
109
+ 'foo' ,
110
+ 'bar' )
96
111
end
97
112
98
113
it 'downloads the specified version from the selenium site' do
@@ -117,10 +132,13 @@ module Selenium
117
132
expected_options = { port : 5555 }
118
133
fake_server = Object . new
119
134
120
- expect ( Selenium ::Server ) . to receive ( :download ) . with ( required_version ) . and_return ( expected_download_file_name )
121
- expect ( Selenium ::Server ) . to receive ( :new ) . with ( expected_download_file_name , expected_options ) . and_return ( fake_server )
135
+ allow ( Selenium ::Server ) . to receive ( :download ) . with ( required_version ) . and_return ( expected_download_file_name )
136
+ allow ( Selenium ::Server ) . to receive ( :new ) . with ( expected_download_file_name , expected_options ) . and_return ( fake_server )
137
+
122
138
server = Selenium ::Server . get required_version , expected_options
123
139
expect ( server ) . to eq ( fake_server )
140
+ expect ( Selenium ::Server ) . to have_received ( :download ) . with ( required_version )
141
+ expect ( Selenium ::Server ) . to have_received ( :new ) . with ( expected_download_file_name , expected_options )
124
142
end
125
143
126
144
it 'automatically repairs http_proxy settings that do not start with http://' do
@@ -137,9 +155,10 @@ module Selenium
137
155
required_version = '10.2.0'
138
156
expected_download_file_name = "selenium-server-standalone-#{ required_version } .jar"
139
157
140
- expect ( File ) . to receive ( :exist? ) . with ( expected_download_file_name ) . and_return true
158
+ allow ( File ) . to receive ( :exist? ) . with ( expected_download_file_name ) . and_return true
141
159
142
160
Selenium ::Server . download required_version
161
+ expect ( File ) . to have_received ( :exist? ) . with ( expected_download_file_name )
143
162
end
144
163
145
164
it 'should know what the latest version available is' do
@@ -160,33 +179,35 @@ module Selenium
160
179
minor_version = '2.42'
161
180
expected_download_file_name = "selenium-server-standalone-#{ required_version } .jar"
162
181
163
- expect ( Selenium ::Server ) . to receive ( :latest ) . and_return required_version
182
+ allow ( Selenium ::Server ) . to receive ( :latest ) . and_return required_version
164
183
stub_request ( :get , "http://selenium-release.storage.googleapis.com/#{ minor_version } /#{ expected_download_file_name } " )
165
184
. to_return ( body : 'this is pretending to be a jar file for testing purposes' )
166
185
167
186
begin
168
187
actual_download_file_name = Selenium ::Server . download ( :latest )
169
188
expect ( actual_download_file_name ) . to eq ( expected_download_file_name )
170
189
expect ( File ) . to exist ( expected_download_file_name )
190
+ expect ( Selenium ::Server ) . to have_received ( :latest )
171
191
ensure
172
192
FileUtils . rm_rf expected_download_file_name
173
193
end
174
194
end
175
195
176
196
it 'raises Selenium::Server::Error if the server is not launched within the timeout' do
177
- expect ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
197
+ allow ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
178
198
179
199
poller = instance_double ( 'SocketPoller' )
180
- expect ( poller ) . to receive ( :connected? ) . and_return ( false )
200
+ allow ( poller ) . to receive ( :connected? ) . and_return ( false )
181
201
182
202
server = Selenium ::Server . new ( 'selenium_server_deploy.jar' , background : true )
183
203
allow ( server ) . to receive ( :socket ) . and_return ( poller )
184
204
185
205
expect { server . start } . to raise_error ( Selenium ::Server ::Error )
206
+ expect ( File ) . to have_received ( :exist? ) . with ( 'selenium_server_deploy.jar' )
186
207
end
187
208
188
209
it 'sets options after instantiation' do
189
- expect ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
210
+ allow ( File ) . to receive ( :exist? ) . with ( 'selenium_server_deploy.jar' ) . and_return ( true )
190
211
server = Selenium ::Server . new ( 'selenium_server_deploy.jar' )
191
212
expect ( server . port ) . to eq ( 4444 )
192
213
expect ( server . timeout ) . to eq ( 30 )
@@ -204,6 +225,7 @@ module Selenium
204
225
expect ( server . background ) . to be_truthy
205
226
expect ( server . log ) . to eq ( '/tmp/server.log' )
206
227
end
228
+ expect ( File ) . to have_received ( :exist? ) . with ( 'selenium_server_deploy.jar' )
207
229
end
208
230
end
209
231
end # Selenium
0 commit comments