Merge pull request #15285 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-capybara-2.18.0

build(deps): bump rubocop-capybara from 2.17.1 to 2.18.0 in /Library/Homebrew
This commit is contained in:
Nanda H Krishna 2023-04-21 19:55:11 -04:00 committed by GitHub
commit 270abd8467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 32 additions and 12 deletions

View File

@ -142,7 +142,7 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.17.1)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-performance (1.17.1)
rubocop (>= 1.7.0, < 2.0)

View File

@ -63,6 +63,7 @@ module RuboCop::Cop::Capybara::CssSelector
end
class RuboCop::Cop::Capybara::CurrentPathExpectation < ::RuboCop::Cop::Base
include ::RuboCop::Cop::RangeHelp
extend ::RuboCop::Cop::AutoCorrector
def as_is_matcher(param0 = T.unsafe(nil)); end
@ -72,9 +73,11 @@ class RuboCop::Cop::Capybara::CurrentPathExpectation < ::RuboCop::Cop::Base
private
def add_argument_parentheses(corrector, arg_node); end
def add_ignore_query_options(corrector, node); end
def autocorrect(corrector, node); end
def convert_regexp_node_to_literal(corrector, matcher_node, regexp_node); end
def method_call_with_no_parentheses?(arg_node); end
def regexp_node_to_regexp_expr(regexp_node); end
def rewrite_expectation(corrector, node, to_symbol, matcher_node); end

View File

@ -104,7 +104,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-progressbar-1.13.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-display_width-2.4.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.50.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-capybara-2.17.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-capybara-2.18.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.17.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.19.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.19.0/lib")

View File

@ -4,7 +4,7 @@ module RuboCop
module Capybara
# Version information for the Capybara RuboCop plugin.
module Version
STRING = '2.17.1'
STRING = '2.18.0'
end
end
end

View File

@ -6,10 +6,10 @@ module RuboCop
# Checks that no expectations are set on Capybara's `current_path`.
#
# The
# https://www.rubydoc.info/github/teamcapybara/capybara/main/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
# https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
# should be used on `page` to set expectations on Capybara's
# current path, since it uses
# https://github.com/teamcapybara/capybara/blob/main/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
# https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
# which ensures that preceding actions (like `click_link`) have
# completed.
#
@ -30,6 +30,7 @@ module RuboCop
#
class CurrentPathExpectation < ::RuboCop::Cop::Base
extend AutoCorrector
include RangeHelp
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
'Capybara feature specs - instead, use the ' \
@ -85,8 +86,7 @@ module RuboCop
end
def rewrite_expectation(corrector, node, to_symbol, matcher_node)
current_path_node = node.first_argument
corrector.replace(current_path_node, 'page')
corrector.replace(node.first_argument, 'page')
corrector.replace(node.parent.loc.selector, 'to')
matcher_method = if to_symbol == :to
'have_current_path'
@ -94,6 +94,7 @@ module RuboCop
'have_no_current_path'
end
corrector.replace(matcher_node.loc.selector, matcher_method)
add_argument_parentheses(corrector, matcher_node.first_argument)
add_ignore_query_options(corrector, node)
end
@ -111,6 +112,20 @@ module RuboCop
end
end
def add_argument_parentheses(corrector, arg_node)
return unless method_call_with_no_parentheses?(arg_node)
first_argument_range = range_with_surrounding_space(
arg_node.first_argument.source_range, side: :left
)
corrector.insert_before(first_argument_range, '(')
corrector.insert_after(arg_node.last_argument, ')')
end
def method_call_with_no_parentheses?(arg_node)
arg_node.send_type? && arg_node.arguments? && !arg_node.parenthesized?
end
# `have_current_path` with no options will include the querystring
# while `page.current_path` does not.
# This ensures the option `ignore_query: true` is added

View File

@ -4,6 +4,7 @@ module RuboCop
module Cop
module Capybara
# Help methods for capybara.
# @api private
module CapybaraHelp
COMMON_OPTIONS = %w[
id class style

View File

@ -4,6 +4,7 @@ module RuboCop
module Cop
module Capybara
# Helps parsing css selector.
# @api private
module CssSelector
module_function

View File

@ -31,7 +31,7 @@ module RuboCop
CAPYBARA_MATCHERS = %w[
selector css xpath text title current_path link button
field checked_field unchecked_field select table
sibling ancestor
sibling ancestor content
].freeze
POSITIVE_MATCHERS =
Set.new(CAPYBARA_MATCHERS) { |element| :"have_#{element}" }.freeze

View File

@ -75,7 +75,7 @@ module RuboCop
end
def offense_range(node, receiver)
receiver.loc.selector.with(end_pos: node.loc.expression.end_pos)
receiver.loc.selector.with(end_pos: node.source_range.end_pos)
end
def message(action, selector)

View File

@ -19,7 +19,7 @@ module RuboCop
include RangeHelp
MSG = 'Prefer `find_by` over `find`.'
MSG = 'Prefer `find_by_id` over `find`.'
RESTRICT_ON_SEND = %i[find].freeze
# @!method find_argument(node)
@ -68,7 +68,7 @@ module RuboCop
def register_offense(node, id, classes = [])
add_offense(offense_range(node)) do |corrector|
corrector.replace(node.loc.selector, 'find_by_id')
corrector.replace(node.first_argument.loc.expression,
corrector.replace(node.first_argument,
id.delete('\\'))
unless classes.compact.empty?
autocorrect_classes(corrector, node, classes)
@ -117,7 +117,7 @@ module RuboCop
if node.loc.end
node.loc.end.end_pos
else
node.loc.expression.end_pos
node.source_range.end_pos
end
end
end