Skip to content

Commit

Permalink
[rb] fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Apr 1, 2020
1 parent a1d8cb6 commit a009a8a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
7 changes: 2 additions & 5 deletions rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,15 @@ Metrics/CyclomaticComplexity:

Metrics/ClassLength:
CountComments: false
Max: 150
Max: 160
Exclude:
- 'lib/selenium/webdriver/firefox/profile.rb'
- 'lib/selenium/webdriver/remote/bridge.rb'
- 'lib/selenium/webdriver/remote/capabilities.rb'
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'

Metrics/AbcSize:
Max: 33
Exclude:
- 'lib/selenium/webdriver/chrome/driver.rb'
- 'lib/selenium/webdriver/remote/capabilities.rb'
- 'lib/selenium/webdriver/common/driver.rb'
- 'lib/selenium/webdriver/support/color.rb'

Metrics/LineLength:
Expand Down
30 changes: 17 additions & 13 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,23 @@ def create_bridge(**opts)
cap_array << options
end

capabilities = cap_array.map { |cap|
capabilities = generate_capabilities(cap_array)

bridge = Remote::Bridge.new(http_client: opts.delete(:http_client), url: opts.delete(:url))
raise ArgumentError, "Unable to create a driver with parameters: #{opts}" unless opts.empty?

namespacing = self.class.to_s.split('::')

if Object.const_defined?("#{namespacing[0..-2].join('::')}::Bridge") && !namespacing.include?('Remote')
bridge.extend Object.const_get("#{namespacing[0, namespacing.length - 1].join('::')}::Bridge")
end

bridge.create_session(capabilities)
bridge
end

def generate_capabilities(cap_array)
cap_array.map { |cap|
if cap.is_a? Symbol
cap = Remote::Capabilities.send(cap)
elsif cap.is_a? Hash
Expand All @@ -331,18 +347,6 @@ def create_bridge(**opts)
end
cap&.as_json
}.inject(:merge) || Remote::Capabilities.send(browser || :new)

bridge = Remote::Bridge.new(http_client: opts.delete(:http_client), url: opts.delete(:url))
raise ArgumentError, "Unable to create a driver with parameters: #{opts}" unless opts.empty?

namespacing = self.class.to_s.split('::')

if Object.const_defined?("#{namespacing[0..-2].join('::')}::Bridge") && !namespacing.include?('Remote')
bridge.extend Object.const_get("#{namespacing[0, namespacing.length - 1].join('::')}::Bridge")
end

bridge.create_session(capabilities)
bridge
end

def service_url(opts)
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def expect_request(body: nil, endpoint: nil)
expect {
expect {
Driver.new(options: Options.new(browser_opts), desired_capabilities: caps)
}.to have_deprecated([:browser_options, :desired_capabilities])
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
end

Expand Down
4 changes: 2 additions & 2 deletions rb/spec/unit/selenium/webdriver/edge/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def expect_request(body: nil, endpoint: nil)
end

it 'accepts constructed Capabilities with Camel Case as Symbols' do
capabilities = Remote::Capabilities.new(browser_name: 'MicrosoftEdge', invalid: 'foobar')
capabilities = Remote::Capabilities.new(browserName: 'MicrosoftEdge', invalid: 'foobar')
expect_request(body: {capabilities: {firstMatch: [browserName: "MicrosoftEdge",
invalid: 'foobar']}})

Expand Down Expand Up @@ -136,7 +136,7 @@ def expect_request(body: nil, endpoint: nil)
expect {
expect {
Driver.new(options: Options.new(browser_opts), desired_capabilities: caps)
}.to have_deprecated([:browser_options, :desired_capabilities])
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
end

Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def expect_request(body: nil, endpoint: nil)
expect {
expect {
Driver.new(options: Options.new(browser_opts), desired_capabilities: caps)
}.to have_deprecated([:browser_options, :desired_capabilities])
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
end

Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/ie/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def expect_request(body: nil, endpoint: nil)
expect {
expect {
Driver.new(options: Options.new(browser_opts), desired_capabilities: caps)
}.to have_deprecated([:browser_options, :desired_capabilities])
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
end

Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/remote/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def expect_request(body: nil, endpoint: nil)
expect {
expect {
Driver.new(desired_capabilities: :chrome, options: Chrome::Options.new(opts))
}.to have_deprecated([:browser_options, :desired_capabilities])
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
end

Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/safari/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def expect_request(body: nil, endpoint: nil)
expect {
expect {
Driver.new(options: Options.new(browser_opts), desired_capabilities: caps)
}.to have_deprecated([:browser_options, :desired_capabilities])
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
end

Expand Down

0 comments on commit a009a8a

Please sign in to comment.