From 920ce495d726348a455a5f6626dbd34f7d2ecd2d Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sat, 31 Oct 2020 10:39:21 -0700 Subject: [PATCH] Rubocop 1.x was released - use it --- .rubocop.yml | 16 +++++++++++++++- capybara.gemspec | 4 ++-- lib/capybara/selector/definition.rb | 2 +- lib/capybara/selector/definition/button.rb | 2 +- .../selector/definition/datalist_input.rb | 2 +- lib/capybara/selector/definition/select.rb | 2 +- lib/capybara/selector/definition/table_row.rb | 2 +- lib/capybara/selector/filter_set.rb | 2 +- lib/capybara/session.rb | 2 +- lib/capybara/spec/session/find_spec.rb | 2 +- lib/capybara/spec/spec_helper.rb | 2 +- spec/rspec/shared_spec_matchers.rb | 4 ++-- 12 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6bde93ec..8009245d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -83,6 +83,11 @@ Lint/DuplicateElsifCondition: Layout/EndAlignment: EnforcedStyleAlignWith: variable +Lint/EmptyBlock: + Exclude: + - 'lib/capybara/spec/**/*' + - 'spec/**/*.rb' + Naming/PredicateName: Exclude: - '**/*/*matchers.rb' @@ -111,6 +116,9 @@ Style/Documentation: - 'spec/**/*' Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false + Style/DoubleNegation: Enabled: false @@ -261,5 +269,11 @@ RSpec/PredicateMatcher: Exclude: - 'spec/basic_node_spec.rb' -Capybara/FeatureMethods: +RSpec/Capybara: + Enabled: false + +RSpec/Capybara/FeatureMethods: + Enabled: false + +RSpec/Capybara/VisibilityMatcher: Enabled: false diff --git a/capybara.gemspec b/capybara.gemspec index fcd7ef52..be7fe16e 100644 --- a/capybara.gemspec +++ b/capybara.gemspec @@ -46,9 +46,9 @@ Gem::Specification.new do |s| s.add_development_dependency('rake') s.add_development_dependency('rspec', ['>= 3.5.0']) s.add_development_dependency('rspec-instafail') - s.add_development_dependency('rubocop', ['~>0.72']) + s.add_development_dependency('rubocop', ['~>1.1.0']) s.add_development_dependency('rubocop-performance') - s.add_development_dependency('rubocop-rspec') + s.add_development_dependency('rubocop-rspec', ['~>2.0.0.pre']) s.add_development_dependency('sauce_whisk') s.add_development_dependency('selenium_statistics') s.add_development_dependency('selenium-webdriver', ['~>3.5']) diff --git a/lib/capybara/selector/definition.rb b/lib/capybara/selector/definition.rb index 10422547..0670e0b3 100644 --- a/lib/capybara/selector/definition.rb +++ b/lib/capybara/selector/definition.rb @@ -15,7 +15,7 @@ module Capybara def initialize(name, locator_type: nil, raw_locator: false, supports_exact: nil, &block) @name = name - @filter_set = Capybara::Selector::FilterSet.add(name) {} + @filter_set = Capybara::Selector::FilterSet.add(name) @match = nil @label = nil @failure_message = nil diff --git a/lib/capybara/selector/definition/button.rb b/lib/capybara/selector/definition/button.rb index 89944166..28548abd 100644 --- a/lib/capybara/selector/definition/button.rb +++ b/lib/capybara/selector/definition/button.rb @@ -30,7 +30,7 @@ Capybara.add_selector(:button, locator_type: [String, Symbol]) do end %i[value title type].inject(input_btn_xpath.union(btn_xpath).union(image_btn_xpath)) do |memo, ef| - memo[find_by_attr(ef, options[ef])] + memo.where(find_by_attr(ef, options[ef])) end end diff --git a/lib/capybara/selector/definition/datalist_input.rb b/lib/capybara/selector/definition/datalist_input.rb index f3210fe9..7a409296 100644 --- a/lib/capybara/selector/definition/datalist_input.rb +++ b/lib/capybara/selector/definition/datalist_input.rb @@ -19,7 +19,7 @@ Capybara.add_selector(:datalist_input, locator_type: [String, Symbol]) do expression_filter(:with_options) do |expr, options| options.inject(expr) do |xpath, option| - xpath[XPath.attr(:list) == XPath.anywhere(:datalist)[expression_for(:datalist_option, option)].attr(:id)] + xpath.where(XPath.attr(:list) == XPath.anywhere(:datalist)[expression_for(:datalist_option, option)].attr(:id)) end end diff --git a/lib/capybara/selector/definition/select.rb b/lib/capybara/selector/definition/select.rb index 92582f55..48de81cf 100644 --- a/lib/capybara/selector/definition/select.rb +++ b/lib/capybara/selector/definition/select.rb @@ -33,7 +33,7 @@ Capybara.add_selector(:select, locator_type: [String, Symbol]) do expression_filter(:with_options) do |expr, options| options.inject(expr) do |xpath, option| - xpath[expression_for(:option, option)] + xpath.where(expression_for(:option, option)) end end diff --git a/lib/capybara/selector/definition/table_row.rb b/lib/capybara/selector/definition/table_row.rb index d917e685..e079c976 100644 --- a/lib/capybara/selector/definition/table_row.rb +++ b/lib/capybara/selector/definition/table_row.rb @@ -14,7 +14,7 @@ Capybara.add_selector(:table_row, locator_type: [Array, Hash]) do else initial_td = XPath.descendant(:td)[XPath.string.n.is(locator.shift)] tds = locator.reverse.map { |cell| XPath.following_sibling(:td)[XPath.string.n.is(cell)] } - .reduce { |xp, cell| xp[cell] } + .reduce { |xp, cell| xp.where(cell) } xpath[initial_td[tds]] end end diff --git a/lib/capybara/selector/filter_set.rb b/lib/capybara/selector/filter_set.rb index 91500843..56962a9a 100644 --- a/lib/capybara/selector/filter_set.rb +++ b/lib/capybara/selector/filter_set.rb @@ -12,7 +12,7 @@ module Capybara @node_filters = {} @expression_filters = {} @descriptions = Hash.new { |hsh, key| hsh[key] = [] } - instance_eval(&block) + instance_eval(&block) if block end def node_filter(names, *types, **options, &block) diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index e9f600b1..48ecc87b 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -739,7 +739,7 @@ module Capybara # @param [Hash] options a customizable set of options # def save_and_open_screenshot(path = nil, **options) - save_screenshot(path, **options).tap { |s_path| open_file(s_path) } # rubocop:disable Lint/Debugger + save_screenshot(path, **options).tap { |s_path| open_file(s_path) } end def document diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index fd6190b3..150786d4 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -60,7 +60,7 @@ Capybara::SpecHelper.spec '#find' do end end - context 'with frozen time', requires: [:js] do # rubocop:disable RSpec/EmptyExampleGroup + context 'with frozen time', requires: [:js] do if defined?(Process::CLOCK_MONOTONIC) it 'will time out even if time is frozen' do @session.visit('/with_js') diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 3ee4e873..7a3eb2ea 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -84,7 +84,7 @@ module Capybara end specs.each do |spec_name, spec_options, block| - describe spec_name, *spec_options do # rubocop:disable RSpec/EmptyExampleGroup + describe spec_name, *spec_options do class_eval(&block) end end diff --git a/spec/rspec/shared_spec_matchers.rb b/spec/rspec/shared_spec_matchers.rb index ff9e2f60..61f9a5ec 100644 --- a/spec/rspec/shared_spec_matchers.rb +++ b/spec/rspec/shared_spec_matchers.rb @@ -840,10 +840,10 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode| end it 'gives proper description when :visible option passed' do - expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher + expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"') expect(have_table('Lovely table', visible: :hidden).description).to eq('have non-visible table "Lovely table"') expect(have_table('Lovely table', visible: :all).description).to eq('have table "Lovely table"') - expect(have_table('Lovely table', visible: false).description).to eq('have table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher + expect(have_table('Lovely table', visible: false).description).to eq('have table "Lovely table"') end it 'passes if there is such a table' do