rubocop-capybara 2.20.0 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 963a68452b58c47db1d1d9e7f9201db0a98a8b70bb8089473b406911fa5cc33e
4
- data.tar.gz: 58e60dd5ff6097695a1029b9e37414209f7c26d2da0d16cbc6b808c8cd56efd8
3
+ metadata.gz: ed8a103d3d11a90d7873a5569246e580d816e2ebad0a614827bd2ed3546bf6bf
4
+ data.tar.gz: d09792f9ea669f7556814b898fbfd9829e8db25fdd3b8873ac85487ee9f199ef
5
5
  SHA512:
6
- metadata.gz: cec93e7919aeefbb1f2b2c13f1f0caeb7627c5556f85fe219f107b6520237cccd792ad4713905dfb47151f0bcb82e04d4bd0034a7a747b741e607ea9d4de5e54
7
- data.tar.gz: 3e359ec71065b5daf64cdb080d8ddfad4f6144778ad7fb89d932aa083353547663a1316efe7f9e9fd3cb7bca6a6f012812ea7f18e00c76a8af22316f24325f7c
6
+ metadata.gz: '0798dc5b62b3dc8a8ea31bd1f79cedde039d0d69e94cf18a902ced3da7ae757b0529fa17b8d5711baae964fb591eccfcce4f7b16320598cd9dafb657c4aee85c'
7
+ data.tar.gz: 7de56f77982c7b52973c38698317233da3ebeb2a55dff962c380105419d2708e43e16d5f1f63a87338ec935d6c5c24941efd95a2d308b2236d7dd840bf8c63ab
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Edge (Unreleased)
4
4
 
5
+ ## 2.21.0 (2024-06-08)
6
+
7
+ - Fix a false negative for `Capybara/NegationMatcher` when using `to_not`. ([@ydah])
8
+ - Fix a false negative for `Capybara/SpecificFinders` when using `find(:id, 'some-id')`. ([@ydah])
9
+
5
10
  ## 2.20.0 (2024-01-03)
6
11
 
7
12
  - Change to default `EnforcedStyle: link_or_button` for `Capybara/ClickLinkOrButtonStyle` cop. ([@ydah])
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Capybara
5
+ module Cop
6
+ # Source and spec generator for new cops
7
+ #
8
+ # This generator will take a cop name and generate a source file
9
+ # and spec file when given a valid qualified cop name.
10
+ # @api private
11
+ class Generator < RuboCop::Cop::Generator
12
+ def todo
13
+ <<~TODO
14
+ Do 4 steps:
15
+ 1. Modify the description of #{badge} in config/default.yml
16
+ 2. Implement your new cop in the generated file!
17
+ 3. Add an entry about new cop to CHANGELOG.md
18
+ 4. Commit your new cop with a message such as
19
+ e.g. "Add new `#{badge}` cop"
20
+ TODO
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -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.20.0'
7
+ STRING = '2.21.0'
8
8
  end
9
9
  end
10
10
  end
@@ -37,20 +37,20 @@ module RuboCop
37
37
  RESTRICT_ON_SEND = %i[expect].freeze
38
38
 
39
39
  # @!method expectation_set_on_current_path(node)
40
- def_node_matcher :expectation_set_on_current_path, <<-PATTERN
40
+ def_node_matcher :expectation_set_on_current_path, <<~PATTERN
41
41
  (send nil? :expect (send {(send nil? :page) nil?} :current_path))
42
42
  PATTERN
43
43
 
44
44
  # Supported matchers: eq(...) / match(/regexp/) / match('regexp')
45
45
  # @!method as_is_matcher(node)
46
- def_node_matcher :as_is_matcher, <<-PATTERN
46
+ def_node_matcher :as_is_matcher, <<~PATTERN
47
47
  (send
48
48
  #expectation_set_on_current_path ${:to :to_not :not_to}
49
49
  ${(send nil? :eq ...) (send nil? :match (regexp ...))})
50
50
  PATTERN
51
51
 
52
52
  # @!method regexp_node_matcher(node)
53
- def_node_matcher :regexp_node_matcher, <<-PATTERN
53
+ def_node_matcher :regexp_node_matcher, <<~PATTERN
54
54
  (send
55
55
  #expectation_set_on_current_path ${:to :to_not :not_to}
56
56
  $(send nil? :match ${str dstr xstr}))
@@ -16,7 +16,7 @@ module RuboCop
16
16
 
17
17
  # @return [Array<String>]
18
18
  def parse # rubocop:disable Metrics/MethodLength
19
- @selector.chars do |char|
19
+ @selector.each_char do |char|
20
20
  if char == '['
21
21
  on_bracket_start
22
22
  elsif char == ']'
@@ -7,20 +7,20 @@ module RuboCop
7
7
  #
8
8
  # @example EnforcedStyle: have_no (default)
9
9
  # # bad
10
- # expect(page).not_to have_selector
10
+ # expect(page).not_to have_selector 'a'
11
11
  # expect(page).not_to have_css('a')
12
12
  #
13
13
  # # good
14
- # expect(page).to have_no_selector
14
+ # expect(page).to have_no_selector 'a'
15
15
  # expect(page).to have_no_css('a')
16
16
  #
17
17
  # @example EnforcedStyle: not_to
18
18
  # # bad
19
- # expect(page).to have_no_selector
19
+ # expect(page).to have_no_selector 'a'
20
20
  # expect(page).to have_no_css('a')
21
21
  #
22
22
  # # good
23
- # expect(page).not_to have_selector
23
+ # expect(page).not_to have_selector 'a'
24
24
  # expect(page).not_to have_css('a')
25
25
  #
26
26
  class NegationMatcher < ::RuboCop::Cop::Base
@@ -42,7 +42,7 @@ module RuboCop
42
42
 
43
43
  # @!method not_to?(node)
44
44
  def_node_matcher :not_to?, <<~PATTERN
45
- (send ... :not_to
45
+ (send ... {:not_to :to_not}
46
46
  (send nil? %POSITIVE_MATCHERS ...))
47
47
  PATTERN
48
48
 
@@ -53,7 +53,7 @@ module RuboCop
53
53
  PATTERN
54
54
 
55
55
  def on_send(node)
56
- return unless offense?(node.parent)
56
+ return unless offense?(node)
57
57
 
58
58
  matcher = node.method_name.to_s
59
59
  add_offense(offense_range(node),
@@ -67,8 +67,9 @@ module RuboCop
67
67
  private
68
68
 
69
69
  def offense?(node)
70
- (style == :have_no && not_to?(node)) ||
71
- (style == :not_to && have_no?(node))
70
+ node.arguments? &&
71
+ ((style == :have_no && not_to?(node.parent)) ||
72
+ (style == :not_to && have_no?(node.parent)))
72
73
  end
73
74
 
74
75
  def offense_range(node)
@@ -28,7 +28,7 @@ module RuboCop
28
28
  }.freeze
29
29
 
30
30
  # @!method click_on_selector(node)
31
- def_node_matcher :click_on_selector, <<-PATTERN
31
+ def_node_matcher :click_on_selector, <<~PATTERN
32
32
  (send _ :find (str $_) ...)
33
33
  PATTERN
34
34
 
@@ -10,6 +10,7 @@ module RuboCop
10
10
  # find('#some-id')
11
11
  # find('[id=some-id]')
12
12
  # find(:css, '#some-id')
13
+ # find(:id, 'some-id')
13
14
  #
14
15
  # # good
15
16
  # find_by_id('some-id')
@@ -23,7 +24,7 @@ module RuboCop
23
24
 
24
25
  # @!method find_argument(node)
25
26
  def_node_matcher :find_argument, <<~PATTERN
26
- (send _ :find $(sym :css)? (str $_) ...)
27
+ (send _ :find $(sym {:css :id})? (str $_) ...)
27
28
  PATTERN
28
29
 
29
30
  # @!method class_options(node)
@@ -38,6 +39,7 @@ module RuboCop
38
39
 
39
40
  on_attr(node, sym, arg) if attribute?(arg)
40
41
  on_id(node, sym, arg) if CssSelector.id?(arg)
42
+ on_sym_id(node, sym, arg) if sym.first&.value == :id
41
43
  end
42
44
  end
43
45
 
@@ -59,6 +61,10 @@ module RuboCop
59
61
  CssSelector.classes(arg.sub("##{id}", '')))
60
62
  end
61
63
 
64
+ def on_sym_id(node, sym, id)
65
+ register_offense(node, sym, "'#{id}'")
66
+ end
67
+
62
68
  def attribute?(arg)
63
69
  CssSelector.attribute?(arg) &&
64
70
  CapybaraHelp.common_attributes?(arg)
@@ -106,11 +112,11 @@ module RuboCop
106
112
  end
107
113
 
108
114
  def to_options(attrs)
109
- attrs.each.map do |key, value|
115
+ attrs.each.filter_map do |key, value|
110
116
  next if key == 'id'
111
117
 
112
118
  "#{key}: #{value}"
113
- end.compact.join(', ')
119
+ end.join(', ')
114
120
  end
115
121
 
116
122
  def offense_range(node)
@@ -23,7 +23,7 @@ module RuboCop
23
23
  # expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com')
24
24
  # expect(page).to have_table(class: 'cls')
25
25
  # expect(page).to have_select
26
- # expect(page).to have_field('foo')
26
+ # expect(page).to have_field(with: 'foo')
27
27
  #
28
28
  class SpecificMatcher < ::RuboCop::Cop::Base
29
29
  MSG = 'Prefer `%<good_matcher>s` over `%<bad_matcher>s`.'
@@ -38,12 +38,12 @@ module RuboCop
38
38
  }.freeze
39
39
 
40
40
  # @!method first_argument(node)
41
- def_node_matcher :first_argument, <<-PATTERN
41
+ def_node_matcher :first_argument, <<~PATTERN
42
42
  (send nil? _ (str $_) ... )
43
43
  PATTERN
44
44
 
45
45
  # @!method text_with_regexp?(node)
46
- def_node_search :text_with_regexp?, <<-PATTERN
46
+ def_node_search :text_with_regexp?, <<~PATTERN
47
47
  (pair (sym {:text :exact_text}) (regexp ...))
48
48
  PATTERN
49
49
 
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.20.0
4
+ version: 2.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-02 00:00:00.000000000 Z
11
+ date: 2024-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -24,10 +24,10 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.41'
27
- description: |2
28
- Code style checking for Capybara test files (RSpec, Cucumber, Minitest).
29
- A plugin for the RuboCop code style enforcing & linting tool.
30
- email:
27
+ description: |
28
+ Code style checking for Capybara test files (RSpec, Cucumber, Minitest).
29
+ A plugin for the RuboCop code style enforcing & linting tool.
30
+ email:
31
31
  executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files:
@@ -41,6 +41,7 @@ files:
41
41
  - config/default.yml
42
42
  - lib/rubocop-capybara.rb
43
43
  - lib/rubocop/capybara/config_formatter.rb
44
+ - lib/rubocop/capybara/cop/generator.rb
44
45
  - lib/rubocop/capybara/description_extractor.rb
45
46
  - lib/rubocop/capybara/version.rb
46
47
  - lib/rubocop/cop/capybara/click_link_or_button_style.rb
@@ -65,7 +66,7 @@ metadata:
65
66
  changelog_uri: https://github.com/rubocop/rubocop-capybara/blob/main/CHANGELOG.md
66
67
  documentation_uri: https://docs.rubocop.org/rubocop-capybara/
67
68
  rubygems_mfa_required: 'true'
68
- post_install_message:
69
+ post_install_message:
69
70
  rdoc_options: []
70
71
  require_paths:
71
72
  - lib
@@ -80,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  - !ruby/object:Gem::Version
81
82
  version: '0'
82
83
  requirements: []
83
- rubygems_version: 3.4.22
84
- signing_key:
84
+ rubygems_version: 3.5.9
85
+ signing_key:
85
86
  specification_version: 4
86
87
  summary: Code style checking for Capybara test files
87
88
  test_files: []