Skip to content

Commit

Permalink
[rb] update specs for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 28, 2019
1 parent 62e867b commit 01701f6
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 316 deletions.
2 changes: 1 addition & 1 deletion rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@ RSpec/InstanceVariable:
- 'spec/unit/selenium/webdriver/socket_poller_spec.rb'

RSpec/DescribedClass:
Enabled: false
EnforcedStyle: explicit
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Selenium
module WebDriver
module Chrome
describe Options, only: {browser: :chrome} do
subject(:options) { described_class.new }
subject(:options) { Options.new }

it 'passes emulated device correctly' do
options.add_emulation(device_name: 'Nexus 5')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Selenium
module WebDriver
module EdgeChrome
describe Options, only: {browser: :edge_chrome} do
subject(:options) { described_class.new }
subject(:options) { Options.new }

it 'passes emulated device correctly' do
options.add_emulation(device_name: 'Nexus 5')
Expand Down
95 changes: 52 additions & 43 deletions rb/spec/unit/selenium/webdriver/chrome/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,40 @@ module Selenium
module WebDriver
module Chrome
describe Options do
subject(:options) { described_class.new }
subject(:options) { Options.new }

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

opt = Options.new(args: %w[foo bar],
prefs: {foo: 'bar'},
binary: '/foo/bar',
extensions: ['foo.crx', 'bar.crx'],
encoded_extensions: ['encoded_foobar'],
foo: 'bar',
emulation: {device_name: :bar},
local_state: {foo: 'bar'},
detach: true,
debugger_address: '127.0.0.1:8181',
exclude_switches: %w[foobar barfoo],
minidump_path: 'linux/only',
perf_logging_prefs: {enable_network: true},
window_types: %w[normal devtools])

expect(opt.args.to_a).to eq(%w[foo bar])
expect(opt.prefs[:foo]).to eq('bar')
expect(opt.binary).to eq('/foo/bar')
expect(opt.extensions).to eq(['foo.crx', 'bar.crx'])
expect(opt.instance_variable_get('@options')[:foo]).to eq('bar')
expect(opt.emulation[:device_name]).to eq(:bar)
expect(opt.local_state[:foo]).to eq('bar')
expect(opt.detach).to eq(true)
expect(opt.debugger_address).to eq('127.0.0.1:8181')
expect(opt.exclude_switches).to eq(%w[foobar barfoo])
expect(opt.minidump_path).to eq('linux/only')
expect(opt.perf_logging_prefs[:enable_network]).to eq(true)
expect(opt.window_types).to eq(%w[normal devtools])
opts = Options.new(args: %w[foo bar],
prefs: {foo: 'bar'},
binary: '/foo/bar',
extensions: ['foo.crx', 'bar.crx'],
encoded_extensions: ['encoded_foobar'],
foo: 'bar',
emulation: {device_name: :bar},
local_state: {foo: 'bar'},
detach: true,
debugger_address: '127.0.0.1:8181',
exclude_switches: %w[foobar barfoo],
minidump_path: 'linux/only',
perf_logging_prefs: {enable_network: true},
window_types: %w[normal devtools])

expect(opts.args.to_a).to eq(%w[foo bar])
expect(opts.prefs[:foo]).to eq('bar')
expect(opts.binary).to eq('/foo/bar')
expect(opts.extensions).to eq(['foo.crx', 'bar.crx'])
expect(opts.instance_variable_get('@options')[:foo]).to eq('bar')
expect(opts.emulation[:device_name]).to eq(:bar)
expect(opts.local_state[:foo]).to eq('bar')
expect(opts.detach).to eq(true)
expect(opts.debugger_address).to eq('127.0.0.1:8181')
expect(opts.exclude_switches).to eq(%w[foobar barfoo])
expect(opts.minidump_path).to eq('linux/only')
expect(opts.perf_logging_prefs[:enable_network]).to eq(true)
expect(opts.window_types).to eq(%w[normal devtools])
end
end

Expand Down Expand Up @@ -143,6 +143,15 @@ module Chrome
end

describe '#as_json' do
it 'returns empty options by default' do
expect(options.as_json).to eq("goog:chromeOptions" => {})
end

it 'returns added option' do
options.add_option(:foo, 'bar')
expect(options.as_json).to eq("goog:chromeOptions" => {"foo" => "bar"})
end

it 'returns a JSON hash' do
allow(File).to receive(:file?).and_return(true)
allow_any_instance_of(Options).to receive(:encode_extension).with('foo.crx').and_return("encoded_foo")
Expand All @@ -163,20 +172,20 @@ module Chrome
perf_logging_prefs: {'enable_network': true},
window_types: %w[normal devtools])

json = opts.as_json['goog:chromeOptions']
expect(json).to eq('args' => %w[foo bar],
'prefs' => {'foo' => 'bar'},
'binary' => '/foo/bar',
'extensions' => %w[encoded_foo encoded_bar encoded_foobar],
'foo' => 'bar',
'mobileEmulation' => {'deviceName' => 'mine'},
'localState' => {'foo' => 'bar'},
'detach' => true,
'debuggerAddress' => '127.0.0.1:8181',
'excludeSwitches' => %w[foobar barfoo],
'minidumpPath' => 'linux/only',
'perfLoggingPrefs' => {'enableNetwork' => true},
'windowTypes' => %w[normal devtools])
key = 'goog:chromeOptions'
expect(opts.as_json).to eq(key => {'args' => %w[foo bar],
'prefs' => {'foo' => 'bar'},
'binary' => '/foo/bar',
'extensions' => %w[encoded_foo encoded_bar encoded_foobar],
'foo' => 'bar',
'mobileEmulation' => {'deviceName' => 'mine'},
'localState' => {'foo' => 'bar'},
'detach' => true,
'debuggerAddress' => '127.0.0.1:8181',
'excludeSwitches' => %w[foobar barfoo],
'minidumpPath' => 'linux/only',
'perfLoggingPrefs' => {'enableNetwork' => true},
'windowTypes' => %w[normal devtools]})
end
end
end # Options
Expand Down
31 changes: 14 additions & 17 deletions rb/spec/unit/selenium/webdriver/chrome/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
module Selenium
module WebDriver
describe Service do
let(:service_path) { "/path/to/#{Chrome::Service::EXECUTABLE}" }
describe '#new' do
let(:service_path) { "/path/to/#{Chrome::Service::EXECUTABLE}" }

before do
allow(Platform).to receive(:assert_executable).and_return(true)
end
before do
allow(Platform).to receive(:assert_executable).and_return(true)
end

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

Expand Down Expand Up @@ -110,27 +110,24 @@ module WebDriver
expect(service.instance_variable_get('@extra_args')).to eq ['--log-path=/path/to/log', '--verbose']
end
end
end

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

before do
allow(Remote::Bridge).to receive(:new).and_return(bridge)
end
before { allow(Remote::Bridge).to receive(:new).and_return(bridge) }

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

described_class.new(url: 'http://example.com:4321')
driver.new(url: 'http://example.com:4321')
end

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

described_class.new
driver.new
end

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

expect {
described_class.new(driver_path: driver_path)
driver.new(driver_path: driver_path)
}.to output(/WARN Selenium \[DEPRECATION\] :driver_path/).to_stdout_from_any_process
end

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

expect {
described_class.new(port: driver_port)
driver.new(port: driver_port)
}.to output(/WARN Selenium \[DEPRECATION\] :port/).to_stdout_from_any_process
end

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

expect {
described_class.new(driver_opts: driver_opts)
driver.new(driver_opts: driver_opts)
}.to output(/WARN Selenium \[DEPRECATION\] :driver_opts/).to_stdout_from_any_process
end

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

described_class.new(service: service)
driver.new(service: service)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ module Selenium
module WebDriver
module Interactions
describe InputDevice do
subject(:input) { described_class.new }
let(:device) do
Class.new(InputDevice) {
def type
:none
end
}.new
end

let(:device) { described_class.new }
let(:action) { instance_double(Pause) }
let(:action) { Pause.new(device) }

it 'should provide access to name' do
expect(input).to respond_to(:name)
expect(device).to respond_to(:name)
end

it 'should provide access to actions' do
expect(input).to respond_to(:actions)
expect(device).to respond_to(:actions)
end

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

it 'should add action to actions array' do
allow(action).to receive(:class).and_return(KeyInput::TypingInteraction)

expect { device.add_action(action) }.to change(device, :actions).from([]).to([action])
end
end # when adding an action
Expand All @@ -62,10 +65,9 @@ module Interactions

context 'when creating a pause' do
it 'should create a pause action' do
expect(Pause).to receive(:new).with(device, 5).and_return(:pause)
allow(device).to receive(:add_action)
expect(Pause).to receive(:new).with(device, 5).and_return(action)

device.create_pause(5)
expect { device.create_pause(5) }.to change(device, :actions).from([]).to([action])
end

it 'should add a pause action' do
Expand Down
6 changes: 3 additions & 3 deletions rb/spec/unit/selenium/webdriver/common/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module WebDriver
describe '#new' do
it 'uses default path and port' do
expect(Platform).to receive(:find_binary).and_return(service_path)
expect(described_class).to receive(:driver_path)
expect(Service).to receive(:driver_path)

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

it 'does not create args by default' do
expect(Platform).to receive(:find_binary).and_return(service_path)
expect(described_class).to receive(:driver_path)
expect(Service).to receive(:driver_path)

service = Service.new
expect(service.instance_variable_get('@extra_args')).to be_empty
end

it 'uses provided args' do
expect(Platform).to receive(:find_binary).and_return(service_path)
expect(described_class).to receive(:driver_path)
expect(Service).to receive(:driver_path)

service = Service.new(args: ['--foo', '--bar'])
expect(service.instance_variable_get('@extra_args')).to eq ['--foo', '--bar']
Expand Down
36 changes: 22 additions & 14 deletions rb/spec/unit/selenium/webdriver/edge/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ module Selenium
module WebDriver
module EdgeHtml
describe Options do
subject(:options) { described_class.new }
subject(:options) { Options.new }

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

options = Options.new(in_private: true,
extension_paths: ['/path1', '/path2'],
start_page: 'http://selenium.dev')
opts = Options.new(in_private: true,
extension_paths: ['/path1', '/path2'],
start_page: 'http://selenium.dev')

expect(options.in_private).to eq(true)
expect(options.extension_paths).to eq(['/path1', '/path2'])
expect(options.start_page).to eq('http://selenium.dev')
expect(opts.in_private).to eq(true)
expect(opts.extension_paths).to eq(['/path1', '/path2'])
expect(opts.start_page).to eq('http://selenium.dev')
end
end

Expand All @@ -51,17 +51,25 @@ module EdgeHtml
end

describe '#as_json' do
it 'returns empty options by default' do
expect(options.as_json).to be_empty
end

it 'returns added option' do
options.add_option(:foo, 'bar')
expect(options.as_json).to eq("foo" => "bar")
end

it 'returns JSON hash' do
allow(File).to receive(:directory?).and_return(true)

options = Options.new(in_private: true,
extension_paths: ['/path1', '/path2'],
start_page: 'http://selenium.dev')
opts = Options.new(in_private: true,
extension_paths: ['/path1', '/path2'],
start_page: 'http://selenium.dev')

json = options.as_json
expect(json).to eq('ms:inPrivate' => true,
'ms:extensionPaths' => ['/path1', '/path2'],
'ms:startPage' => 'http://selenium.dev')
expect(opts.as_json).to eq('ms:inPrivate' => true,
'ms:extensionPaths' => ['/path1', '/path2'],
'ms:startPage' => 'http://selenium.dev')
end
end
end # Options
Expand Down
Loading

0 comments on commit 01701f6

Please sign in to comment.