rubocop-rspec 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: 1ebfcc955ecfa8b3437defde668d955020f03a2dbba2c9337f0b75a8fb9a3c26
4
- data.tar.gz: 7a547b1e24c278de072b2c912be27e1dc5fb1450b6fa65d563278d0f054d6d1d
3
+ metadata.gz: 5a388b40471f85e4da35358c9c9c0ab8bdce272c171b989553a174ea5f2fa04f
4
+ data.tar.gz: 251c7b2c7f83daeb4f3e3f4e10f1b0f37763088ac792982e27052da26c1645ea
5
5
  SHA512:
6
- metadata.gz: f8942cdf262718de32bfbc765e3f2aac9eae49e364d7a2d866300b77e0bd39fd24b168d513577a1a95a82ce10a0f325a66c6b2914da71dd3951011c2399b0b3e
7
- data.tar.gz: 89c8fce01b42c53c50460b9411cd44f96b99663ce3a2e7735e6cb0f260c1cc3a86ba0daba553b4ebeba25625dde25f41d8b2129929cf92514e06e0f0f8191ec5
6
+ metadata.gz: 6311a48d125da92639f8bebbeebdd9b16e7968bf2b522d29310c913490977a465aa77112e39497880373be23732a2fb3cfa205b92475e2edd069c1009ae91aac
7
+ data.tar.gz: fd3d495d5ec63969e2d926c5c151cf888de321b74486644983c6aa72b3c18b071daafe19b0996a0fa476334d00bf05768c09ae4ce03d39bbdf436898b64809c0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.21.0 (2023-05-05)
6
+
7
+ - Fix a false positive in `RSpec/IndexedLet` with suffixes after index-like numbers. ([@pirj])
8
+ - Fix an error for `RSpec/Rails/HaveHttpStatus` with comparison with strings containing non-numeric characters. ([@ydah])
9
+ - Fix an error for `RSpec/MatchArray` when `match_array` with no argument. ([@ydah])
10
+ - Add support `a_block_changing` and `changing` for `RSpec/ChangeByZero`. ([@ydah])
11
+ - Drop Ruby 2.6 support. ([@ydah])
12
+
5
13
  ## 2.20.0 (2023-04-18)
6
14
 
7
15
  - Add new `RSpec/IndexedLet` cop. ([@dmitrytsepelev])
@@ -59,15 +59,16 @@ module RuboCop
59
59
  #
60
60
  class ChangeByZero < Base
61
61
  extend AutoCorrector
62
- MSG = 'Prefer `not_to change` over `to change.by(0)`.'
62
+ MSG = 'Prefer `not_to change` over `to %<method>s.by(0)`.'
63
63
  MSG_COMPOUND = 'Prefer %<preferred>s with compound expectations ' \
64
- 'over `change.by(0)`.'
65
- RESTRICT_ON_SEND = %i[change].freeze
64
+ 'over `%<method>s.by(0)`.'
65
+ CHANGE_METHODS = Set[:change, :a_block_changing, :changing].freeze
66
+ RESTRICT_ON_SEND = CHANGE_METHODS.freeze
66
67
 
67
68
  # @!method expect_change_with_arguments(node)
68
69
  def_node_matcher :expect_change_with_arguments, <<-PATTERN
69
70
  (send
70
- (send nil? :change ...) :by
71
+ $(send nil? CHANGE_METHODS ...) :by
71
72
  (int 0))
72
73
  PATTERN
73
74
 
@@ -75,48 +76,61 @@ module RuboCop
75
76
  def_node_matcher :expect_change_with_block, <<-PATTERN
76
77
  (send
77
78
  (block
78
- (send nil? :change)
79
+ $(send nil? CHANGE_METHODS)
79
80
  (args)
80
- (send (...) $_)) :by
81
+ (send (...) _)) :by
81
82
  (int 0))
82
83
  PATTERN
83
84
 
84
85
  # @!method change_nodes(node)
85
86
  def_node_search :change_nodes, <<-PATTERN
86
- $(send nil? :change ...)
87
+ $(send nil? CHANGE_METHODS ...)
87
88
  PATTERN
88
89
 
89
90
  def on_send(node)
90
- expect_change_with_arguments(node.parent) do
91
- check_offense(node.parent)
91
+ expect_change_with_arguments(node.parent) do |change|
92
+ register_offense(node.parent, change)
92
93
  end
93
94
 
94
- expect_change_with_block(node.parent.parent) do
95
- check_offense(node.parent.parent)
95
+ expect_change_with_block(node.parent.parent) do |change|
96
+ register_offense(node.parent.parent, change)
96
97
  end
97
98
  end
98
99
 
99
100
  private
100
101
 
101
- def check_offense(node)
102
- expression = node.source_range
102
+ # rubocop:disable Metrics/MethodLength
103
+ def register_offense(node, change_node)
103
104
  if compound_expectations?(node)
104
- add_offense(expression, message: message_compound) do |corrector|
105
+ add_offense(node.source_range,
106
+ message: message_compound(change_node)) do |corrector|
105
107
  autocorrect_compound(corrector, node)
106
108
  end
107
109
  else
108
- add_offense(expression) do |corrector|
109
- autocorrect(corrector, node)
110
+ add_offense(node.source_range,
111
+ message: message(change_node)) do |corrector|
112
+ autocorrect(corrector, node, change_node)
110
113
  end
111
114
  end
112
115
  end
116
+ # rubocop:enable Metrics/MethodLength
113
117
 
114
118
  def compound_expectations?(node)
115
119
  %i[and or & |].include?(node.parent.method_name)
116
120
  end
117
121
 
118
- def autocorrect(corrector, node)
122
+ def message(change_node)
123
+ format(MSG, method: change_node.method_name)
124
+ end
125
+
126
+ def message_compound(change_node)
127
+ format(MSG_COMPOUND, preferred: preferred_method,
128
+ method: change_node.method_name)
129
+ end
130
+
131
+ def autocorrect(corrector, node, change_node)
119
132
  corrector.replace(node.parent.loc.selector, 'not_to')
133
+ corrector.replace(change_node.loc.selector, 'change')
120
134
  range = node.loc.dot.with(end_pos: node.source_range.end_pos)
121
135
  corrector.remove(range)
122
136
  end
@@ -135,10 +149,6 @@ module RuboCop
135
149
  cop_config['NegatedMatcher']
136
150
  end
137
151
 
138
- def message_compound
139
- format(MSG_COMPOUND, preferred: preferred_method)
140
- end
141
-
142
152
  def preferred_method
143
153
  negated_matcher ? "`#{negated_matcher}`" : 'negated matchers'
144
154
  end
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # Checks that spec file paths are consistent and well-formed.
7
7
  #
8
8
  # By default, this checks that spec file paths are consistent with the
9
- # test subject and and enforces that it reflects the described
9
+ # test subject and enforces that it reflects the described
10
10
  # class/module and its optionally called out method.
11
11
  #
12
12
  # With the configuration option `IgnoreMethods` the called out method will
@@ -56,19 +56,24 @@ module RuboCop
56
56
 
57
57
  private
58
58
 
59
- INDEX_REGEX = /_?\d+/.freeze
59
+ SUFFIX_INDEX_REGEX = /_?\d+$/.freeze
60
+ INDEX_REGEX = /\d+/.freeze
60
61
 
61
62
  def filter_indexed_lets(candidates)
62
63
  candidates
63
64
  .filter { |node| indexed_let?(node) }
64
- .group_by { |node| let_name(node).to_s.gsub(INDEX_REGEX, '') }
65
+ .group_by { |node| let_name_stripped_index(node) }
65
66
  .values
66
67
  .filter { |lets| lets.length > cop_config['Max'] }
67
68
  .flatten
68
69
  end
69
70
 
70
71
  def indexed_let?(node)
71
- let?(node) && INDEX_REGEX.match?(let_name(node))
72
+ let?(node) && SUFFIX_INDEX_REGEX.match?(let_name(node))
73
+ end
74
+
75
+ def let_name_stripped_index(node)
76
+ let_name(node).to_s.gsub(INDEX_REGEX, '')
72
77
  end
73
78
  end
74
79
  end
@@ -34,7 +34,7 @@ module RuboCop
34
34
  PATTERN
35
35
 
36
36
  def on_send(node)
37
- return unless node.first_argument.array_type?
37
+ return unless node.first_argument&.array_type?
38
38
  return if match_array_with_empty_array?(node)
39
39
 
40
40
  check_populated_array(node)
@@ -18,7 +18,7 @@ module RuboCop
18
18
  extend AutoCorrector
19
19
 
20
20
  MSG =
21
- 'Prefer `expect(response).%<to>s have_http_status(%<status>i)` ' \
21
+ 'Prefer `expect(response).%<to>s have_http_status(%<status>s)` ' \
22
22
  'over `%<bad_code>s`.'
23
23
 
24
24
  RUNNERS = %i[to to_not not_to].to_set
@@ -37,12 +37,14 @@ module RuboCop
37
37
 
38
38
  def on_send(node)
39
39
  match_status(node) do |response_status, to, match, status|
40
+ return unless status.to_s.match?(/\A\d+\z/)
41
+
40
42
  message = format(MSG, to: to, status: status,
41
43
  bad_code: node.source)
42
44
  add_offense(node, message: message) do |corrector|
43
45
  corrector.replace(response_status, 'response')
44
46
  corrector.replace(match.loc.selector, 'have_http_status')
45
- corrector.replace(match.first_argument, status.to_i.to_s)
47
+ corrector.replace(match.first_argument, status.to_s)
46
48
  end
47
49
  end
48
50
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec 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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec
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
  - John Backus
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-04-18 00:00:00.000000000 Z
13
+ date: 2023-05-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -222,14 +222,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
222
  requirements:
223
223
  - - ">="
224
224
  - !ruby/object:Gem::Version
225
- version: 2.6.0
225
+ version: 2.7.0
226
226
  required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  requirements:
228
228
  - - ">="
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements: []
232
- rubygems_version: 3.4.10
232
+ rubygems_version: 3.4.12
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: Code style checking for RSpec files