rubocop-capybara 2.17.1 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f842364dafbf74a569f7e4d40eeee32b49bf3b9983d7ada2f376fb919481bdf
4
- data.tar.gz: 075717405e4165171110bbdd29863873b4b94822baef45cb3946d8055da497bb
3
+ metadata.gz: bb7f795cc80f072b94781f2339e781cccf9922ad2303c09111c0e34a4af264f8
4
+ data.tar.gz: d2ae47b522208177b7c93338973c8a144dfbccca2f817f0797b531f8c89e50b9
5
5
  SHA512:
6
- metadata.gz: 70e7fe7215dda9d8ae088bc0df07e50cf3d2f1c0645afe8797d7ce4a03b080a710b52da0403b37ce0ec6dc1a428d999e0342ea53d39d406c68f894059d9d7f6c
7
- data.tar.gz: 7d17ff840e4f4ac78b079bbc9a567c10b1fbf2419f748b932bd67a2bdfe43e2a825dd06735974daff51dc35f323824803010e4526adedef9dc0812f77a8fe5f7
6
+ metadata.gz: 36b58f29500840c7dc34c2c2ed55856ff08cdd7ca41822209a9388204948903be89cf13c3065da7cfed3e8332f3433b3293087c8de1cf1266f093fadef2fa69d
7
+ data.tar.gz: 5b961abac7ae8dd46708ec9649718a23596bde9e45bcc48f7d9e818c2a116d5fda3de0653cf3aa8e56d11ed11ebcb94e24ef49ee0653e739a26d43d2383c2152
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Edge (Unreleased)
4
4
 
5
+ ## 2.18.0 (2023-04-21)
6
+
7
+ - Fix an offense message for `Capybara/SpecificFinders`. ([@ydah])
8
+ - Expand `Capybara/NegationMatcher` to support `have_content` ([@OskarsEzerins])
9
+ - Fix an incorrect autocorrect for `Capybara/CurrentPathExpectation` when matcher's argument is a method with a argument and no parentheses. ([@ydah])
10
+
5
11
  ## 2.17.1 (2023-02-13)
6
12
 
7
13
  - Fix an incorrect autocorrect for `Capybara/CurrentPathExpectation`. ([@ydah])
@@ -47,6 +53,7 @@
47
53
  [@bquorning]: https://github.com/bquorning
48
54
  [@darhazer]: https://github.com/Darhazer
49
55
  [@onumis]: https://github.com/onumis
56
+ [@oskarsezerins]: https://github.com/OskarsEzerins
50
57
  [@pirj]: https://github.com/pirj
51
58
  [@rspeicher]: https://github.com/rspeicher
52
59
  [@timrogers]: https://github.com/timrogers
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Capybara
5
5
  # Version information for the Capybara RuboCop plugin.
6
6
  module Version
7
- STRING = '2.17.1'
7
+ STRING = '2.18.0'
8
8
  end
9
9
  end
10
10
  end
@@ -6,10 +6,10 @@ module RuboCop
6
6
  # Checks that no expectations are set on Capybara's `current_path`.
7
7
  #
8
8
  # The
9
- # https://www.rubydoc.info/github/teamcapybara/capybara/main/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
9
+ # https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
10
10
  # should be used on `page` to set expectations on Capybara's
11
11
  # current path, since it uses
12
- # https://github.com/teamcapybara/capybara/blob/main/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
12
+ # https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
13
13
  # which ensures that preceding actions (like `click_link`) have
14
14
  # completed.
15
15
  #
@@ -30,6 +30,7 @@ module RuboCop
30
30
  #
31
31
  class CurrentPathExpectation < ::RuboCop::Cop::Base
32
32
  extend AutoCorrector
33
+ include RangeHelp
33
34
 
34
35
  MSG = 'Do not set an RSpec expectation on `current_path` in ' \
35
36
  'Capybara feature specs - instead, use the ' \
@@ -85,8 +86,7 @@ module RuboCop
85
86
  end
86
87
 
87
88
  def rewrite_expectation(corrector, node, to_symbol, matcher_node)
88
- current_path_node = node.first_argument
89
- corrector.replace(current_path_node, 'page')
89
+ corrector.replace(node.first_argument, 'page')
90
90
  corrector.replace(node.parent.loc.selector, 'to')
91
91
  matcher_method = if to_symbol == :to
92
92
  'have_current_path'
@@ -94,6 +94,7 @@ module RuboCop
94
94
  'have_no_current_path'
95
95
  end
96
96
  corrector.replace(matcher_node.loc.selector, matcher_method)
97
+ add_argument_parentheses(corrector, matcher_node.first_argument)
97
98
  add_ignore_query_options(corrector, node)
98
99
  end
99
100
 
@@ -111,6 +112,20 @@ module RuboCop
111
112
  end
112
113
  end
113
114
 
115
+ def add_argument_parentheses(corrector, arg_node)
116
+ return unless method_call_with_no_parentheses?(arg_node)
117
+
118
+ first_argument_range = range_with_surrounding_space(
119
+ arg_node.first_argument.source_range, side: :left
120
+ )
121
+ corrector.insert_before(first_argument_range, '(')
122
+ corrector.insert_after(arg_node.last_argument, ')')
123
+ end
124
+
125
+ def method_call_with_no_parentheses?(arg_node)
126
+ arg_node.send_type? && arg_node.arguments? && !arg_node.parenthesized?
127
+ end
128
+
114
129
  # `have_current_path` with no options will include the querystring
115
130
  # while `page.current_path` does not.
116
131
  # This ensures the option `ignore_query: true` is added
@@ -4,6 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Capybara
6
6
  # Help methods for capybara.
7
+ # @api private
7
8
  module CapybaraHelp
8
9
  COMMON_OPTIONS = %w[
9
10
  id class style
@@ -4,6 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Capybara
6
6
  # Helps parsing css selector.
7
+ # @api private
7
8
  module CssSelector
8
9
  module_function
9
10
 
@@ -31,7 +31,7 @@ module RuboCop
31
31
  CAPYBARA_MATCHERS = %w[
32
32
  selector css xpath text title current_path link button
33
33
  field checked_field unchecked_field select table
34
- sibling ancestor
34
+ sibling ancestor content
35
35
  ].freeze
36
36
  POSITIVE_MATCHERS =
37
37
  Set.new(CAPYBARA_MATCHERS) { |element| :"have_#{element}" }.freeze
@@ -75,7 +75,7 @@ module RuboCop
75
75
  end
76
76
 
77
77
  def offense_range(node, receiver)
78
- receiver.loc.selector.with(end_pos: node.loc.expression.end_pos)
78
+ receiver.loc.selector.with(end_pos: node.source_range.end_pos)
79
79
  end
80
80
 
81
81
  def message(action, selector)
@@ -19,7 +19,7 @@ module RuboCop
19
19
 
20
20
  include RangeHelp
21
21
 
22
- MSG = 'Prefer `find_by` over `find`.'
22
+ MSG = 'Prefer `find_by_id` over `find`.'
23
23
  RESTRICT_ON_SEND = %i[find].freeze
24
24
 
25
25
  # @!method find_argument(node)
@@ -68,7 +68,7 @@ module RuboCop
68
68
  def register_offense(node, id, classes = [])
69
69
  add_offense(offense_range(node)) do |corrector|
70
70
  corrector.replace(node.loc.selector, 'find_by_id')
71
- corrector.replace(node.first_argument.loc.expression,
71
+ corrector.replace(node.first_argument,
72
72
  id.delete('\\'))
73
73
  unless classes.compact.empty?
74
74
  autocorrect_classes(corrector, node, classes)
@@ -117,7 +117,7 @@ module RuboCop
117
117
  if node.loc.end
118
118
  node.loc.end.end_pos
119
119
  else
120
- node.loc.expression.end_pos
120
+ node.source_range.end_pos
121
121
  end
122
122
  end
123
123
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.17.1
4
+ version: 2.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-16 00:00:00.000000000 Z
11
+ date: 2023-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.4.3
78
+ rubygems_version: 3.4.5
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Code style checking for Capybara test files