Skip to content

Commit cd72cc0

Browse files
committed
[rb] update specs for Ruby 2.4 and RSpec 3.0
1 parent 6cbff93 commit cd72cc0

File tree

10 files changed

+141
-135
lines changed

10 files changed

+141
-135
lines changed

rb/selenium-webdriver.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ HTML of the application.'
2626
s.add_runtime_dependency 'childprocess', ['~> 0.5']
2727
s.add_runtime_dependency 'websocket', ['~> 1.0']
2828

29-
s.add_development_dependency 'rspec', ['~> 2.99.0']
29+
s.add_development_dependency 'rspec', ['~> 3.0']
3030
s.add_development_dependency 'rack', ['~> 1.0']
3131
s.add_development_dependency 'ci_reporter', ['~> 1.6', '>= 1.6.2']
32-
s.add_development_dependency 'webmock', ['~> 1.7', '>= 1.7.5']
32+
s.add_development_dependency 'webmock', ['~> 2.0']
3333
s.add_development_dependency 'yard', ['~> 0.8.7']
3434
end

rb/spec/integration/selenium/webdriver/firefox/profile_spec.rb

Lines changed: 121 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -22,161 +22,163 @@
2222
module Selenium
2323
module WebDriver
2424
module Firefox
25-
describe Profile do
26-
let(:profile) { Profile.new }
27-
let(:browser) { GlobalTestEnv.driver == :remote ? :remote : :firefox }
25+
compliant_on browser: :firefox do
26+
describe Profile do
27+
let(:profile) { Profile.new }
28+
let(:browser) { GlobalTestEnv.driver == :remote ? :remote : :firefox }
2829

29-
def read_generated_prefs(from = nil)
30-
prof = from || profile
31-
dir = prof.layout_on_disk
30+
def read_generated_prefs(from = nil)
31+
prof = from || profile
32+
dir = prof.layout_on_disk
3233

33-
File.read(File.join(dir, 'user.js'))
34-
end
34+
File.read(File.join(dir, 'user.js'))
35+
end
3536

36-
def profile_opts
37-
if GlobalTestEnv.driver == :remote
38-
opt = { desired_capabilities: GlobalTestEnv.remote_capabilities.dup }
39-
opt[:desired_capabilities][:firefox_profile] = profile
40-
opt[:url] = GlobalTestEnv.remote_server.webdriver_url if GlobalTestEnv.remote_server?
41-
opt
42-
else
43-
{ desired_capabilities: Remote::Capabilities.firefox(marionette: GlobalTestEnv.browser == :firefox),
44-
profile: profile }
37+
def profile_opts
38+
if GlobalTestEnv.driver == :remote
39+
opt = {desired_capabilities: GlobalTestEnv.remote_capabilities.dup}
40+
opt[:desired_capabilities][:firefox_profile] = profile
41+
opt[:url] = GlobalTestEnv.remote_server.webdriver_url if GlobalTestEnv.remote_server?
42+
opt
43+
else
44+
{desired_capabilities: Remote::Capabilities.firefox(marionette: GlobalTestEnv.browser == :firefox),
45+
profile: profile}
46+
end
4547
end
46-
end
4748

48-
it 'should set additional preferences' do
49-
profile['foo.number'] = 123
50-
profile['foo.boolean'] = true
51-
profile['foo.string'] = 'bar'
49+
it 'should set additional preferences' do
50+
profile['foo.number'] = 123
51+
profile['foo.boolean'] = true
52+
profile['foo.string'] = 'bar'
5253

53-
string = read_generated_prefs
54-
expect(string).to include('user_pref("foo.number", 123)')
55-
expect(string).to include('user_pref("foo.boolean", true)')
56-
expect(string).to include(%{user_pref("foo.string", "bar")})
57-
end
54+
string = read_generated_prefs
55+
expect(string).to include('user_pref("foo.number", 123)')
56+
expect(string).to include('user_pref("foo.boolean", true)')
57+
expect(string).to include(%{user_pref("foo.string", "bar")})
58+
end
5859

59-
it 'should be serializable to JSON' do
60-
profile['foo.boolean'] = true
60+
it 'should be serializable to JSON' do
61+
profile['foo.boolean'] = true
6162

62-
new_profile = Profile.from_json(profile.to_json)
63-
string = read_generated_prefs(new_profile)
64-
expect(string).to include('user_pref("foo.boolean", true)')
65-
end
63+
new_profile = Profile.from_json(profile.to_json)
64+
string = read_generated_prefs(new_profile)
65+
expect(string).to include('user_pref("foo.boolean", true)')
66+
end
6667

67-
it 'should not let user override defaults' do
68-
profile['app.update.enabled'] = true
68+
it 'should not let user override defaults' do
69+
profile['app.update.enabled'] = true
6970

70-
string = read_generated_prefs
71-
expect(string).to include('user_pref("app.update.enabled", false)')
72-
end
73-
74-
it 'should properly handle escaped characters' do
75-
profile['foo'] = 'C:\\r\\n'
71+
string = read_generated_prefs
72+
expect(string).to include('user_pref("app.update.enabled", false)')
73+
end
7674

77-
string = read_generated_prefs
78-
expect(string).to include('user_pref("foo", "C:\\\\r\\\\n");')
79-
end
75+
it 'should properly handle escaped characters' do
76+
profile['foo'] = 'C:\\r\\n'
8077

81-
it 'should let the user override some specific prefs' do
82-
profile['browser.startup.page'] = 'http://example.com'
78+
string = read_generated_prefs
79+
expect(string).to include('user_pref("foo", "C:\\\\r\\\\n");')
80+
end
8381

84-
string = read_generated_prefs
85-
expect(string).to include(%{user_pref("browser.startup.page", "http://example.com")})
86-
end
82+
it 'should let the user override some specific prefs' do
83+
profile['browser.startup.page'] = 'http://example.com'
8784

88-
it 'should raise an error if the value given is not a string, number or boolean' do
89-
expect { profile['foo.bar'] = [] }.to raise_error(TypeError)
90-
end
85+
string = read_generated_prefs
86+
expect(string).to include(%{user_pref("browser.startup.page", "http://example.com")})
87+
end
9188

92-
it 'should raise an error if the value is already stringified' do
93-
expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError)
94-
end
89+
it 'should raise an error if the value given is not a string, number or boolean' do
90+
expect { profile['foo.bar'] = [] }.to raise_error(TypeError)
91+
end
9592

96-
it 'should enable secure SSL' do
97-
profile.secure_ssl = true
93+
it 'should raise an error if the value is already stringified' do
94+
expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError)
95+
end
9896

99-
string = read_generated_prefs
100-
expect(string).to include('user_pref("webdriver_accept_untrusted_certs", false)')
101-
end
97+
it 'should enable secure SSL' do
98+
profile.secure_ssl = true
10299

103-
it 'should disable secure SSL' do
104-
profile.secure_ssl = false
100+
string = read_generated_prefs
101+
expect(string).to include('user_pref("webdriver_accept_untrusted_certs", false)')
102+
end
105103

106-
string = read_generated_prefs
107-
expect(string).to include('user_pref("webdriver_accept_untrusted_certs", true)')
108-
end
104+
it 'should disable secure SSL' do
105+
profile.secure_ssl = false
109106

110-
it 'should change the setting for untrusted certificate issuer' do
111-
profile.assume_untrusted_certificate_issuer = false
107+
string = read_generated_prefs
108+
expect(string).to include('user_pref("webdriver_accept_untrusted_certs", true)')
109+
end
112110

113-
string = read_generated_prefs
114-
expect(string).to include('user_pref("webdriver_assume_untrusted_issuer", false)')
115-
end
111+
it 'should change the setting for untrusted certificate issuer' do
112+
profile.assume_untrusted_certificate_issuer = false
116113

117-
it 'can configure a manual proxy' do
118-
proxy = Proxy.new(
119-
http: 'foo:123',
120-
ftp: 'bar:234',
121-
ssl: 'baz:345',
122-
no_proxy: 'localhost'
123-
)
114+
string = read_generated_prefs
115+
expect(string).to include('user_pref("webdriver_assume_untrusted_issuer", false)')
116+
end
124117

125-
profile.proxy = proxy
126-
string = read_generated_prefs
118+
it 'can configure a manual proxy' do
119+
proxy = Proxy.new(
120+
http: 'foo:123',
121+
ftp: 'bar:234',
122+
ssl: 'baz:345',
123+
no_proxy: 'localhost'
124+
)
127125

128-
expect(string).to include('user_pref("network.proxy.http", "foo")')
129-
expect(string).to include('user_pref("network.proxy.http_port", 123)')
126+
profile.proxy = proxy
127+
string = read_generated_prefs
130128

131-
expect(string).to include('user_pref("network.proxy.ftp", "bar")')
132-
expect(string).to include('user_pref("network.proxy.ftp_port", 234)')
129+
expect(string).to include('user_pref("network.proxy.http", "foo")')
130+
expect(string).to include('user_pref("network.proxy.http_port", 123)')
133131

134-
expect(string).to include('user_pref("network.proxy.ssl", "baz")')
135-
expect(string).to include('user_pref("network.proxy.ssl_port", 345)')
132+
expect(string).to include('user_pref("network.proxy.ftp", "bar")')
133+
expect(string).to include('user_pref("network.proxy.ftp_port", 234)')
136134

137-
expect(string).to include('user_pref("network.proxy.no_proxies_on", "localhost")')
138-
expect(string).to include('user_pref("network.proxy.type", 1)')
139-
end
135+
expect(string).to include('user_pref("network.proxy.ssl", "baz")')
136+
expect(string).to include('user_pref("network.proxy.ssl_port", 345)')
140137

141-
it 'can configure a PAC proxy' do
142-
profile.proxy = Proxy.new(pac: 'http://foo/bar.pac')
143-
string = read_generated_prefs
138+
expect(string).to include('user_pref("network.proxy.no_proxies_on", "localhost")')
139+
expect(string).to include('user_pref("network.proxy.type", 1)')
140+
end
144141

145-
expect(string).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")')
146-
expect(string).to include('user_pref("network.proxy.type", 2)')
147-
end
142+
it 'can configure a PAC proxy' do
143+
profile.proxy = Proxy.new(pac: 'http://foo/bar.pac')
144+
string = read_generated_prefs
148145

149-
it 'can configure an auto-detected proxy' do
150-
profile.proxy = Proxy.new(auto_detect: true)
151-
string = read_generated_prefs
146+
expect(string).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")')
147+
expect(string).to include('user_pref("network.proxy.type", 2)')
148+
end
152149

153-
expect(string).to include('user_pref("network.proxy.type", 4)')
154-
end
150+
it 'can configure an auto-detected proxy' do
151+
profile.proxy = Proxy.new(auto_detect: true)
152+
string = read_generated_prefs
155153

156-
describe 'with browser' do
157-
before(:each) do
158-
profile['browser.startup.homepage'] = url_for('simpleTest.html')
159-
profile['browser.startup.page'] = 1
154+
expect(string).to include('user_pref("network.proxy.type", 4)')
160155
end
161156

162-
it 'should instantiate the browser with the correct profile' do
163-
begin
164-
driver1 = WebDriver.for(browser, profile_opts.dup)
165-
expect{ wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error
166-
ensure
167-
driver1.quit
157+
describe 'with browser' do
158+
before(:each) do
159+
profile['browser.startup.homepage'] = url_for('simpleTest.html')
160+
profile['browser.startup.page'] = 1
161+
end
162+
163+
it 'should instantiate the browser with the correct profile' do
164+
begin
165+
driver1 = WebDriver.for(browser, profile_opts.dup)
166+
expect { wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error
167+
ensure
168+
driver1.quit
169+
end
168170
end
169-
end
170171

171-
it 'should be able to use the same profile more than once' do
172-
begin
173-
driver1 = WebDriver.for(browser, profile_opts.dup)
174-
expect{ wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error
175-
driver2 = WebDriver.for(browser, profile_opts.dup)
176-
expect{ wait(5).until { driver2.find_element(id: 'oneline') } }.to_not raise_error
177-
ensure
178-
driver1.quit if driver1
179-
driver2.quit if driver2
172+
it 'should be able to use the same profile more than once' do
173+
begin
174+
driver1 = WebDriver.for(browser, profile_opts.dup)
175+
expect { wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error
176+
driver2 = WebDriver.for(browser, profile_opts.dup)
177+
expect { wait(5).until { driver2.find_element(id: 'oneline') } }.to_not raise_error
178+
ensure
179+
driver1.quit if driver1
180+
driver2.quit if driver2
181+
end
180182
end
181183
end
182184
end

rb/spec/integration/selenium/webdriver/spec_support/rack_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def start
4848
end
4949

5050
def run
51-
handler.run @app, Host: @host, Port: @port
51+
handler.run @app, Host: @host, Port: @port, AccessLog: []
5252
end
5353

5454
def where_is(file)

rb/spec/unit/selenium/webdriver/chrome/bridge_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module Chrome
117117
end
118118

119119
it 'accepts :service_log_path' do
120-
expect(Service).to receive(:new).with(Chrome.driver_path, Service::DEFAULT_PORT, '--log-path=/foo/bar')
120+
expect(Service).to receive(:new).with(nil, Service::DEFAULT_PORT, '--log-path=/foo/bar')
121121
Bridge.new(http_client: http, service_log_path: '/foo/bar')
122122
end
123123
end

rb/spec/unit/selenium/webdriver/chrome/profile_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Chrome
3131
allow(File).to receive(:exist?).with(model).and_return true
3232
allow(File).to receive(:directory?).with(model).and_return true
3333

34-
Dir.stub(mktmpdir: '/tmp/some/path')
34+
allow(Dir).to receive(:mktmpdir).and_return('/tmp/some/path')
3535
allow(FileUtils).to receive(:rm_rf)
3636
allow(FileUtils).to receive(:mkdir_p)
3737
allow(FileUtils).to receive(:cp_r)

rb/spec/unit/selenium/webdriver/common/driver_extensions/has_network_connection_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,31 @@ module DriverExtensions
2525
describe HasNetworkConnection do
2626
class FakeDriver
2727
include HasNetworkConnection
28+
attr_reader :bridge
29+
def initialize(bridge)
30+
@bridge = bridge
31+
end
2832
end
2933

30-
let(:driver) { FakeDriver.new }
34+
let(:driver) { FakeDriver.new(double(Remote::Bridge)) }
3135

3236
describe '#network_connection' do
3337
it 'returns the correct connection type' do
34-
allow(@bridge).to receive(:network_connection) { 1 }
38+
allow(driver.bridge).to receive(:network_connection) { 1 }
3539

3640
expect(driver.network_connection_type).to eq :airplane_mode
3741
end
3842

3943
it 'returns an unknown connection value' do
40-
allow(@bridge).to receive(:network_connection) { 5 }
44+
allow(driver.bridge).to receive(:network_connection) { 5 }
4145

4246
expect(driver.network_connection_type).to eq 5
4347
end
4448
end
4549

4650
describe '#network_connection=' do
4751
it 'sends out the correct connection value' do
48-
expect(@bridge).to receive(:network_connection=).with(1)
52+
expect(driver.bridge).to receive(:network_connection=).with(1)
4953

5054
driver.network_connection_type = :airplane_mode
5155
end

rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module WebDriver
2424
module Firefox
2525
describe Extension do
2626
before do
27-
File.stub(exist?: true)
27+
allow(File).to receive(:exist?).and_return(true)
2828
end
2929

3030
let(:extension) do

rb/spec/unit/selenium/webdriver/ie/bridge_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module IE
6565
end
6666

6767
it 'sets the server log level and log file' do
68-
expect(Service).to receive(:new).with(IE.driver_path, Service::DEFAULT_PORT, '--log-level=TRACE', '--log-file=/foo/bar')
68+
expect(Service).to receive(:new).with(nil, Service::DEFAULT_PORT, '--log-level=TRACE', '--log-file=/foo/bar')
6969

7070
Bridge.new(
7171
log_level: :trace,
@@ -75,7 +75,7 @@ module IE
7575
end
7676

7777
it 'should be able to set implementation' do
78-
expect(Service).to receive(:new).with(IE.driver_path, Service::DEFAULT_PORT, '--implementation=VENDOR')
78+
expect(Service).to receive(:new).with(nil, Service::DEFAULT_PORT, '--implementation=VENDOR')
7979

8080
Bridge.new(
8181
implementation: :vendor,

0 commit comments

Comments
 (0)