From 50125e25f6999c4ba6eb2899720ffe4e517b433a Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 13 Jul 2020 23:23:08 -0700 Subject: [PATCH] Rubocop update --- .rubocop.yml | 18 ++++++++++++++++++ lib/capybara.rb | 2 +- lib/capybara/queries/selector_query.rb | 5 +++-- lib/capybara/selenium/extensions/scroll.rb | 18 ++++++++---------- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e4f44698..a9e79522 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -73,6 +73,9 @@ Lint/DeprecatedOpenSSLConstant: Lint/MixedRegexpCaptureTypes: Enabled: true +Lint/DuplicateElsifCondition: + Enabled: true + Layout/EndAlignment: EnforcedStyleAlignWith: variable @@ -158,6 +161,21 @@ Style/BisectedAttrAccessor: Style/RedundantAssignment: Enabled: true + +Style/ArrayCoercion: + Enabled: true + +Style/CaseLikeIf: + Enabled: true + +Style/HashAsLastArrayItem: + Enabled: true + +Style/HashLikeCase: + Enabled: true + +Style/RedundantFileExtensionInRequire: + Enabled: true Layout/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true diff --git a/lib/capybara.rb b/lib/capybara.rb index d0b6af40..95c2ac78 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -484,7 +484,7 @@ module Capybara require 'capybara/rack_test/node' require 'capybara/rack_test/form' require 'capybara/rack_test/browser' - require 'capybara/rack_test/css_handlers.rb' + require 'capybara/rack_test/css_handlers' require 'capybara/selenium/node' require 'capybara/selenium/driver' diff --git a/lib/capybara/queries/selector_query.rb b/lib/capybara/queries/selector_query.rb index 083b58ea..2a27574f 100644 --- a/lib/capybara/queries/selector_query.rb +++ b/lib/capybara/queries/selector_query.rb @@ -239,13 +239,14 @@ module Capybara hints[:styles] = options[:style] if use_default_style_filter? hints[:position] = true if use_spatial_filter? - if selector_format == :css + case selector_format + when :css if node.method(:find_css).arity != 1 node.find_css(css, **hints) else node.find_css(css) end - elsif selector_format == :xpath + when :xpath if node.method(:find_xpath).arity != 1 node.find_xpath(xpath(exact), **hints) else diff --git a/lib/capybara/selenium/extensions/scroll.rb b/lib/capybara/selenium/extensions/scroll.rb index 4e36c6af..41305c2d 100644 --- a/lib/capybara/selenium/extensions/scroll.rb +++ b/lib/capybara/selenium/extensions/scroll.rb @@ -45,20 +45,18 @@ module Capybara JS end + SCROLL_POSITIONS = { + top: '0', + bottom: 'arguments[0].scrollHeight', + center: '(arguments[0].scrollHeight - arguments[0].clientHeight)/2' + }.freeze + def scroll_to_location(location) - scroll_y = case location - when :top - '0' - when :bottom - 'arguments[0].scrollHeight' - when :center - '(arguments[0].scrollHeight - arguments[0].clientHeight)/2' - end driver.execute_script <<~JS, self if (arguments[0].scrollTo){ - arguments[0].scrollTo(0, #{scroll_y}); + arguments[0].scrollTo(0, #{SCROLL_POSITIONS[location]}); } else { - arguments[0].scrollTop = #{scroll_y}; + arguments[0].scrollTop = #{SCROLL_POSITIONS[location]}; } JS end