webdrivers 3.9.2 → 3.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,210 +1,210 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Webdrivers::Geckodriver do
6
- let(:geckodriver) { described_class }
7
-
8
- before do
9
- geckodriver.remove
10
- geckodriver.required_version = nil
11
- end
12
-
13
- describe '#update' do
14
- context 'when evaluating #correct_binary?' do
15
- it 'does not download when latest version and current version match' do
16
- allow(geckodriver).to receive(:latest_version).and_return(Gem::Version.new('0.3.0'))
17
- allow(geckodriver).to receive(:current_version).and_return(Gem::Version.new('0.3.0'))
18
-
19
- geckodriver.update
20
-
21
- expect(geckodriver.send(:exists?)).to be false
22
- end
23
-
24
- it 'does not download when offline, but binary exists' do
25
- allow(Webdrivers::System).to receive(:call).and_return('geckodriver 0.24.0 ( 2019-01-28)')
26
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
27
- allow(geckodriver).to receive(:exists?).and_return(true)
28
-
29
- geckodriver.update
30
-
31
- expect(File.exist?(geckodriver.driver_path)).to be false
32
- end
33
-
34
- it 'raises ConnectionError when offline, and no binary exists' do
35
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
36
- allow(geckodriver).to receive(:exists?).and_return(false)
37
-
38
- expect { geckodriver.update }.to raise_error(Webdrivers::ConnectionError)
39
- end
40
- end
41
-
42
- context 'when correct binary is found' do
43
- before { allow(geckodriver).to receive(:correct_binary?).and_return(true) }
44
-
45
- it 'does not download' do
46
- geckodriver.update
47
-
48
- expect(geckodriver.current_version).to be_nil
49
- end
50
-
51
- it 'does not raise exception if offline' do
52
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
53
-
54
- geckodriver.update
55
-
56
- expect(geckodriver.current_version).to be_nil
57
- end
58
- end
59
-
60
- context 'when correct binary is not found' do
61
- before { allow(geckodriver).to receive(:correct_binary?).and_return(false) }
62
-
63
- it 'downloads binary' do
64
- geckodriver.update
65
-
66
- expect(geckodriver.current_version).not_to be_nil
67
- end
68
-
69
- it 'raises ConnectionError if offline' do
70
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
71
-
72
- msg = %r{Can not reach https://github.com/mozilla/geckodriver/releases}
73
- expect { geckodriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
74
- end
75
- end
76
-
77
- it 'finds the required version from parsed downloads page' do
78
- base = 'https://github.com/mozilla/geckodriver/releases/download'
79
- url = %r{#{base}\/v0\.2\.0\/geckodriver-v0\.2\.0-}
80
-
81
- allow(Webdrivers::System).to receive(:download).with(url, geckodriver.driver_path)
82
-
83
- geckodriver.required_version = '0.2.0'
84
- geckodriver.update
85
-
86
- expect(Webdrivers::System).to have_received(:download).with(url, geckodriver.driver_path)
87
- end
88
-
89
- it 'does something when a wrong version is supplied' do
90
- geckodriver.required_version = '0.2.0'
91
-
92
- msg = /Net::HTTPServerException: 404 "Not Found"/
93
- expect { geckodriver.update }.to raise_error(StandardError, msg)
94
- end
95
- end
96
-
97
- describe '#current_version' do
98
- it 'returns nil if binary does not exist on the system' do
99
- allow(geckodriver).to receive(:driver_path).and_return('')
100
-
101
- expect(geckodriver.current_version).to be_nil
102
- end
103
-
104
- it 'returns a Gem::Version instance if binary is on the system' do
105
- allow(geckodriver).to receive(:exists?).and_return(true)
106
-
107
- return_value = "geckodriver 0.24.0 ( 2019-01-28)
108
-
109
- The source code of this program is available from
110
- testing/geckodriver in https://hg.mozilla.org/mozilla-central.
111
-
112
- This program is subject to the terms of the Mozilla Public License 2.0.
113
- You can obtain a copy of the license at https://mozilla.org/MPL/2.0/"
114
-
115
- allow(Webdrivers::System).to receive(:call).with("#{geckodriver.driver_path} --version").and_return return_value
116
-
117
- expect(geckodriver.current_version).to eq Gem::Version.new('0.24.0')
118
- end
119
- end
120
-
121
- describe '#latest_version' do
122
- it 'finds the latest version directly' do
123
- url = 'https://github.com/mozilla/geckodriver/releases/tag/v0.24.0'
124
- allow(Webdrivers::Network).to receive(:get_url).and_return(url)
125
-
126
- geckodriver.update
127
-
128
- expect(geckodriver.latest_version).to eq Gem::Version.new('0.24.0')
129
- end
130
-
131
- it 'creates cached file' do
132
- allow(Webdrivers::Network).to receive(:get).and_return('0.24.0')
133
-
134
- geckodriver.latest_version
135
- expect(File.exist?("#{Webdrivers::System.install_dir}/geckodriver.version")).to eq true
136
- end
137
-
138
- it 'does not make network call if cache is valid' do
139
- allow(Webdrivers).to receive(:cache_time).and_return(3600)
140
- Webdrivers::System.cache_version('geckodriver', '0.23.0')
141
- allow(Webdrivers::Network).to receive(:get)
142
-
143
- expect(geckodriver.latest_version).to eq Gem::Version.new('0.23.0')
144
-
145
- expect(Webdrivers::Network).not_to have_received(:get)
146
- end
147
-
148
- it 'makes a network call if cache is expired' do
149
- Webdrivers::System.cache_version('geckodriver', '0.23.0')
150
- url = 'https://github.com/mozilla/geckodriver/releases/tag/v0.24.0'
151
- allow(Webdrivers::Network).to receive(:get_url).and_return(url)
152
- allow(Webdrivers::System).to receive(:valid_cache?)
153
-
154
- expect(geckodriver.latest_version).to eq Gem::Version.new('0.24.0')
155
-
156
- expect(Webdrivers::Network).to have_received(:get_url)
157
- expect(Webdrivers::System).to have_received(:valid_cache?)
158
- end
159
- end
160
-
161
- describe '#required_version=' do
162
- it 'returns the version specified as a Float' do
163
- geckodriver.required_version = 0.12
164
-
165
- expect(geckodriver.required_version).to eq Gem::Version.new('0.12')
166
- end
167
-
168
- it 'returns the version specified as a String' do
169
- geckodriver.required_version = '0.12.1'
170
-
171
- expect(geckodriver.required_version).to eq Gem::Version.new('0.12.1')
172
- end
173
- end
174
-
175
- describe '#remove' do
176
- it 'removes existing geckodriver' do
177
- geckodriver.update
178
-
179
- geckodriver.remove
180
- expect(geckodriver.current_version).to be_nil
181
- end
182
-
183
- it 'does not raise exception if no geckodriver found' do
184
- expect { geckodriver.remove }.not_to raise_error
185
- end
186
- end
187
-
188
- describe '#install_dir' do
189
- it 'uses ~/.webdrivers as default value' do
190
- expect(Webdrivers::System.install_dir).to include('.webdriver')
191
- end
192
-
193
- it 'uses provided value' do
194
- begin
195
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
196
- Webdrivers.install_dir = install_dir
197
-
198
- expect(Webdrivers::System.install_dir).to eq install_dir
199
- ensure
200
- Webdrivers.install_dir = nil
201
- end
202
- end
203
- end
204
-
205
- describe '#driver_path' do
206
- it 'returns full location of binary' do
207
- expect(geckodriver.driver_path).to match("#{File.join(ENV['HOME'])}/.webdrivers/geckodriver")
208
- end
209
- end
210
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Webdrivers::Geckodriver do
6
+ let(:geckodriver) { described_class }
7
+
8
+ before do
9
+ geckodriver.remove
10
+ geckodriver.required_version = nil
11
+ end
12
+
13
+ describe '#update' do
14
+ context 'when evaluating #correct_binary?' do
15
+ it 'does not download when latest version and current version match' do
16
+ allow(geckodriver).to receive(:latest_version).and_return(Gem::Version.new('0.3.0'))
17
+ allow(geckodriver).to receive(:current_version).and_return(Gem::Version.new('0.3.0'))
18
+
19
+ geckodriver.update
20
+
21
+ expect(geckodriver.send(:exists?)).to be false
22
+ end
23
+
24
+ it 'does not download when offline, but binary exists' do
25
+ allow(Webdrivers::System).to receive(:call).and_return('geckodriver 0.24.0 ( 2019-01-28)')
26
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
27
+ allow(geckodriver).to receive(:exists?).and_return(true)
28
+
29
+ geckodriver.update
30
+
31
+ expect(File.exist?(geckodriver.driver_path)).to be false
32
+ end
33
+
34
+ it 'raises ConnectionError when offline, and no binary exists' do
35
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
36
+ allow(geckodriver).to receive(:exists?).and_return(false)
37
+
38
+ expect { geckodriver.update }.to raise_error(Webdrivers::ConnectionError)
39
+ end
40
+ end
41
+
42
+ context 'when correct binary is found' do
43
+ before { allow(geckodriver).to receive(:correct_binary?).and_return(true) }
44
+
45
+ it 'does not download' do
46
+ geckodriver.update
47
+
48
+ expect(geckodriver.current_version).to be_nil
49
+ end
50
+
51
+ it 'does not raise exception if offline' do
52
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
53
+
54
+ geckodriver.update
55
+
56
+ expect(geckodriver.current_version).to be_nil
57
+ end
58
+ end
59
+
60
+ context 'when correct binary is not found' do
61
+ before { allow(geckodriver).to receive(:correct_binary?).and_return(false) }
62
+
63
+ it 'downloads binary' do
64
+ geckodriver.update
65
+
66
+ expect(geckodriver.current_version).not_to be_nil
67
+ end
68
+
69
+ it 'raises ConnectionError if offline' do
70
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
71
+
72
+ msg = %r{Can not reach https://github.com/mozilla/geckodriver/releases}
73
+ expect { geckodriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
74
+ end
75
+ end
76
+
77
+ it 'finds the required version from parsed downloads page' do
78
+ base = 'https://github.com/mozilla/geckodriver/releases/download'
79
+ url = %r{#{base}\/v0\.2\.0\/geckodriver-v0\.2\.0-}
80
+
81
+ allow(Webdrivers::System).to receive(:download).with(url, geckodriver.driver_path)
82
+
83
+ geckodriver.required_version = '0.2.0'
84
+ geckodriver.update
85
+
86
+ expect(Webdrivers::System).to have_received(:download).with(url, geckodriver.driver_path)
87
+ end
88
+
89
+ it 'does something when a wrong version is supplied' do
90
+ geckodriver.required_version = '0.2.0'
91
+
92
+ msg = /Net::HTTPServerException: 404 "Not Found"/
93
+ expect { geckodriver.update }.to raise_error(StandardError, msg)
94
+ end
95
+ end
96
+
97
+ describe '#current_version' do
98
+ it 'returns nil if binary does not exist on the system' do
99
+ allow(geckodriver).to receive(:driver_path).and_return('')
100
+
101
+ expect(geckodriver.current_version).to be_nil
102
+ end
103
+
104
+ it 'returns a Gem::Version instance if binary is on the system' do
105
+ allow(geckodriver).to receive(:exists?).and_return(true)
106
+
107
+ return_value = "geckodriver 0.24.0 ( 2019-01-28)
108
+
109
+ The source code of this program is available from
110
+ testing/geckodriver in https://hg.mozilla.org/mozilla-central.
111
+
112
+ This program is subject to the terms of the Mozilla Public License 2.0.
113
+ You can obtain a copy of the license at https://mozilla.org/MPL/2.0/"
114
+
115
+ allow(Webdrivers::System).to receive(:call).with("#{geckodriver.driver_path} --version").and_return return_value
116
+
117
+ expect(geckodriver.current_version).to eq Gem::Version.new('0.24.0')
118
+ end
119
+ end
120
+
121
+ describe '#latest_version' do
122
+ it 'finds the latest version directly' do
123
+ url = 'https://github.com/mozilla/geckodriver/releases/tag/v0.24.0'
124
+ allow(Webdrivers::Network).to receive(:get_url).and_return(url)
125
+
126
+ geckodriver.update
127
+
128
+ expect(geckodriver.latest_version).to eq Gem::Version.new('0.24.0')
129
+ end
130
+
131
+ it 'creates cached file' do
132
+ allow(Webdrivers::Network).to receive(:get).and_return('0.24.0')
133
+
134
+ geckodriver.latest_version
135
+ expect(File.exist?("#{Webdrivers::System.install_dir}/geckodriver.version")).to eq true
136
+ end
137
+
138
+ it 'does not make network call if cache is valid' do
139
+ allow(Webdrivers).to receive(:cache_time).and_return(3600)
140
+ Webdrivers::System.cache_version('geckodriver', '0.23.0')
141
+ allow(Webdrivers::Network).to receive(:get)
142
+
143
+ expect(geckodriver.latest_version).to eq Gem::Version.new('0.23.0')
144
+
145
+ expect(Webdrivers::Network).not_to have_received(:get)
146
+ end
147
+
148
+ it 'makes a network call if cache is expired' do
149
+ Webdrivers::System.cache_version('geckodriver', '0.23.0')
150
+ url = 'https://github.com/mozilla/geckodriver/releases/tag/v0.24.0'
151
+ allow(Webdrivers::Network).to receive(:get_url).and_return(url)
152
+ allow(Webdrivers::System).to receive(:valid_cache?)
153
+
154
+ expect(geckodriver.latest_version).to eq Gem::Version.new('0.24.0')
155
+
156
+ expect(Webdrivers::Network).to have_received(:get_url)
157
+ expect(Webdrivers::System).to have_received(:valid_cache?)
158
+ end
159
+ end
160
+
161
+ describe '#required_version=' do
162
+ it 'returns the version specified as a Float' do
163
+ geckodriver.required_version = 0.12
164
+
165
+ expect(geckodriver.required_version).to eq Gem::Version.new('0.12')
166
+ end
167
+
168
+ it 'returns the version specified as a String' do
169
+ geckodriver.required_version = '0.12.1'
170
+
171
+ expect(geckodriver.required_version).to eq Gem::Version.new('0.12.1')
172
+ end
173
+ end
174
+
175
+ describe '#remove' do
176
+ it 'removes existing geckodriver' do
177
+ geckodriver.update
178
+
179
+ geckodriver.remove
180
+ expect(geckodriver.current_version).to be_nil
181
+ end
182
+
183
+ it 'does not raise exception if no geckodriver found' do
184
+ expect { geckodriver.remove }.not_to raise_error
185
+ end
186
+ end
187
+
188
+ describe '#install_dir' do
189
+ it 'uses ~/.webdrivers as default value' do
190
+ expect(Webdrivers::System.install_dir).to include('.webdriver')
191
+ end
192
+
193
+ it 'uses provided value' do
194
+ begin
195
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
196
+ Webdrivers.install_dir = install_dir
197
+
198
+ expect(Webdrivers::System.install_dir).to eq install_dir
199
+ ensure
200
+ Webdrivers.install_dir = nil
201
+ end
202
+ end
203
+ end
204
+
205
+ describe '#driver_path' do
206
+ it 'returns full location of binary' do
207
+ expect(geckodriver.driver_path).to match("#{File.join(ENV['HOME'])}/.webdrivers/geckodriver")
208
+ end
209
+ end
210
+ end
@@ -1,192 +1,192 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Webdrivers::IEdriver do
6
- let(:iedriver) { described_class }
7
-
8
- before do
9
- iedriver.remove
10
- iedriver.required_version = nil
11
- end
12
-
13
- describe '#update' do
14
- context 'when evaluating #correct_binary?' do
15
- it 'does not download when latest version and current version match' do
16
- allow(iedriver).to receive(:latest_version).and_return(Gem::Version.new('0.3.0'))
17
- allow(iedriver).to receive(:current_version).and_return(Gem::Version.new('0.3.0'))
18
-
19
- iedriver.update
20
-
21
- expect(iedriver.send(:exists?)).to be false
22
- end
23
-
24
- it 'does not download when offline, but binary exists' do
25
- allow(Webdrivers::System).to receive(:call).and_return('something IEDriverServer.exe 3.5.1 something else')
26
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
27
- allow(iedriver).to receive(:exists?).and_return(true)
28
-
29
- iedriver.update
30
-
31
- expect(File.exist?(iedriver.driver_path)).to be false
32
- end
33
-
34
- it 'raises ConnectionError when offline, and no binary exists' do
35
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
36
- allow(iedriver).to receive(:exists?).and_return(false)
37
-
38
- expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError)
39
- end
40
- end
41
-
42
- context 'when correct binary is found' do
43
- before { allow(iedriver).to receive(:correct_binary?).and_return(true) }
44
-
45
- it 'does not download' do
46
- iedriver.update
47
-
48
- expect(iedriver.current_version).to be_nil
49
- end
50
-
51
- it 'does not raise exception if offline' do
52
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
53
-
54
- iedriver.update
55
-
56
- expect(iedriver.current_version).to be_nil
57
- end
58
- end
59
-
60
- context 'when correct binary is not found' do
61
- before { allow(iedriver).to receive(:correct_binary?).and_return(false) }
62
-
63
- it 'downloads binary' do
64
- iedriver.update
65
-
66
- expect(File.exist?(iedriver.driver_path)).to eq true
67
- end
68
-
69
- it 'raises ConnectionError if offline' do
70
- allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
71
-
72
- msg = %r{Can not reach https://selenium-release.storage.googleapis.com/}
73
- expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
74
- end
75
- end
76
- end
77
-
78
- describe '#current_version' do
79
- it 'returns nil if binary does not exist on the system' do
80
- allow(iedriver).to receive(:driver_path).and_return('')
81
-
82
- expect(iedriver.current_version).to be_nil
83
- end
84
-
85
- it 'returns a Gem::Version instance if binary is on the system' do
86
- allow(iedriver).to receive(:exists?).and_return(true)
87
-
88
- return_value = 'something IEDriverServer.exe 3.5.1 something else'
89
-
90
- allow(Webdrivers::System).to receive(:call).with("#{iedriver.driver_path} --version").and_return return_value
91
-
92
- expect(iedriver.current_version).to eq Gem::Version.new('3.5.1')
93
- end
94
- end
95
-
96
- describe '#latest_version' do
97
- it 'finds the latest version from parsed hash' do
98
- base = 'https://selenium-release.storage.googleapis.com/'
99
- hash = {Gem::Version.new('3.4.0') => "#{base}/3.4/IEDriverServer_Win32_3.4.0.zip",
100
- Gem::Version.new('3.5.0') => "#{base}/3.5/IEDriverServer_Win32_3.5.0.zip",
101
- Gem::Version.new('3.5.1') => "#{base}/3.5/IEDriverServer_Win32_3.5.1.zip"}
102
- allow(iedriver).to receive(:downloads).and_return(hash)
103
-
104
- expect(iedriver.latest_version).to eq Gem::Version.new('3.5.1')
105
- end
106
-
107
- it 'correctly parses the downloads page' do
108
- expect(iedriver.send(:downloads)).not_to be_empty
109
- end
110
-
111
- it 'creates cached file' do
112
- allow(Webdrivers::Network).to receive(:get).and_return('3.4.0')
113
-
114
- iedriver.latest_version
115
- expect(File.exist?("#{Webdrivers::System.install_dir}/IEDriverServer.version")).to eq true
116
- end
117
-
118
- it 'does not make network call if cache is valid' do
119
- allow(Webdrivers).to receive(:cache_time).and_return(3600)
120
- Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
121
- allow(Webdrivers::Network).to receive(:get)
122
-
123
- expect(iedriver.latest_version).to eq Gem::Version.new('3.4.0')
124
-
125
- expect(Webdrivers::Network).not_to have_received(:get)
126
- end
127
-
128
- it 'makes a network call if cache is expired' do
129
- Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
130
- base = 'https://selenium-release.storage.googleapis.com/'
131
- hash = {Gem::Version.new('3.4.0') => "#{base}/3.4/IEDriverServer_Win32_3.4.0.zip",
132
- Gem::Version.new('3.5.0') => "#{base}/3.5/IEDriverServer_Win32_3.5.0.zip",
133
- Gem::Version.new('3.5.1') => "#{base}/3.5/IEDriverServer_Win32_3.5.1.zip"}
134
- allow(iedriver).to receive(:downloads).and_return(hash)
135
- allow(Webdrivers::System).to receive(:valid_cache?)
136
-
137
- expect(iedriver.latest_version).to eq Gem::Version.new('3.5.1')
138
- expect(iedriver).to have_received(:downloads)
139
- expect(Webdrivers::System).to have_received(:valid_cache?)
140
- end
141
- end
142
-
143
- describe '#required_version=' do
144
- it 'returns the version specified as a Float' do
145
- iedriver.required_version = 0.12
146
-
147
- expect(iedriver.required_version).to eq Gem::Version.new('0.12')
148
- end
149
-
150
- it 'returns the version specified as a String' do
151
- iedriver.required_version = '0.12.1'
152
-
153
- expect(iedriver.required_version).to eq Gem::Version.new('0.12.1')
154
- end
155
- end
156
-
157
- describe '#remove' do
158
- it 'removes existing iedriver' do
159
- iedriver.update
160
-
161
- iedriver.remove
162
- expect(iedriver.current_version).to be_nil
163
- end
164
-
165
- it 'does not raise exception if no iedriver found' do
166
- expect { iedriver.remove }.not_to raise_error
167
- end
168
- end
169
-
170
- describe '#install_dir' do
171
- it 'uses ~/.webdrivers as default value' do
172
- expect(Webdrivers::System.install_dir).to include('.webdriver')
173
- end
174
-
175
- it 'uses provided value' do
176
- begin
177
- install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
178
- Webdrivers.install_dir = install_dir
179
-
180
- expect(Webdrivers::System.install_dir).to eq install_dir
181
- ensure
182
- Webdrivers.install_dir = nil
183
- end
184
- end
185
- end
186
-
187
- describe '#driver_path' do
188
- it 'returns full location of binary' do
189
- expect(iedriver.driver_path).to eq("#{File.join(ENV['HOME'])}/.webdrivers/IEDriverServer.exe")
190
- end
191
- end
192
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Webdrivers::IEdriver do
6
+ let(:iedriver) { described_class }
7
+
8
+ before do
9
+ iedriver.remove
10
+ iedriver.required_version = nil
11
+ end
12
+
13
+ describe '#update' do
14
+ context 'when evaluating #correct_binary?' do
15
+ it 'does not download when latest version and current version match' do
16
+ allow(iedriver).to receive(:latest_version).and_return(Gem::Version.new('0.3.0'))
17
+ allow(iedriver).to receive(:current_version).and_return(Gem::Version.new('0.3.0'))
18
+
19
+ iedriver.update
20
+
21
+ expect(iedriver.send(:exists?)).to be false
22
+ end
23
+
24
+ it 'does not download when offline, but binary exists' do
25
+ allow(Webdrivers::System).to receive(:call).and_return('something IEDriverServer.exe 3.5.1 something else')
26
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
27
+ allow(iedriver).to receive(:exists?).and_return(true)
28
+
29
+ iedriver.update
30
+
31
+ expect(File.exist?(iedriver.driver_path)).to be false
32
+ end
33
+
34
+ it 'raises ConnectionError when offline, and no binary exists' do
35
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
36
+ allow(iedriver).to receive(:exists?).and_return(false)
37
+
38
+ expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError)
39
+ end
40
+ end
41
+
42
+ context 'when correct binary is found' do
43
+ before { allow(iedriver).to receive(:correct_binary?).and_return(true) }
44
+
45
+ it 'does not download' do
46
+ iedriver.update
47
+
48
+ expect(iedriver.current_version).to be_nil
49
+ end
50
+
51
+ it 'does not raise exception if offline' do
52
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
53
+
54
+ iedriver.update
55
+
56
+ expect(iedriver.current_version).to be_nil
57
+ end
58
+ end
59
+
60
+ context 'when correct binary is not found' do
61
+ before { allow(iedriver).to receive(:correct_binary?).and_return(false) }
62
+
63
+ it 'downloads binary' do
64
+ iedriver.update
65
+
66
+ expect(File.exist?(iedriver.driver_path)).to eq true
67
+ end
68
+
69
+ it 'raises ConnectionError if offline' do
70
+ allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
71
+
72
+ msg = %r{Can not reach https://selenium-release.storage.googleapis.com/}
73
+ expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe '#current_version' do
79
+ it 'returns nil if binary does not exist on the system' do
80
+ allow(iedriver).to receive(:driver_path).and_return('')
81
+
82
+ expect(iedriver.current_version).to be_nil
83
+ end
84
+
85
+ it 'returns a Gem::Version instance if binary is on the system' do
86
+ allow(iedriver).to receive(:exists?).and_return(true)
87
+
88
+ return_value = 'something IEDriverServer.exe 3.5.1 something else'
89
+
90
+ allow(Webdrivers::System).to receive(:call).with("#{iedriver.driver_path} --version").and_return return_value
91
+
92
+ expect(iedriver.current_version).to eq Gem::Version.new('3.5.1')
93
+ end
94
+ end
95
+
96
+ describe '#latest_version' do
97
+ it 'finds the latest version from parsed hash' do
98
+ base = 'https://selenium-release.storage.googleapis.com/'
99
+ hash = {Gem::Version.new('3.4.0') => "#{base}/3.4/IEDriverServer_Win32_3.4.0.zip",
100
+ Gem::Version.new('3.5.0') => "#{base}/3.5/IEDriverServer_Win32_3.5.0.zip",
101
+ Gem::Version.new('3.5.1') => "#{base}/3.5/IEDriverServer_Win32_3.5.1.zip"}
102
+ allow(iedriver).to receive(:downloads).and_return(hash)
103
+
104
+ expect(iedriver.latest_version).to eq Gem::Version.new('3.5.1')
105
+ end
106
+
107
+ it 'correctly parses the downloads page' do
108
+ expect(iedriver.send(:downloads)).not_to be_empty
109
+ end
110
+
111
+ it 'creates cached file' do
112
+ allow(Webdrivers::Network).to receive(:get).and_return('3.4.0')
113
+
114
+ iedriver.latest_version
115
+ expect(File.exist?("#{Webdrivers::System.install_dir}/IEDriverServer.version")).to eq true
116
+ end
117
+
118
+ it 'does not make network call if cache is valid' do
119
+ allow(Webdrivers).to receive(:cache_time).and_return(3600)
120
+ Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
121
+ allow(Webdrivers::Network).to receive(:get)
122
+
123
+ expect(iedriver.latest_version).to eq Gem::Version.new('3.4.0')
124
+
125
+ expect(Webdrivers::Network).not_to have_received(:get)
126
+ end
127
+
128
+ it 'makes a network call if cache is expired' do
129
+ Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
130
+ base = 'https://selenium-release.storage.googleapis.com/'
131
+ hash = {Gem::Version.new('3.4.0') => "#{base}/3.4/IEDriverServer_Win32_3.4.0.zip",
132
+ Gem::Version.new('3.5.0') => "#{base}/3.5/IEDriverServer_Win32_3.5.0.zip",
133
+ Gem::Version.new('3.5.1') => "#{base}/3.5/IEDriverServer_Win32_3.5.1.zip"}
134
+ allow(iedriver).to receive(:downloads).and_return(hash)
135
+ allow(Webdrivers::System).to receive(:valid_cache?)
136
+
137
+ expect(iedriver.latest_version).to eq Gem::Version.new('3.5.1')
138
+ expect(iedriver).to have_received(:downloads)
139
+ expect(Webdrivers::System).to have_received(:valid_cache?)
140
+ end
141
+ end
142
+
143
+ describe '#required_version=' do
144
+ it 'returns the version specified as a Float' do
145
+ iedriver.required_version = 0.12
146
+
147
+ expect(iedriver.required_version).to eq Gem::Version.new('0.12')
148
+ end
149
+
150
+ it 'returns the version specified as a String' do
151
+ iedriver.required_version = '0.12.1'
152
+
153
+ expect(iedriver.required_version).to eq Gem::Version.new('0.12.1')
154
+ end
155
+ end
156
+
157
+ describe '#remove' do
158
+ it 'removes existing iedriver' do
159
+ iedriver.update
160
+
161
+ iedriver.remove
162
+ expect(iedriver.current_version).to be_nil
163
+ end
164
+
165
+ it 'does not raise exception if no iedriver found' do
166
+ expect { iedriver.remove }.not_to raise_error
167
+ end
168
+ end
169
+
170
+ describe '#install_dir' do
171
+ it 'uses ~/.webdrivers as default value' do
172
+ expect(Webdrivers::System.install_dir).to include('.webdriver')
173
+ end
174
+
175
+ it 'uses provided value' do
176
+ begin
177
+ install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
178
+ Webdrivers.install_dir = install_dir
179
+
180
+ expect(Webdrivers::System.install_dir).to eq install_dir
181
+ ensure
182
+ Webdrivers.install_dir = nil
183
+ end
184
+ end
185
+ end
186
+
187
+ describe '#driver_path' do
188
+ it 'returns full location of binary' do
189
+ expect(iedriver.driver_path).to eq("#{File.join(ENV['HOME'])}/.webdrivers/IEDriverServer.exe")
190
+ end
191
+ end
192
+ end