Skip to content

Commit

Permalink
General rubocop_rspec driven cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Mar 6, 2019
1 parent 775417d commit 34522d1
Show file tree
Hide file tree
Showing 31 changed files with 217 additions and 174 deletions.
31 changes: 31 additions & 0 deletions rb/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.3

Expand Down Expand Up @@ -88,6 +91,9 @@ Metrics/LineLength:
- 'lib/selenium/webdriver/ie/service.rb'
- 'spec/unit/selenium/server_spec.rb'
- 'spec/integration/selenium/webdriver/timeout_spec.rb'
IgnoredPatterns:
- '\s+# rubocop'
- '^\s*#'

Metrics/ModuleLength:
Exclude:
Expand All @@ -102,6 +108,7 @@ Metrics/MethodLength:
Metrics/BlockLength:
Exclude:
- "**/*_spec.rb"
- 'selenium-webdriver.gemspec'

Metrics/ParameterLists:
Exclude:
Expand All @@ -116,9 +123,33 @@ Layout/EmptyLinesAroundClassBody:
Layout/EmptyLinesAroundModuleBody:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/Dir:
Exclude:
- 'selenium-webdriver.gemspec'

Style/RescueStandardError:
Enabled: false

RSpec/ExampleWording:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/DescribeClass:
Enabled: false

RSpec/ContextWording:
Enabled: false

RSpec/AnyInstance:
Enabled: false

RSpec/MessageSpies:
Enabled: false
1 change: 1 addition & 0 deletions rb/selenium-webdriver.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rack', ['~> 2.0']
s.add_development_dependency 'rspec', ['~> 3.0']
s.add_development_dependency 'rubocop', ['~> 0.64.0']
s.add_development_dependency 'rubocop-rspec'
s.add_development_dependency 'webmock', ['~> 3.5']
s.add_development_dependency 'yard', ['~> 0.9.11']
end
18 changes: 10 additions & 8 deletions rb/spec/integration/selenium/webdriver/chrome/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,39 @@ module Selenium
module WebDriver
module Chrome
describe Options, only: {driver: :chrome} do
subject(:options) { described_class.new }

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

create_driver!(options: subject) do |driver|
create_driver!(options: options) do |driver|
ua = driver.execute_script 'return window.navigator.userAgent'
expect(ua).to include('Nexus 5')
end
end

it 'passes emulated user agent correctly' do
subject.add_emulation(user_agent: 'foo;bar')
options.add_emulation(user_agent: 'foo;bar')

create_driver!(options: subject) do |driver|
create_driver!(options: options) do |driver|
ua = driver.execute_script 'return window.navigator.userAgent'
expect(ua).to eq('foo;bar')
end
end

it 'passes args correctly' do
subject.add_argument('--user-agent=foo;bar')
options.add_argument('--user-agent=foo;bar')

create_driver!(options: subject) do |driver|
create_driver!(options: options) do |driver|
ua = driver.execute_script 'return window.navigator.userAgent'
expect(ua).to eq('foo;bar')
end
end

it 'should be able to run in headless mode with #headless!' do
subject.headless!
options.headless!

create_driver!(options: subject) do |driver|
create_driver!(options: options) do |driver|
ua = driver.execute_script 'return window.navigator.userAgent'
expect(ua).to match(/HeadlessChrome/)
end
Expand Down
6 changes: 3 additions & 3 deletions rb/spec/integration/selenium/webdriver/chrome/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ module Chrome

create_driver!(profile: profile) do |driver|
driver.navigate.to url_for('xhtmlTest.html')
expect('verify manually - home button displayed')
expect('verify manually - make page red extension properly installed')
expect('verify manually - home button displayed') # rubocop:disable RSpec/ExpectActual,RSpec/VoidExpect
expect('verify manually - make page red extension properly installed') # rubocop:disable RSpec/ExpectActual,RSpec/VoidExpect
end
end

Expand All @@ -55,7 +55,7 @@ module Chrome

profile.add_extension(ext_path)

ext_file = double('file')
ext_file = instance_double('file')
expect(File).to receive(:open).with(ext_path, 'rb').and_yield ext_file
expect(ext_file).to receive(:read).and_return 'test'

Expand Down
13 changes: 7 additions & 6 deletions rb/spec/integration/selenium/webdriver/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ def save_screenshot_and_assert(path)
expect(driver.find_element(name: 'x').attribute('value')).to eq('name')
end

it 'should find by class name' do
it 'should find by class name' do # rubocop:disable RSpec/RepeatedExample
driver.navigate.to url_for('xhtmlTest.html')
expect(driver.find_element(class: 'header').text).to eq('XHTML Might Be The Future')
end

# TODO: Rewrite this test so it's not a duplicate of above or remove
it 'should find elements with a hash selector' do # rubocop:disable RSpec/RepeatedExample
driver.navigate.to url_for('xhtmlTest.html')
expect(driver.find_element(class: 'header').text).to eq('XHTML Might Be The Future')
end
Expand Down Expand Up @@ -149,11 +155,6 @@ def save_screenshot_and_assert(path)
expect(child.attribute('id')).to eq('2')
end

it 'should find elements with a hash selector' do
driver.navigate.to url_for('xhtmlTest.html')
expect(driver.find_element(class: 'header').text).to eq('XHTML Might Be The Future')
end

it 'should find elements with the shortcut syntax' do
driver.navigate.to url_for('xhtmlTest.html')

Expand Down
36 changes: 19 additions & 17 deletions rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module WebDriver
caps = driver.capabilities
expect(caps.proxy).to be_nil
expect(caps.browser_version).to match(/^\d\d\./)
expect(caps.platform_name).to_not be_nil
expect(caps.platform_name).not_to be_nil

expect(caps.accept_insecure_certs).to be == false
expect(caps.page_load_strategy).to be == 'normal'
Expand All @@ -42,21 +42,21 @@ module WebDriver
create_driver! do |driver|
caps = driver.capabilities
expect(caps.proxy).to be_nil
expect(caps.browser_name).to_not be_nil
expect(caps.browser_name).not_to be_nil
expect(caps.version).to match(/^\d\d\./)
expect(caps.platform).to_not be_nil
expect(caps.platform).not_to be_nil

expect(caps.javascript_enabled).to_not be_nil
expect(caps.css_selectors_enabled).to_not be_nil
expect(caps.takes_screenshot).to_not be_nil
expect(caps.native_events).to_not be_nil
expect(caps.rotatable).to_not be_nil
expect(caps.javascript_enabled).not_to be_nil
expect(caps.css_selectors_enabled).not_to be_nil
expect(caps.takes_screenshot).not_to be_nil
expect(caps.native_events).not_to be_nil
expect(caps.rotatable).not_to be_nil
end
end

it 'has remote session ID', only: {driver: :remote}, except: {browser: :ff_esr} do
create_driver! do |driver|
expect(driver.capabilities.remote_session_id).to be
expect(driver.capabilities.remote_session_id).to be_truthy
end
end

Expand All @@ -65,16 +65,17 @@ module WebDriver

begin
path = Firefox::Binary.path
default_version = nil

create_driver! do |driver|
@default_version = driver.capabilities.version
expect { driver.capabilities.browser_version }.to_not raise_exception
default_version = driver.capabilities.version
expect { driver.capabilities.browser_version }.not_to raise_exception
end

caps = Remote::Capabilities.firefox(firefox_options: {binary: ENV['ALT_FIREFOX_BINARY']})
create_driver!(desired_capabilities: caps) do |driver|
expect(driver.capabilities.version).to_not eql(@default_version)
expect { driver.capabilities.browser_version }.to_not raise_exception
expect(driver.capabilities.version).not_to eql(default_version)
expect { driver.capabilities.browser_version }.not_to raise_exception
end
ensure
Firefox::Binary.path = path
Expand All @@ -86,16 +87,17 @@ module WebDriver

begin
path = Firefox::Binary.path
default_version = nil

create_driver! do |driver|
@default_version = driver.capabilities.version
expect { driver.capabilities.browser_version }.to_not raise_exception
default_version = driver.capabilities.version
expect { driver.capabilities.browser_version }.not_to raise_exception
end

caps = Remote::Capabilities.firefox(firefox_options: {binary: ENV['ALT_FIREFOX_BINARY']})
create_driver!(desired_capabilities: caps, driver_opts: {binary: path}) do |driver|
expect(driver.capabilities.version).to_not eql(@default_version)
expect { driver.capabilities.browser_version }.to_not raise_exception
expect(driver.capabilities.version).not_to eql(default_version)
expect { driver.capabilities.browser_version }.not_to raise_exception
end
ensure
Firefox::Binary.path = path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,22 @@ def profile_opts
end

describe 'with browser', except: {driver: :ff_esr} do
before(:each) do
before do
profile['browser.startup.homepage'] = url_for('simpleTest.html')
profile['browser.startup.page'] = 1
end

it 'should instantiate the browser with the correct profile' do
create_driver!(profile_opts) do |driver|
expect { wait(5).until { driver.find_element(id: 'oneline') } }.to_not raise_error
expect { wait(5).until { driver.find_element(id: 'oneline') } }.not_to raise_error
end
end

it 'should be able to use the same profile more than once' do
create_driver!(profile_opts) do |driver1|
expect { wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error
expect { wait(5).until { driver1.find_element(id: 'oneline') } }.not_to raise_error
create_driver!(profile_opts) do |driver2|
expect { wait(5).until { driver2.find_element(id: 'oneline') } }.to_not raise_error
expect { wait(5).until { driver2.find_element(id: 'oneline') } }.not_to raise_error
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions rb/spec/integration/selenium/webdriver/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ module DriverExtensions

context 'local storage' do
let(:storage) { driver.local_storage }

it_behaves_like 'web storage'
end

context 'session storage' do
let(:storage) { driver.session_storage }

it_behaves_like 'web storage'
end
end
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module WebDriver
after { driver.manage.timeouts.page_load = 300000 }

it 'should be able to set the page load timeout' do
expect { driver.manage.timeouts.page_load = 2 }.to_not raise_exception
expect { driver.manage.timeouts.page_load = 2 }.not_to raise_exception
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions rb/spec/unit/selenium/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

module Selenium
describe Server do
let(:mock_process) { double(ChildProcess).as_null_object }
let(:mock_poller) { double('SocketPoller', connected?: true, closed?: true) }
let(:mock_process) { instance_double(ChildProcess::AbstractProcess).as_null_object }
let(:mock_poller) { instance_double('SocketPoller', connected?: true, closed?: true) }

it 'raises an error if the jar file does not exist' do
expect {
Expand Down Expand Up @@ -170,7 +170,7 @@ module Selenium
it 'raises Selenium::Server::Error if the server is not launched within the timeout' do
expect(File).to receive(:exist?).with('selenium-server-test.jar').and_return(true)

poller = double('SocketPoller')
poller = instance_double('SocketPoller')
expect(poller).to receive(:connected?).and_return(false)

server = Selenium::Server.new('selenium-server-test.jar', background: true)
Expand Down
Loading

0 comments on commit 34522d1

Please sign in to comment.