diff --git a/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb index 85e1bdad3ab44..b912f05b188c4 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb @@ -21,116 +21,118 @@ module Selenium module WebDriver - describe Service do - describe '#new' do - let(:service_path) { "/path/to/#{Chrome::Service::EXECUTABLE}" } + module Chrome + describe Service do + describe '#new' do + let(:service_path) { "/path/to/#{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 - after { Chrome::Service.driver_path = nil } + after { Service.driver_path = nil } - it 'uses default path and port' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses default path and port' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.chrome + service = Service.chrome - expect(service.executable_path).to include Chrome::Service::EXECUTABLE - expected_port = Chrome::Service::DEFAULT_PORT - expect(service.port).to eq expected_port - expect(service.host).to eq Platform.localhost - end + expect(service.executable_path).to include Service::EXECUTABLE + expected_port = Service::DEFAULT_PORT + expect(service.port).to eq expected_port + expect(service.host).to eq Platform.localhost + end - it 'uses provided path and port' do - path = 'foo' - port = 5678 + it 'uses provided path and port' do + path = 'foo' + port = 5678 - service = Service.chrome(path: path, port: port) + service = Service.chrome(path: path, port: port) - expect(service.executable_path).to eq path - expect(service.port).to eq port - expect(service.host).to eq Platform.localhost - end + expect(service.executable_path).to eq path + expect(service.port).to eq port + expect(service.host).to eq Platform.localhost + end - it 'allows #driver_path= with String value' do - path = '/path/to/driver' - Chrome::Service.driver_path = path + it 'allows #driver_path= with String value' do + path = '/path/to/driver' + Service.driver_path = path - service = Service.chrome + service = Service.chrome - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'allows #driver_path= with Proc value' do - path = '/path/to/driver' - proc = proc { path } - Chrome::Service.driver_path = proc + it 'allows #driver_path= with Proc value' do + path = '/path/to/driver' + proc = proc { path } + Service.driver_path = proc - service = Service.chrome + service = Service.chrome - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'does not create args by default' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'does not create args by default' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.chrome + service = Service.new - expect(service.extra_args).to be_empty - end + expect(service.extra_args).to be_empty + end - it 'uses provided args' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses provided args' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.chrome(args: ['--foo', '--bar']) + service = Service.chrome(args: ['--foo', '--bar']) - expect(service.extra_args).to eq ['--foo', '--bar'] - end + expect(service.extra_args).to eq ['--foo', '--bar'] + end - it 'uses args when passed in as a Hash' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses args when passed in as a Hash' do + allow(Platform).to receive(:find_binary).and_return(service_path) - expect { - service = Service.chrome(args: {log_path: '/path/to/log', - verbose: true}) + expect { + service = Service.new(args: {log_path: '/path/to/log', + verbose: true}) - expect(service.extra_args).to eq ['--log-path=/path/to/log', '--verbose'] - }.to have_deprecated(:driver_opts) + expect(service.extra_args).to eq ['--log-path=/path/to/log', '--verbose'] + }.to have_deprecated(:driver_opts) + end end - end - context 'when initializing driver' do - let(:driver) { Chrome::Driver } - let(:service) { instance_double(Service, launch: service_manager) } - let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') } - let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) } + context 'when initializing driver' do + let(:driver) { Chrome::Driver } + let(:service) { instance_double(Service, launch: service_manager) } + let(:service_manager) { instance_double(ServiceManager, 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) - allow(bridge).to receive(:browser).and_return(:chrome) - end + before do + allow(Remote::Bridge).to receive(:new).and_return(bridge) + allow(bridge).to receive(:browser).and_return(:chrome) + end - it 'is not created when :url is provided' do - expect(Service).not_to receive(:new) + it 'is not created when :url is provided' do + expect(Service).not_to receive(:new) - driver.new(url: 'http://example.com:4321') - end + driver.new(url: 'http://example.com:4321') + end - it 'is created when :url is not provided' do - allow(Service).to receive(:new).and_return(service) + it 'is created when :url is not provided' do + allow(Service).to receive(:new).and_return(service) - driver.new - expect(Service).to have_received(:new).with(no_args) - end + driver.new + expect(Service).to have_received(:new).with(no_args) + end - it 'accepts :service without creating a new instance' do - allow(Service).to receive(:new) + it 'accepts :service without creating a new instance' do + allow(Service).to receive(:new) - driver.new(service: service) - expect(Service).not_to have_received(:new) + driver.new(service: service) + expect(Service).not_to have_received(:new) + end end end - end + end # Chrome end # WebDriver end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/common/service_spec.rb b/rb/spec/unit/selenium/webdriver/common/service_spec.rb index 88ca0c1947572..ed2a29621ec66 100644 --- a/rb/spec/unit/selenium/webdriver/common/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/common/service_spec.rb @@ -30,6 +30,42 @@ module WebDriver stub_const('Selenium::WebDriver::Service::EXECUTABLE', 'service') end + describe 'browser shortcuts' do + before { allow(Platform).to receive(:find_binary).and_return(service_path) } + + let(:args) { %w[--foo --bar] } + + it 'creates Chrome instance' do + service = Service.chrome(args: args) + expect(service).to be_a(Chrome::Service) + expect(service.args).to eq args + end + + it 'creates Edge instance' do + service = Service.edge(args: args) + expect(service).to be_a(Edge::Service) + expect(service.args).to eq args + end + + it 'creates Firefox instance' do + service = Service.firefox(args: args) + expect(service).to be_a(Firefox::Service) + expect(service.args).to eq args + end + + it 'creates IE instance' do + service = Service.internet_explorer(args: args) + expect(service).to be_a(IE::Service) + expect(service.args).to eq args + end + + it 'creates Safari instance' do + service = Service.safari(args: args) + expect(service).to be_a(Safari::Service) + expect(service.args).to eq args + end + end + describe '#new' do it 'uses default path and port' do allow(Platform).to receive(:find_binary).and_return(service_path) diff --git a/rb/spec/unit/selenium/webdriver/edge/service_spec.rb b/rb/spec/unit/selenium/webdriver/edge/service_spec.rb index afce4f867d7e4..5aee10d0efb14 100644 --- a/rb/spec/unit/selenium/webdriver/edge/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/edge/service_spec.rb @@ -21,120 +21,122 @@ module Selenium module WebDriver - describe Service do - describe '#new' do - let(:service_path) { "/path/to/#{Edge::Service::EXECUTABLE}" } - - before do - allow(Platform).to receive(:assert_executable).and_return(true) - Edge::Service.driver_path = nil - end + module Edge + describe Service do + describe '#new' do + let(:service_path) { "/path/to/#{Service::EXECUTABLE}" } + + before do + allow(Platform).to receive(:assert_executable).and_return(true) + Service.driver_path = nil + end - it 'uses default path and port' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses default path and port' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.edge + service = Service.new - expect(service.executable_path).to include Edge::Service::EXECUTABLE - expected_port = Edge::Service::DEFAULT_PORT - expect(service.port).to eq expected_port - expect(service.host).to eq Platform.localhost - end + expect(service.executable_path).to include Service::EXECUTABLE + expected_port = Service::DEFAULT_PORT + expect(service.port).to eq expected_port + expect(service.host).to eq Platform.localhost + end - it 'uses provided path and port' do - path = 'foo' - port = 5678 + it 'uses provided path and port' do + path = 'foo' + port = 5678 - service = Service.edge(path: path, port: port) + service = Service.new(path: path, port: port) - expect(service.executable_path).to eq path - expect(service.port).to eq port - expect(service.host).to eq Platform.localhost - end + expect(service.executable_path).to eq path + expect(service.port).to eq port + expect(service.host).to eq Platform.localhost + end - describe "#driver_path=" do - after { Edge::Service.driver_path = nil } + describe "#driver_path=" do + after { Service.driver_path = nil } - it 'allows #driver_path= with String value' do - path = '/path/to/driver' - Edge::Service.driver_path = path + it 'allows #driver_path= with String value' do + path = '/path/to/driver' + Service.driver_path = path - service = Service.edge + service = Service.new - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'allows #driver_path= with Proc value' do - path = '/path/to/driver' - proc = proc { path } - Edge::Service.driver_path = proc + it 'allows #driver_path= with Proc value' do + path = '/path/to/driver' + proc = proc { path } + Service.driver_path = proc - service = Service.edge + service = Service.new - expect(service.executable_path).to eq path + expect(service.executable_path).to eq path + end end - end - it 'does not create args by default' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'does not create args by default' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.edge + service = Service.new - expect(service.extra_args).to be_empty - end + expect(service.extra_args).to be_empty + end - it 'uses provided args' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses provided args' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.edge(args: ['--foo', '--bar']) + service = Service.new(args: ['--foo', '--bar']) - expect(service.extra_args).to eq ['--foo', '--bar'] - end + expect(service.extra_args).to eq ['--foo', '--bar'] + end - # This is deprecated behavior - it 'uses args when passed in as a Hash' do - allow(Platform).to receive(:find_binary).and_return(service_path) + # This is deprecated behavior + it 'uses args when passed in as a Hash' do + allow(Platform).to receive(:find_binary).and_return(service_path) - expect { - service = Service.edge(args: {log_path: '/path/to/log', - verbose: true}) + expect { + service = Service.new(args: {log_path: '/path/to/log', + verbose: true}) - expect(service.extra_args).to eq ['--log-path=/path/to/log', '--verbose'] - }.to have_deprecated(:driver_opts) + expect(service.extra_args).to eq ['--log-path=/path/to/log', '--verbose'] + }.to have_deprecated(:driver_opts) + end end - end - context 'when initializing driver' do - let(:driver) { Edge::Driver } - let(:service) { instance_double(Service, launch: service_manager) } - let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') } - let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) } + context 'when initializing driver' do + let(:driver) { Edge::Driver } + let(:service) { instance_double(Service, launch: service_manager) } + let(:service_manager) { instance_double(ServiceManager, 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) - allow(bridge).to receive(:browser).and_return(:msedge) - end + before do + allow(Remote::Bridge).to receive(:new).and_return(bridge) + allow(bridge).to receive(:browser).and_return(:msedge) + end - it 'is not created when :url is provided' do - expect(Service).not_to receive(:new) + it 'is not created when :url is provided' do + expect(Service).not_to receive(:new) - driver.new(url: 'http://example.com:4321') - end + driver.new(url: 'http://example.com:4321') + end - it 'is created when :url is not provided' do - allow(Service).to receive(:new).and_return(service) + it 'is created when :url is not provided' do + allow(Service).to receive(:new).and_return(service) - driver.new - expect(Service).to have_received(:new).with(no_args) - end + driver.new + expect(Service).to have_received(:new).with(no_args) + end - it 'accepts :service without creating a new instance' do - allow(Service).to receive(:new) + it 'accepts :service without creating a new instance' do + allow(Service).to receive(:new) - driver.new(service: service) - expect(Service).not_to have_received(:new) + driver.new(service: service) + expect(Service).not_to have_received(:new) + end end end - end + end # Edge end # WebDriver end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/firefox/service_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/service_spec.rb index cf33ad76203f9..ddb3b34a17dde 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/service_spec.rb @@ -21,111 +21,113 @@ module Selenium module WebDriver - describe Service do - describe '#new' do - let(:service_path) { "/path/to/#{Firefox::Service::EXECUTABLE}" } + module Firefox + describe Service do + describe '#new' do + let(:service_path) { "/path/to/#{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 - it 'uses default path and port' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses default path and port' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.firefox + service = Service.new - expect(service.executable_path).to include Firefox::Service::EXECUTABLE - expected_port = Firefox::Service::DEFAULT_PORT - expect(service.port).to eq expected_port - end + expect(service.executable_path).to include Service::EXECUTABLE + expected_port = Service::DEFAULT_PORT + expect(service.port).to eq expected_port + end - it 'uses provided path and port' do - path = 'foo' - port = 5678 + it 'uses provided path and port' do + path = 'foo' + port = 5678 - service = Service.firefox(path: path, port: port) + service = Service.new(path: path, port: port) - expect(service.executable_path).to eq path - expect(service.port).to eq port - end + expect(service.executable_path).to eq path + expect(service.port).to eq port + end - it 'allows #driver_path= with String value' do - path = '/path/to/driver' - Firefox::Service.driver_path = path + it 'allows #driver_path= with String value' do + path = '/path/to/driver' + Service.driver_path = path - service = Service.firefox + service = Service.new - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'allows #driver_path= with Proc value' do - path = '/path/to/driver' - proc = proc { path } - Firefox::Service.driver_path = proc + it 'allows #driver_path= with Proc value' do + path = '/path/to/driver' + proc = proc { path } + Service.driver_path = proc - service = Service.firefox + service = Service.new - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'does not create args by default' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'does not create args by default' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.firefox + service = Service.new - expect(service.extra_args).to be_empty - end + expect(service.extra_args).to be_empty + end - it 'uses provided args' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses provided args' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.firefox(args: ['--foo', '--bar']) + service = Service.new(args: ['--foo', '--bar']) - expect(service.extra_args).to eq ['--foo', '--bar'] - end + expect(service.extra_args).to eq ['--foo', '--bar'] + end - it 'uses args when passed in as a Hash' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses args when passed in as a Hash' do + allow(Platform).to receive(:find_binary).and_return(service_path) - expect { - service = Service.firefox(args: {log: '/path/to/log', - marionette_port: 4}) + expect { + service = Service.new(args: {log: '/path/to/log', + marionette_port: 4}) - expect(service.extra_args).to eq ['--log=/path/to/log', '--marionette-port=4'] - }.to have_deprecated(:driver_opts) + expect(service.extra_args).to eq ['--log=/path/to/log', '--marionette-port=4'] + }.to have_deprecated(:driver_opts) + end end - end - context 'when initializing driver' do - let(:driver) { Firefox::Driver } - let(:service) { instance_double(Service, launch: service_manager) } - let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') } - let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) } + context 'when initializing driver' do + let(:driver) { Firefox::Driver } + let(:service) { instance_double(Service, launch: service_manager) } + let(:service_manager) { instance_double(ServiceManager, 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) - allow(bridge).to receive(:browser).and_return(:firefox) - end + before do + allow(Remote::Bridge).to receive(:new).and_return(bridge) + allow(bridge).to receive(:browser).and_return(:firefox) + end - it 'is not created when :url is provided' do - expect(Service).not_to receive(:new) + it 'is not created when :url is provided' do + expect(Service).not_to receive(:new) - driver.new(url: 'http://example.com:4321') - end + driver.new(url: 'http://example.com:4321') + end - it 'is created when :url is not provided' do - allow(Service).to receive(:new).and_return(service) + it 'is created when :url is not provided' do + allow(Service).to receive(:new).and_return(service) - driver.new - expect(Service).to have_received(:new).with(no_args) - end + driver.new + expect(Service).to have_received(:new).with(no_args) + end - it 'accepts :service without creating a new instance' do - expect(Service).not_to receive(:new) + it 'accepts :service without creating a new instance' do + expect(Service).not_to receive(:new) - driver.new(service: service) + driver.new(service: service) + end end end - end + end # Firefox end # WebDriver end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/ie/service_spec.rb b/rb/spec/unit/selenium/webdriver/ie/service_spec.rb index d237e4b1a9046..1b5318aca7507 100644 --- a/rb/spec/unit/selenium/webdriver/ie/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/ie/service_spec.rb @@ -21,115 +21,117 @@ module Selenium module WebDriver - describe Service do - describe '#new' do - let(:service_path) { "/path/to/#{IE::Service::EXECUTABLE}" } + module IE + describe Service do + describe '#new' do + let(:service_path) { "/path/to/#{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 - it 'uses default path and port' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses default path and port' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.ie + service = Service.new - expect(service.executable_path).to include IE::Service::EXECUTABLE - expected_port = IE::Service::DEFAULT_PORT - expect(service.port).to eq expected_port - end + expect(service.executable_path).to include Service::EXECUTABLE + expected_port = Service::DEFAULT_PORT + expect(service.port).to eq expected_port + end - it 'uses provided path and port' do - path = 'foo' - port = 5678 + it 'uses provided path and port' do + path = 'foo' + port = 5678 - service = Service.ie(path: path, port: port) + service = Service.new(path: path, port: port) - expect(service.executable_path).to eq path - expect(service.port).to eq port - expect(service.host).to eq Platform.localhost - end + expect(service.executable_path).to eq path + expect(service.port).to eq port + expect(service.host).to eq Platform.localhost + end - it 'allows #driver_path= with String value' do - path = '/path/to/driver' - IE::Service.driver_path = path + it 'allows #driver_path= with String value' do + path = '/path/to/driver' + Service.driver_path = path - service = Service.ie + service = Service.new - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'allows #driver_path= with Proc value' do - path = '/path/to/driver' - proc = proc { path } - IE::Service.driver_path = proc + it 'allows #driver_path= with Proc value' do + path = '/path/to/driver' + proc = proc { path } + Service.driver_path = proc - service = Service.ie + service = Service.new - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'does not create args by default' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'does not create args by default' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.ie + service = Service.new - expect(service.extra_args).to be_empty - end + expect(service.extra_args).to be_empty + end - it 'uses provided args' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses provided args' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.ie(args: ['--foo', '--bar']) + service = Service.new(args: ['--foo', '--bar']) - expect(service.extra_args).to eq ['--foo', '--bar'] - end + expect(service.extra_args).to eq ['--foo', '--bar'] + end - # This is deprecated behavior - it 'uses args when passed in as a Hash' do - allow(Platform).to receive(:find_binary).and_return(service_path) + # This is deprecated behavior + it 'uses args when passed in as a Hash' do + allow(Platform).to receive(:find_binary).and_return(service_path) - expect { - service = Service.ie(args: {log_file: '/path/to/log', - silent: true}) + expect { + service = Service.new(args: {log_file: '/path/to/log', + silent: true}) - expect(service.extra_args).to eq ['--log-file=/path/to/log', '--silent'] - }.to have_deprecated(:driver_opts) + expect(service.extra_args).to eq ['--log-file=/path/to/log', '--silent'] + }.to have_deprecated(:driver_opts) + end end - end - context 'when initializing driver' do - let(:driver) { IE::Driver } - let(:service) { instance_double(Service, launch: service_manager) } - let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') } - let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) } + context 'when initializing driver' do + let(:driver) { IE::Driver } + let(:service) { instance_double(Service, launch: service_manager) } + let(:service_manager) { instance_double(ServiceManager, 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) - allow(ServiceManager).to receive(:new).and_return(service_manager) - allow(bridge).to receive(:browser).and_return(:internet_explorer) - end + before do + allow(Remote::Bridge).to receive(:new).and_return(bridge) + allow(ServiceManager).to receive(:new).and_return(service_manager) + allow(bridge).to receive(:browser).and_return(:internet_explorer) + end - it 'is not created when :url is provided' do - expect(ServiceManager).not_to receive(:new) - expect(Service).not_to receive(:new) + it 'is not created when :url is provided' do + expect(ServiceManager).not_to receive(:new) + expect(Service).not_to receive(:new) - driver.new(url: 'http://example.com:4321') - end + driver.new(url: 'http://example.com:4321') + end - it 'is created when :url is not provided' do - allow(Service).to receive(:new).and_return(service) + it 'is created when :url is not provided' do + allow(Service).to receive(:new).and_return(service) - driver.new - expect(Service).to have_received(:new).with(no_args) - end + driver.new + expect(Service).to have_received(:new).with(no_args) + end - it 'accepts :service without creating a new instance' do - expect(Service).not_to receive(:new) + it 'accepts :service without creating a new instance' do + expect(Service).not_to receive(:new) - driver.new(service: service) + driver.new(service: service) + end end end - end + end # IE end # WebDriver end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/safari/service_spec.rb b/rb/spec/unit/selenium/webdriver/safari/service_spec.rb index 5631a42414449..647c60aafa234 100644 --- a/rb/spec/unit/selenium/webdriver/safari/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/safari/service_spec.rb @@ -21,104 +21,106 @@ module Selenium module WebDriver - describe Service do - describe '#new' do - let(:service_path) { "/path/to/#{Safari::Service::EXECUTABLE}" } + module Safari + describe Service do + describe '#new' do + let(:service_path) { "/path/to/#{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 - it 'uses default path and port' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses default path and port' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.safari + service = Service.new - expect(service.executable_path).to include Safari::Service::EXECUTABLE - expected_port = Safari::Service::DEFAULT_PORT - expect(service.port).to eq expected_port - expect(service.host).to eq Platform.localhost - end + expect(service.executable_path).to include Service::EXECUTABLE + expected_port = Service::DEFAULT_PORT + expect(service.port).to eq expected_port + expect(service.host).to eq Platform.localhost + end - it 'uses provided path and port' do - path = 'foo' - port = 5678 + it 'uses provided path and port' do + path = 'foo' + port = 5678 - service = Service.safari(path: path, port: port) + service = Service.new(path: path, port: port) - expect(service.executable_path).to eq path - expect(service.port).to eq port - expect(service.host).to eq Platform.localhost - end + expect(service.executable_path).to eq path + expect(service.port).to eq port + expect(service.host).to eq Platform.localhost + end - it 'allows #driver_path= with String value' do - path = '/path/to/driver' - Safari::Service.driver_path = path + it 'allows #driver_path= with String value' do + path = '/path/to/driver' + Service.driver_path = path - service = Service.safari + service = Service.new - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'allows #driver_path= with Proc value' do - path = '/path/to/driver' - proc = proc { path } - Safari::Service.driver_path = proc + it 'allows #driver_path= with Proc value' do + path = '/path/to/driver' + proc = proc { path } + Service.driver_path = proc - service = Service.safari + service = Service.new - expect(service.executable_path).to eq path - end + expect(service.executable_path).to eq path + end - it 'does not create args by default' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'does not create args by default' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.safari + service = Service.new - expect(service.extra_args).to be_empty - end + expect(service.extra_args).to be_empty + end - it 'uses provided args' do - allow(Platform).to receive(:find_binary).and_return(service_path) + it 'uses provided args' do + allow(Platform).to receive(:find_binary).and_return(service_path) - service = Service.safari(args: ['--foo', '--bar']) + service = Service.new(args: ['--foo', '--bar']) - expect(service.extra_args).to eq ['--foo', '--bar'] + expect(service.extra_args).to eq ['--foo', '--bar'] + end end - end - context 'when initializing driver' do - let(:driver) { Safari::Driver } - let(:service) { instance_double(Service, launch: service_manager) } - let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') } - let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) } + context 'when initializing driver' do + let(:driver) { Safari::Driver } + let(:service) { instance_double(Service, launch: service_manager) } + let(:service_manager) { instance_double(ServiceManager, 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) - allow(ServiceManager).to receive(:new).and_return(service_manager) - allow(bridge).to receive(:browser).and_return(:safari) - end + before do + allow(Remote::Bridge).to receive(:new).and_return(bridge) + allow(ServiceManager).to receive(:new).and_return(service_manager) + allow(bridge).to receive(:browser).and_return(:safari) + end - it 'is not created when :url is provided' do - expect(Service).not_to receive(:new) - expect(ServiceManager).not_to receive(:new) + it 'is not created when :url is provided' do + expect(Service).not_to receive(:new) + expect(ServiceManager).not_to receive(:new) - driver.new(url: 'http://example.com:4321') - end + driver.new(url: 'http://example.com:4321') + end - it 'is created when :url is not provided' do - allow(Service).to receive(:new).and_return(service) + it 'is created when :url is not provided' do + allow(Service).to receive(:new).and_return(service) - driver.new - expect(Service).to have_received(:new).with(no_args) - end + driver.new + expect(Service).to have_received(:new).with(no_args) + end - it 'accepts :service without creating a new instance' do - expect(Service).not_to receive(:new) + it 'accepts :service without creating a new instance' do + expect(Service).not_to receive(:new) - driver.new(service: service) + driver.new(service: service) + end end end - end + end # Safari end # WebDriver end # Selenium