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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/rubocop/capybara/version.rb +1 -1
- data/lib/rubocop/cop/capybara/current_path_expectation.rb +19 -4
- data/lib/rubocop/cop/capybara/mixin/capybara_help.rb +1 -0
- data/lib/rubocop/cop/capybara/mixin/css_selector.rb +1 -0
- data/lib/rubocop/cop/capybara/negation_matcher.rb +1 -1
- data/lib/rubocop/cop/capybara/specific_actions.rb +1 -1
- data/lib/rubocop/cop/capybara/specific_finders.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb7f795cc80f072b94781f2339e781cccf9922ad2303c09111c0e34a4af264f8
|
4
|
+
data.tar.gz: d2ae47b522208177b7c93338973c8a144dfbccca2f817f0797b531f8c89e50b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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/
|
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/
|
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
|
-
|
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
|
@@ -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
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
|
20
20
|
include RangeHelp
|
21
21
|
|
22
|
-
MSG = 'Prefer `
|
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
|
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.
|
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.
|
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-
|
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.
|
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
|