webdrivers 4.0.1 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,273 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Webdrivers::Edgedriver do
6
+ let(:edgedriver) { described_class }
7
+
8
+ before do
9
+ edgedriver.remove
10
+ end
11
+
12
+ describe '#update' do
13
+ context 'when evaluating #correct_binary?' do
14
+ it 'does not download when latest version and current version match' do
15
+ allow(edgedriver).to receive(:latest_version).and_return(Gem::Version.new('72.0.0'))
16
+ allow(edgedriver).to receive(:current_version).and_return(Gem::Version.new('72.0.0'))
17
+
18
+ edgedriver.update
19
+
20
+ expect(edgedriver.send(:exists?)).to be false
21
+ end
22
+
23
+ it 'does not download when offline, binary exists and is less than v70' do
24
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
25
+ allow(edgedriver).to receive(:exists?).and_return(true)
26
+ allow(edgedriver).to receive(:current_version).and_return(Gem::Version.new(69))
27
+
28
+ edgedriver.update
29
+
30
+ expect(File.exist?(edgedriver.driver_path)).to be false
31
+ end
32
+
33
+ it 'does not download when offline, binary exists and matches major browser version' do
34
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
35
+ allow(edgedriver).to receive(:exists?).and_return(true)
36
+ allow(edgedriver).to receive(:browser_version).and_return(Gem::Version.new('73.0.3683.68'))
37
+ allow(edgedriver).to receive(:current_version).and_return(Gem::Version.new('73.0.3683.20'))
38
+
39
+ edgedriver.update
40
+
41
+ expect(File.exist?(edgedriver.driver_path)).to be false
42
+ end
43
+
44
+ it 'does not download when get raises exception, binary exists and matches major browser version' do
45
+ client_error = instance_double(Net::HTTPNotFound, class: Net::HTTPNotFound, code: 404, message: '')
46
+
47
+ allow(Webdrivers::Network).to receive(:get_response).and_return(client_error)
48
+ allow(edgedriver).to receive(:exists?).and_return(true)
49
+ allow(edgedriver).to receive(:browser_version).and_return(Gem::Version.new('73.0.3683.68'))
50
+ allow(edgedriver).to receive(:current_version).and_return(Gem::Version.new('73.0.3683.20'))
51
+
52
+ edgedriver.update
53
+
54
+ expect(File.exist?(edgedriver.driver_path)).to be false
55
+ end
56
+
57
+ it 'raises ConnectionError when offline, and binary does not match major browser version' do
58
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
59
+ allow(edgedriver).to receive(:exists?).and_return(true)
60
+ allow(edgedriver).to receive(:browser_version).and_return(Gem::Version.new('73.0.3683.68'))
61
+ allow(edgedriver).to receive(:current_version).and_return(Gem::Version.new('72.0.0.0'))
62
+
63
+ msg = %r{Can not reach https://msedgedriver.azureedge.net/}
64
+ expect { edgedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
65
+ end
66
+
67
+ it 'raises ConnectionError when offline, and no binary exists' do
68
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
69
+ allow(edgedriver).to receive(:exists?).and_return(false)
70
+
71
+ msg = %r{Can not reach https://msedgedriver.azureedge.net/}
72
+ expect { edgedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
73
+ end
74
+ end
75
+
76
+ context 'when correct binary is found' do
77
+ before { allow(edgedriver).to receive(:correct_binary?).and_return(true) }
78
+
79
+ it 'does not download' do
80
+ edgedriver.update
81
+
82
+ expect(edgedriver.current_version).to be_nil
83
+ end
84
+
85
+ it 'does not raise exception if offline' do
86
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
87
+
88
+ edgedriver.update
89
+
90
+ expect(edgedriver.current_version).to be_nil
91
+ end
92
+ end
93
+
94
+ context 'when correct binary is not found' do
95
+ before { allow(edgedriver).to receive(:correct_binary?).and_return(false) }
96
+
97
+ it 'downloads binary' do
98
+ edgedriver.update
99
+
100
+ expect(edgedriver.current_version).not_to be_nil
101
+ end
102
+
103
+ it 'raises ConnectionError if offline' do
104
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
105
+
106
+ msg = %r{Can not reach https://msedgedriver.azureedge.net/}
107
+ expect { edgedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
108
+ end
109
+ end
110
+
111
+ it 'makes network calls if cached driver does not match the browser' do
112
+ Webdrivers::System.cache_version('msedgedriver', '71.0.3578.137')
113
+ allow(edgedriver).to receive(:current_version).and_return Gem::Version.new('71.0.3578.137')
114
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('73.0.3683.68')
115
+ allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68'.encode('UTF-16'))
116
+ allow(Webdrivers::System).to receive(:download)
117
+
118
+ edgedriver.update
119
+
120
+ expect(Webdrivers::Network).to have_received(:get).twice
121
+ end
122
+
123
+ context 'when required version is 0' do
124
+ it 'downloads the latest version' do
125
+ allow(edgedriver).to receive(:latest_version).and_return(Gem::Version.new('98.0.1089.1'))
126
+ edgedriver.required_version = 0
127
+ edgedriver.update
128
+ expect(edgedriver.current_version.version).to eq('98.0.1089.1')
129
+ end
130
+ end
131
+
132
+ context 'when required version is nil' do
133
+ it 'downloads the latest version' do
134
+ allow(edgedriver).to receive(:latest_version).and_return(Gem::Version.new('98.0.1089.1'))
135
+ edgedriver.required_version = nil
136
+ edgedriver.update
137
+ expect(edgedriver.current_version.version).to eq('98.0.1089.1')
138
+ end
139
+ end
140
+ end
141
+
142
+ describe '#current_version' do
143
+ it 'returns nil if binary does not exist on the system' do
144
+ allow(edgedriver).to receive(:driver_path).and_return('')
145
+
146
+ expect(edgedriver.current_version).to be_nil
147
+ end
148
+
149
+ it 'returns a Gem::Version instance if binary is on the system' do
150
+ allow(edgedriver).to receive(:exists?).and_return(true)
151
+ allow(Webdrivers::System).to receive(:call)
152
+ .with(edgedriver.driver_path, '--version')
153
+ .and_return '71.0.3578.137'
154
+
155
+ expect(edgedriver.current_version).to eq Gem::Version.new('71.0.3578.137')
156
+ end
157
+ end
158
+
159
+ describe '#latest_version' do
160
+ it 'returns the correct point release for a production version' do
161
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')
162
+
163
+ expect(edgedriver.latest_version).to be_between(Gem::Version.new('77.0.207.0'), Gem::Version.new('78'))
164
+ end
165
+
166
+ it 'raises VersionError for beta version' do
167
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('999.0.0')
168
+ msg = 'Unable to find latest point release version for 999.0.0. '\
169
+ 'You appear to be using a non-production version of Edge. '\
170
+ 'Please set `Webdrivers::Edgedriver.required_version = <desired driver version>` '\
171
+ 'to a known edgedriver version: Can not reach https://msedgedriver.azureedge.net'
172
+
173
+ expect { edgedriver.latest_version }.to raise_exception(Webdrivers::VersionError, msg)
174
+ end
175
+
176
+ it 'raises VersionError for unknown version' do
177
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.9999')
178
+ msg = 'Unable to find latest point release version for 77.0.9999. '\
179
+ 'Please set `Webdrivers::Edgedriver.required_version = <desired driver version>` '\
180
+ 'to a known edgedriver version: Can not reach https://msedgedriver.azureedge.net'
181
+
182
+ expect { edgedriver.latest_version }.to raise_exception(Webdrivers::VersionError, msg)
183
+ end
184
+
185
+ it 'raises ConnectionError when offline' do
186
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
187
+
188
+ msg = %r{^Can not reach https://msedgedriver.azureedge.net}
189
+ expect { edgedriver.latest_version }.to raise_error(Webdrivers::ConnectionError, msg)
190
+ end
191
+
192
+ it 'creates cached file' do
193
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')
194
+ allow(Webdrivers::Network).to receive(:get).and_return('77.0.207.0'.encode('UTF-16'))
195
+
196
+ edgedriver.latest_version
197
+ expect(File.exist?("#{Webdrivers::System.install_dir}/msedgedriver.version")).to eq true
198
+ end
199
+
200
+ it 'does not make network calls if cache is valid and driver exists' do
201
+ allow(Webdrivers).to receive(:cache_time).and_return(3600)
202
+ Webdrivers::System.cache_version('msedgedriver', '82.0.445.0')
203
+ allow(edgedriver).to receive(:current_version).and_return Gem::Version.new('82.0.445.0')
204
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('82.0.445.0')
205
+ allow(Webdrivers::System).to receive(:exists?).and_return(true)
206
+ allow(Webdrivers::Network).to receive(:get)
207
+
208
+ expect(edgedriver.latest_version).to eq Gem::Version.new('82.0.445.0')
209
+
210
+ expect(Webdrivers::Network).not_to have_received(:get)
211
+ end
212
+
213
+ it 'makes network calls if cache is expired' do
214
+ Webdrivers::System.cache_version('msedgedriver', '71.0.3578.137')
215
+ allow(Webdrivers::Network).to receive(:get).and_return('77.0.207.0'.encode('UTF-16'))
216
+ allow(Webdrivers::System).to receive(:valid_cache?).and_return(false)
217
+ allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')
218
+
219
+ expect(edgedriver.latest_version).to eq Gem::Version.new('77.0.207.0')
220
+
221
+ expect(Webdrivers::Network).to have_received(:get)
222
+ expect(Webdrivers::System).to have_received(:valid_cache?)
223
+ end
224
+ end
225
+
226
+ describe '#required_version=' do
227
+ after { edgedriver.required_version = nil }
228
+
229
+ it 'returns the version specified as a Float' do
230
+ edgedriver.required_version = 73.0
231
+
232
+ expect(edgedriver.required_version).to eq Gem::Version.new('73.0')
233
+ end
234
+
235
+ it 'returns the version specified as a String' do
236
+ edgedriver.required_version = '73.0'
237
+
238
+ expect(edgedriver.required_version).to eq Gem::Version.new('73.0')
239
+ end
240
+ end
241
+
242
+ describe '#remove' do
243
+ it 'removes existing edgedriver' do
244
+ edgedriver.update
245
+
246
+ edgedriver.remove
247
+ expect(edgedriver.current_version).to be_nil
248
+ end
249
+
250
+ it 'does not raise exception if no edgedriver found' do
251
+ expect { edgedriver.remove }.not_to raise_error
252
+ end
253
+ end
254
+
255
+ describe '#driver_path' do
256
+ it 'returns full location of binary' do
257
+ expected_bin = "msedgedriver#{'.exe' if Selenium::WebDriver::Platform.windows?}"
258
+ expected_path = File.absolute_path "#{File.join(ENV['HOME'])}/.webdrivers/#{expected_bin}"
259
+ expect(edgedriver.driver_path).to eq(expected_path)
260
+ end
261
+ end
262
+
263
+ describe '#browser_version' do
264
+ it 'returns a Gem::Version object' do
265
+ expect(edgedriver.browser_version).to be_an_instance_of(Gem::Version)
266
+ end
267
+
268
+ it 'returns currently installed Edge version' do
269
+ allow(Webdrivers::EdgeFinder).to receive(:version).and_return('72.0.0.0')
270
+ expect(edgedriver.browser_version).to be Gem::Version.new('72.0.0.0')
271
+ end
272
+ end
273
+ end
@@ -92,6 +92,40 @@ describe Webdrivers::Geckodriver do
92
92
  msg = /Net::HTTPServerException: 404 "Not Found"/
93
93
  expect { geckodriver.update }.to raise_error(StandardError, msg)
94
94
  end
95
+
96
+ context 'when platform is Apple Sillicon' do
97
+ it 'downloads aarch64 binary' do
98
+ allow(Webdrivers::System).to receive(:platform).and_return('mac')
99
+ allow(Webdrivers::System).to receive(:apple_m1_architecture?).and_return(true)
100
+ base = 'https://github.com/mozilla/geckodriver/releases/download'
101
+ binary = 'geckodriver-v0.31.0-macos-aarch64.tar.gz'
102
+ url = "#{base}/v0.31.0/#{binary}"
103
+
104
+ allow(Webdrivers::System).to receive(:download).with(url, geckodriver.driver_path)
105
+
106
+ geckodriver.required_version = '0.31.0'
107
+ geckodriver.update
108
+
109
+ expect(Webdrivers::System).to have_received(:download).with(url, geckodriver.driver_path)
110
+ end
111
+ end
112
+
113
+ context 'when platform isn\'t Apple Sillicon' do
114
+ it 'downloads default binary' do
115
+ allow(Webdrivers::System).to receive(:platform).and_return('mac')
116
+ allow(Webdrivers::System).to receive(:apple_m1_architecture?).and_return(false)
117
+ base = 'https://github.com/mozilla/geckodriver/releases/download'
118
+ binary = 'geckodriver-v0.31.0-macos.tar.gz'
119
+ url = "#{base}/v0.31.0/#{binary}"
120
+
121
+ allow(Webdrivers::System).to receive(:download).with(url, geckodriver.driver_path)
122
+
123
+ geckodriver.required_version = '0.31.0'
124
+ geckodriver.update
125
+
126
+ expect(Webdrivers::System).to have_received(:download).with(url, geckodriver.driver_path)
127
+ end
128
+ end
95
129
  end
96
130
 
97
131
  describe '#current_version' do
@@ -112,7 +146,7 @@ testing/geckodriver in https://hg.mozilla.org/mozilla-central.
112
146
  This program is subject to the terms of the Mozilla Public License 2.0.
113
147
  You can obtain a copy of the license at https://mozilla.org/MPL/2.0/"
114
148
 
115
- allow(Webdrivers::System).to receive(:call).with("#{geckodriver.driver_path} --version").and_return return_value
149
+ allow(Webdrivers::System).to receive(:call).with(geckodriver.driver_path, '--version').and_return return_value
116
150
 
117
151
  expect(geckodriver.current_version).to eq Gem::Version.new('0.24.0')
118
152
  end
@@ -135,9 +169,10 @@ You can obtain a copy of the license at https://mozilla.org/MPL/2.0/"
135
169
  expect(File.exist?("#{Webdrivers::System.install_dir}/geckodriver.version")).to eq true
136
170
  end
137
171
 
138
- it 'does not make network call if cache is valid' do
172
+ it 'does not make network calls if cache is valid and driver exists' do
139
173
  allow(Webdrivers).to receive(:cache_time).and_return(3600)
140
174
  Webdrivers::System.cache_version('geckodriver', '0.23.0')
175
+ allow(Webdrivers::System).to receive(:exists?).and_return(true)
141
176
  allow(Webdrivers::Network).to receive(:get)
142
177
 
143
178
  expect(geckodriver.latest_version).to eq Gem::Version.new('0.23.0')
@@ -191,21 +226,19 @@ You can obtain a copy of the license at https://mozilla.org/MPL/2.0/"
191
226
  end
192
227
 
193
228
  it 'uses provided value' do
194
- begin
195
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
196
- Webdrivers.install_dir = install_dir
229
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
230
+ Webdrivers.install_dir = install_dir
197
231
 
198
- expect(Webdrivers::System.install_dir).to eq install_dir
199
- ensure
200
- Webdrivers.install_dir = nil
201
- end
232
+ expect(Webdrivers::System.install_dir).to eq install_dir
233
+ ensure
234
+ Webdrivers.install_dir = nil
202
235
  end
203
236
  end
204
237
 
205
238
  describe '#driver_path' do
206
239
  it 'returns full location of binary' do
207
240
  expected_bin = "geckodriver#{'.exe' if Selenium::WebDriver::Platform.windows?}"
208
- expected_path = Webdrivers::System.escape_path("#{File.join(ENV['HOME'])}/.webdrivers/#{expected_bin}")
241
+ expected_path = File.absolute_path "#{File.join(ENV['HOME'])}/.webdrivers/#{expected_bin}"
209
242
  expect(geckodriver.driver_path).to eq(expected_path)
210
243
  end
211
244
  end
@@ -6,6 +6,10 @@ describe Webdrivers::IEdriver do
6
6
  let(:iedriver) { described_class }
7
7
 
8
8
  before do
9
+ if ENV['CI'] && !Selenium::WebDriver::Platform.windows?
10
+ skip('Only run IE tests on Windows on CI because rate limiting')
11
+ end
12
+
9
13
  iedriver.remove
10
14
  iedriver.required_version = nil
11
15
  end
@@ -69,7 +73,7 @@ describe Webdrivers::IEdriver do
69
73
  it 'raises ConnectionError if offline' do
70
74
  allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
71
75
 
72
- msg = %r{Can not reach https://selenium-release.storage.googleapis.com/}
76
+ msg = %r{Can not reach https://api.github.com/repos/seleniumhq/selenium/releases}
73
77
  expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
74
78
  end
75
79
  end
@@ -87,7 +91,7 @@ describe Webdrivers::IEdriver do
87
91
 
88
92
  return_value = 'something IEDriverServer.exe 3.5.1 something else'
89
93
 
90
- allow(Webdrivers::System).to receive(:call).with("#{iedriver.driver_path} --version").and_return return_value
94
+ allow(Webdrivers::System).to receive(:call).with(iedriver.driver_path, '--version').and_return return_value
91
95
 
92
96
  expect(iedriver.current_version).to eq Gem::Version.new('3.5.1')
93
97
  end
@@ -109,15 +113,17 @@ describe Webdrivers::IEdriver do
109
113
  end
110
114
 
111
115
  it 'creates cached file' do
112
- allow(Webdrivers::Network).to receive(:get).and_return('3.4.0')
116
+ json = '[{"assets": [{"name":"IEDriverServer_Win32_3.150.0.zip"}]}]'
117
+ allow(Webdrivers::Network).to receive(:get).and_return(json)
113
118
 
114
119
  iedriver.latest_version
115
120
  expect(File.exist?("#{Webdrivers::System.install_dir}/IEDriverServer.version")).to eq true
116
121
  end
117
122
 
118
- it 'does not make network call if cache is valid' do
123
+ it 'does not make network calls if cache is valid and driver exists' do
119
124
  allow(Webdrivers).to receive(:cache_time).and_return(3600)
120
125
  Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
126
+ allow(Webdrivers::System).to receive(:exists?).and_return(true)
121
127
  allow(Webdrivers::Network).to receive(:get)
122
128
 
123
129
  expect(iedriver.latest_version).to eq Gem::Version.new('3.4.0')
@@ -173,20 +179,18 @@ describe Webdrivers::IEdriver do
173
179
  end
174
180
 
175
181
  it 'uses provided value' do
176
- begin
177
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
178
- Webdrivers.install_dir = install_dir
182
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
183
+ Webdrivers.install_dir = install_dir
179
184
 
180
- expect(Webdrivers::System.install_dir).to eq install_dir
181
- ensure
182
- Webdrivers.install_dir = nil
183
- end
185
+ expect(Webdrivers::System.install_dir).to eq install_dir
186
+ ensure
187
+ Webdrivers.install_dir = nil
184
188
  end
185
189
  end
186
190
 
187
191
  describe '#driver_path' do
188
192
  it 'returns full location of binary' do
189
- expected_path = Webdrivers::System.escape_path("#{File.join(ENV['HOME'])}/.webdrivers/IEDriverServer.exe")
193
+ expected_path = File.absolute_path "#{File.join(ENV['HOME'])}/.webdrivers/IEDriverServer.exe"
190
194
  expect(iedriver.driver_path).to eq(expected_path)
191
195
  end
192
196
  end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Webdrivers::System do
6
+ describe '#wsl_v1?' do
7
+ subject { described_class.wsl_v1? }
8
+
9
+ before do
10
+ allow(described_class).to receive(:platform).and_return(platform)
11
+ allow(File).to receive(:open).with('/proc/version').and_return(StringIO.new(wsl_proc_version_contents))
12
+ end
13
+
14
+ let(:platform) { 'linux' }
15
+ let(:wsl_proc_version_contents) { '' }
16
+
17
+ context 'when the current platform is linux and WSL version is 1' do
18
+ let(:wsl_proc_version_contents) do
19
+ 'Linux version 4.4.0-18362-Microsoft'\
20
+ '(Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) )'\
21
+ '#836-Microsoft Mon May 05 16:04:00 PST 2020'
22
+ end
23
+
24
+ it { is_expected.to eq true }
25
+ end
26
+
27
+ context 'when the current platform is linux and WSL version is 2' do
28
+ let(:wsl_proc_version_contents) do
29
+ 'Linux version 4.19.84-microsoft-standard '\
30
+ '(oe-user@oe-host) (gcc version 8.2.0 (GCC)) '\
31
+ '#1 SMP Wed Nov 13 11:44:37 UTC 2019'
32
+ end
33
+
34
+ it { is_expected.to eq false }
35
+ end
36
+
37
+ context 'when the current platform is mac' do
38
+ let(:platform) { 'mac' }
39
+
40
+ it { is_expected.to eq false }
41
+ end
42
+ end
43
+
44
+ describe '#to_win32_path' do
45
+ before { allow(described_class).to receive(:call).and_return("C:\\path\\to\\folder\n") }
46
+
47
+ it 'uses wslpath' do
48
+ described_class.to_win32_path '/c/path/to/folder'
49
+
50
+ expect(described_class).to have_received(:call).with('wslpath -w \'/c/path/to/folder\'')
51
+ end
52
+
53
+ it 'removes the trailing newline' do
54
+ expect(described_class.to_win32_path('/c/path/to/folder')).not_to end_with('\n')
55
+ end
56
+
57
+ context 'when the path is already in Windows format' do
58
+ it 'returns early' do
59
+ expect(described_class.to_win32_path('D:\\')).to eq 'D:\\'
60
+
61
+ expect(described_class).not_to have_received(:call)
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#to_wsl_path' do
67
+ before { allow(described_class).to receive(:call).and_return("/c/path/to/folder\n") }
68
+
69
+ it 'uses wslpath' do
70
+ described_class.to_wsl_path 'C:\\path\\to\\folder'
71
+
72
+ expect(described_class).to have_received(:call).with('wslpath -u \'C:\\path\\to\\folder\'')
73
+ end
74
+
75
+ it 'removes the trailing newline' do
76
+ expect(described_class.to_wsl_path('/c/path/to/folder')).not_to end_with('\n')
77
+ end
78
+ end
79
+ end
@@ -29,15 +29,15 @@ describe Webdrivers do
29
29
  end
30
30
 
31
31
  context 'when ENV variable WD_CACHE_TIME is set' do
32
- before { described_class.cache_time = 86_400 }
32
+ before { described_class.cache_time = 3600 }
33
33
 
34
- it 'uses cache time value from ENV variable over the Webdrivers.cache_time value' do
35
- allow(ENV).to receive(:[]).with('WD_CACHE_TIME').and_return(999)
36
- expect(described_class.cache_time).to be(999)
34
+ it 'uses cache time value from Webdrivers.cache_time over the ENV variable value' do
35
+ allow(ENV).to receive(:[]).with('WD_CACHE_TIME').and_return(900)
36
+ expect(described_class.cache_time).to be(3600)
37
37
  end
38
38
 
39
39
  it 'returns cache time as an Integer' do
40
- allow(ENV).to receive(:fetch).with('WD_CACHE_TIME', 86_400).and_return('999')
40
+ allow(ENV).to receive(:fetch).with('WD_CACHE_TIME', 3600).and_return('999')
41
41
  expect(described_class.cache_time).to be_an_instance_of(Integer)
42
42
  end
43
43
  end
@@ -49,25 +49,31 @@ describe Webdrivers do
49
49
  end
50
50
 
51
51
  it 'uses provided value' do
52
- begin
53
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
54
- described_class.install_dir = install_dir
52
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
53
+ described_class.install_dir = install_dir
55
54
 
56
- expect(described_class.install_dir).to eq install_dir
55
+ expect(described_class.install_dir).to eq install_dir
56
+ ensure
57
+ described_class.install_dir = nil
58
+ end
59
+
60
+ context 'when ENV variable WD_INSTALL_DIR is set and Webdrivers.install_dir is not' do
61
+ it 'uses path from the ENV variable' do
62
+ described_class.install_dir = nil
63
+ allow(ENV).to receive(:[]).with('WD_INSTALL_DIR').and_return('custom_dir')
64
+ expect(described_class.install_dir).to be('custom_dir')
57
65
  ensure
58
66
  described_class.install_dir = nil
59
67
  end
60
68
  end
61
69
 
62
- context 'when ENV variable WD_INSTALL_DIR is set and Webdrivers.install_dir is not' do
63
- it 'uses path from the ENV variable' do
64
- begin
65
- described_class.install_dir = nil
66
- allow(ENV).to receive(:[]).with('WD_INSTALL_DIR').and_return('custom_dir')
67
- expect(described_class.install_dir).to be('custom_dir')
68
- ensure
69
- described_class.install_dir = nil
70
- end
70
+ context 'when both ENV variable WD_INSTALL_DIR and Webdrivers.install_dir are set' do
71
+ it 'uses path from Webdrivers.install_dir' do
72
+ described_class.install_dir = 'my_install_dir_path'
73
+ allow(ENV).to receive(:[]).with('WD_INSTALL_DIR').and_return('my_env_path')
74
+ expect(described_class.install_dir).to be('my_install_dir_path')
75
+ ensure
76
+ described_class.install_dir = nil
71
77
  end
72
78
  end
73
79
  end