Skip to content

Commit 01701f6

Browse files
committed
[rb] update specs for consistency
1 parent 62e867b commit 01701f6

File tree

18 files changed

+332
-316
lines changed

18 files changed

+332
-316
lines changed

rb/.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ RSpec/InstanceVariable:
148148
- 'spec/unit/selenium/webdriver/socket_poller_spec.rb'
149149

150150
RSpec/DescribedClass:
151-
Enabled: false
151+
EnforcedStyle: explicit

rb/spec/integration/selenium/webdriver/chrome/options_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Selenium
2323
module WebDriver
2424
module Chrome
2525
describe Options, only: {browser: :chrome} do
26-
subject(:options) { described_class.new }
26+
subject(:options) { Options.new }
2727

2828
it 'passes emulated device correctly' do
2929
options.add_emulation(device_name: 'Nexus 5')

rb/spec/integration/selenium/webdriver/edge_chrome/options_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Selenium
2323
module WebDriver
2424
module EdgeChrome
2525
describe Options, only: {browser: :edge_chrome} do
26-
subject(:options) { described_class.new }
26+
subject(:options) { Options.new }
2727

2828
it 'passes emulated device correctly' do
2929
options.add_emulation(device_name: 'Nexus 5')

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

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,40 @@ module Selenium
2323
module WebDriver
2424
module Chrome
2525
describe Options do
26-
subject(:options) { described_class.new }
26+
subject(:options) { Options.new }
2727

2828
describe '#initialize' do
2929
it 'accepts defined parameters' do
3030
allow(File).to receive(:file?).and_return(true)
3131

32-
opt = Options.new(args: %w[foo bar],
33-
prefs: {foo: 'bar'},
34-
binary: '/foo/bar',
35-
extensions: ['foo.crx', 'bar.crx'],
36-
encoded_extensions: ['encoded_foobar'],
37-
foo: 'bar',
38-
emulation: {device_name: :bar},
39-
local_state: {foo: 'bar'},
40-
detach: true,
41-
debugger_address: '127.0.0.1:8181',
42-
exclude_switches: %w[foobar barfoo],
43-
minidump_path: 'linux/only',
44-
perf_logging_prefs: {enable_network: true},
45-
window_types: %w[normal devtools])
46-
47-
expect(opt.args.to_a).to eq(%w[foo bar])
48-
expect(opt.prefs[:foo]).to eq('bar')
49-
expect(opt.binary).to eq('/foo/bar')
50-
expect(opt.extensions).to eq(['foo.crx', 'bar.crx'])
51-
expect(opt.instance_variable_get('@options')[:foo]).to eq('bar')
52-
expect(opt.emulation[:device_name]).to eq(:bar)
53-
expect(opt.local_state[:foo]).to eq('bar')
54-
expect(opt.detach).to eq(true)
55-
expect(opt.debugger_address).to eq('127.0.0.1:8181')
56-
expect(opt.exclude_switches).to eq(%w[foobar barfoo])
57-
expect(opt.minidump_path).to eq('linux/only')
58-
expect(opt.perf_logging_prefs[:enable_network]).to eq(true)
59-
expect(opt.window_types).to eq(%w[normal devtools])
32+
opts = Options.new(args: %w[foo bar],
33+
prefs: {foo: 'bar'},
34+
binary: '/foo/bar',
35+
extensions: ['foo.crx', 'bar.crx'],
36+
encoded_extensions: ['encoded_foobar'],
37+
foo: 'bar',
38+
emulation: {device_name: :bar},
39+
local_state: {foo: 'bar'},
40+
detach: true,
41+
debugger_address: '127.0.0.1:8181',
42+
exclude_switches: %w[foobar barfoo],
43+
minidump_path: 'linux/only',
44+
perf_logging_prefs: {enable_network: true},
45+
window_types: %w[normal devtools])
46+
47+
expect(opts.args.to_a).to eq(%w[foo bar])
48+
expect(opts.prefs[:foo]).to eq('bar')
49+
expect(opts.binary).to eq('/foo/bar')
50+
expect(opts.extensions).to eq(['foo.crx', 'bar.crx'])
51+
expect(opts.instance_variable_get('@options')[:foo]).to eq('bar')
52+
expect(opts.emulation[:device_name]).to eq(:bar)
53+
expect(opts.local_state[:foo]).to eq('bar')
54+
expect(opts.detach).to eq(true)
55+
expect(opts.debugger_address).to eq('127.0.0.1:8181')
56+
expect(opts.exclude_switches).to eq(%w[foobar barfoo])
57+
expect(opts.minidump_path).to eq('linux/only')
58+
expect(opts.perf_logging_prefs[:enable_network]).to eq(true)
59+
expect(opts.window_types).to eq(%w[normal devtools])
6060
end
6161
end
6262

@@ -143,6 +143,15 @@ module Chrome
143143
end
144144

145145
describe '#as_json' do
146+
it 'returns empty options by default' do
147+
expect(options.as_json).to eq("goog:chromeOptions" => {})
148+
end
149+
150+
it 'returns added option' do
151+
options.add_option(:foo, 'bar')
152+
expect(options.as_json).to eq("goog:chromeOptions" => {"foo" => "bar"})
153+
end
154+
146155
it 'returns a JSON hash' do
147156
allow(File).to receive(:file?).and_return(true)
148157
allow_any_instance_of(Options).to receive(:encode_extension).with('foo.crx').and_return("encoded_foo")
@@ -163,20 +172,20 @@ module Chrome
163172
perf_logging_prefs: {'enable_network': true},
164173
window_types: %w[normal devtools])
165174

166-
json = opts.as_json['goog:chromeOptions']
167-
expect(json).to eq('args' => %w[foo bar],
168-
'prefs' => {'foo' => 'bar'},
169-
'binary' => '/foo/bar',
170-
'extensions' => %w[encoded_foo encoded_bar encoded_foobar],
171-
'foo' => 'bar',
172-
'mobileEmulation' => {'deviceName' => 'mine'},
173-
'localState' => {'foo' => 'bar'},
174-
'detach' => true,
175-
'debuggerAddress' => '127.0.0.1:8181',
176-
'excludeSwitches' => %w[foobar barfoo],
177-
'minidumpPath' => 'linux/only',
178-
'perfLoggingPrefs' => {'enableNetwork' => true},
179-
'windowTypes' => %w[normal devtools])
175+
key = 'goog:chromeOptions'
176+
expect(opts.as_json).to eq(key => {'args' => %w[foo bar],
177+
'prefs' => {'foo' => 'bar'},
178+
'binary' => '/foo/bar',
179+
'extensions' => %w[encoded_foo encoded_bar encoded_foobar],
180+
'foo' => 'bar',
181+
'mobileEmulation' => {'deviceName' => 'mine'},
182+
'localState' => {'foo' => 'bar'},
183+
'detach' => true,
184+
'debuggerAddress' => '127.0.0.1:8181',
185+
'excludeSwitches' => %w[foobar barfoo],
186+
'minidumpPath' => 'linux/only',
187+
'perfLoggingPrefs' => {'enableNetwork' => true},
188+
'windowTypes' => %w[normal devtools]})
180189
end
181190
end
182191
end # Options

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
module Selenium
2323
module WebDriver
2424
describe Service do
25-
let(:service_path) { "/path/to/#{Chrome::Service::EXECUTABLE}" }
25+
describe '#new' do
26+
let(:service_path) { "/path/to/#{Chrome::Service::EXECUTABLE}" }
2627

27-
before do
28-
allow(Platform).to receive(:assert_executable).and_return(true)
29-
end
28+
before do
29+
allow(Platform).to receive(:assert_executable).and_return(true)
30+
end
3031

31-
describe '#new' do
3232
it 'uses default path and port' do
3333
allow(Platform).to receive(:find_binary).and_return(service_path)
3434

@@ -110,27 +110,24 @@ module WebDriver
110110
expect(service.instance_variable_get('@extra_args')).to eq ['--log-path=/path/to/log', '--verbose']
111111
end
112112
end
113-
end
114113

115-
module Chrome
116-
describe Driver do
114+
context 'when initializing driver' do
115+
let(:driver) { Chrome::Driver }
117116
let(:service) { instance_double(Service, start: true, uri: 'http://example.com') }
118117
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
119118

120-
before do
121-
allow(Remote::Bridge).to receive(:new).and_return(bridge)
122-
end
119+
before { allow(Remote::Bridge).to receive(:new).and_return(bridge) }
123120

124121
it 'is not created when :url is provided' do
125122
expect(Service).not_to receive(:new)
126123

127-
described_class.new(url: 'http://example.com:4321')
124+
driver.new(url: 'http://example.com:4321')
128125
end
129126

130127
it 'is created when :url is not provided' do
131128
expect(Service).to receive(:new).and_return(service)
132129

133-
described_class.new
130+
driver.new
134131
end
135132

136133
it 'accepts :driver_path but throws deprecation notice' do
@@ -141,7 +138,7 @@ module Chrome
141138
args: nil).and_return(service)
142139

143140
expect {
144-
described_class.new(driver_path: driver_path)
141+
driver.new(driver_path: driver_path)
145142
}.to output(/WARN Selenium \[DEPRECATION\] :driver_path/).to_stdout_from_any_process
146143
end
147144

@@ -153,7 +150,7 @@ module Chrome
153150
args: nil).and_return(service)
154151

155152
expect {
156-
described_class.new(port: driver_port)
153+
driver.new(port: driver_port)
157154
}.to output(/WARN Selenium \[DEPRECATION\] :port/).to_stdout_from_any_process
158155
end
159156

@@ -166,14 +163,14 @@ module Chrome
166163
args: driver_opts).and_return(service)
167164

168165
expect {
169-
described_class.new(driver_opts: driver_opts)
166+
driver.new(driver_opts: driver_opts)
170167
}.to output(/WARN Selenium \[DEPRECATION\] :driver_opts/).to_stdout_from_any_process
171168
end
172169

173170
it 'accepts :service without creating a new instance' do
174171
expect(Service).not_to receive(:new)
175172

176-
described_class.new(service: service)
173+
driver.new(service: service)
177174
end
178175
end
179176
end

rb/spec/unit/selenium/webdriver/common/interactions/input_device_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ module Selenium
2323
module WebDriver
2424
module Interactions
2525
describe InputDevice do
26-
subject(:input) { described_class.new }
26+
let(:device) do
27+
Class.new(InputDevice) {
28+
def type
29+
:none
30+
end
31+
}.new
32+
end
2733

28-
let(:device) { described_class.new }
29-
let(:action) { instance_double(Pause) }
34+
let(:action) { Pause.new(device) }
3035

3136
it 'should provide access to name' do
32-
expect(input).to respond_to(:name)
37+
expect(device).to respond_to(:name)
3338
end
3439

3540
it 'should provide access to actions' do
36-
expect(input).to respond_to(:actions)
41+
expect(device).to respond_to(:actions)
3742
end
3843

3944
it 'should assign a random UUID if no name is provided' do
@@ -48,8 +53,6 @@ module Interactions
4853
end
4954

5055
it 'should add action to actions array' do
51-
allow(action).to receive(:class).and_return(KeyInput::TypingInteraction)
52-
5356
expect { device.add_action(action) }.to change(device, :actions).from([]).to([action])
5457
end
5558
end # when adding an action
@@ -62,10 +65,9 @@ module Interactions
6265

6366
context 'when creating a pause' do
6467
it 'should create a pause action' do
65-
expect(Pause).to receive(:new).with(device, 5).and_return(:pause)
66-
allow(device).to receive(:add_action)
68+
expect(Pause).to receive(:new).with(device, 5).and_return(action)
6769

68-
device.create_pause(5)
70+
expect { device.create_pause(5) }.to change(device, :actions).from([]).to([action])
6971
end
7072

7173
it 'should add a pause action' do

rb/spec/unit/selenium/webdriver/common/service_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module WebDriver
3333
describe '#new' do
3434
it 'uses default path and port' do
3535
expect(Platform).to receive(:find_binary).and_return(service_path)
36-
expect(described_class).to receive(:driver_path)
36+
expect(Service).to receive(:driver_path)
3737

3838
service = Service.new
3939
expect(service.executable_path).to eq service_path
@@ -52,15 +52,15 @@ module WebDriver
5252

5353
it 'does not create args by default' do
5454
expect(Platform).to receive(:find_binary).and_return(service_path)
55-
expect(described_class).to receive(:driver_path)
55+
expect(Service).to receive(:driver_path)
5656

5757
service = Service.new
5858
expect(service.instance_variable_get('@extra_args')).to be_empty
5959
end
6060

6161
it 'uses provided args' do
6262
expect(Platform).to receive(:find_binary).and_return(service_path)
63-
expect(described_class).to receive(:driver_path)
63+
expect(Service).to receive(:driver_path)
6464

6565
service = Service.new(args: ['--foo', '--bar'])
6666
expect(service.instance_variable_get('@extra_args')).to eq ['--foo', '--bar']

rb/spec/unit/selenium/webdriver/edge/options_spec.rb

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ module Selenium
2323
module WebDriver
2424
module EdgeHtml
2525
describe Options do
26-
subject(:options) { described_class.new }
26+
subject(:options) { Options.new }
2727

2828
describe '#initialize' do
2929
it 'accepts defined parameters' do
3030
allow(File).to receive(:directory?).and_return(true)
3131

32-
options = Options.new(in_private: true,
33-
extension_paths: ['/path1', '/path2'],
34-
start_page: 'http://selenium.dev')
32+
opts = Options.new(in_private: true,
33+
extension_paths: ['/path1', '/path2'],
34+
start_page: 'http://selenium.dev')
3535

36-
expect(options.in_private).to eq(true)
37-
expect(options.extension_paths).to eq(['/path1', '/path2'])
38-
expect(options.start_page).to eq('http://selenium.dev')
36+
expect(opts.in_private).to eq(true)
37+
expect(opts.extension_paths).to eq(['/path1', '/path2'])
38+
expect(opts.start_page).to eq('http://selenium.dev')
3939
end
4040
end
4141

@@ -51,17 +51,25 @@ module EdgeHtml
5151
end
5252

5353
describe '#as_json' do
54+
it 'returns empty options by default' do
55+
expect(options.as_json).to be_empty
56+
end
57+
58+
it 'returns added option' do
59+
options.add_option(:foo, 'bar')
60+
expect(options.as_json).to eq("foo" => "bar")
61+
end
62+
5463
it 'returns JSON hash' do
5564
allow(File).to receive(:directory?).and_return(true)
5665

57-
options = Options.new(in_private: true,
58-
extension_paths: ['/path1', '/path2'],
59-
start_page: 'http://selenium.dev')
66+
opts = Options.new(in_private: true,
67+
extension_paths: ['/path1', '/path2'],
68+
start_page: 'http://selenium.dev')
6069

61-
json = options.as_json
62-
expect(json).to eq('ms:inPrivate' => true,
63-
'ms:extensionPaths' => ['/path1', '/path2'],
64-
'ms:startPage' => 'http://selenium.dev')
70+
expect(opts.as_json).to eq('ms:inPrivate' => true,
71+
'ms:extensionPaths' => ['/path1', '/path2'],
72+
'ms:startPage' => 'http://selenium.dev')
6573
end
6674
end
6775
end # Options

0 commit comments

Comments
 (0)