rubocop-rspec_rails 2.30.0 → 2.31.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: 63cc745325cc4d3036a64bb2978b54cef08693ab2be90cfe0c36bb9a3c6df8cb
4
- data.tar.gz: 23bb17ac8270e87d87b7d010e3b76f0b77445b319a4b0b8255b082eed6ca9188
3
+ metadata.gz: a532f361a0657a600a657dd22a2344028ce648996179c8c4df27ea29302537ac
4
+ data.tar.gz: f7d10a791b1c5ee7d6a4444ee15eea12622cec6ecfd2174fafe037d37651a6bb
5
5
  SHA512:
6
- metadata.gz: 2df5e064355ce4bdc2e00d2124d6a85d76006b0dd1f8234a6bbe4e1045c750dd5a6963f040978226c040cce52be31dc6d2eb3950213043103417fd4a371a18b2
7
- data.tar.gz: 04371c175f87e01088652c46485b1a41a4e263291bd76eb79adcdae57881691d377984f4e3814be01cdef34f9f3594f554939c8ec728b93792ce1670879f6e17
6
+ metadata.gz: 976d9b3320ea2923c627597dc7cffb0e0f212ea16430084e60c53345093cebc4dff74e28ee7730900e0955920e2f7fee8f7206c4b583731d9cc58d5c67d67688
7
+ data.tar.gz: 657c590a5cb85f4f3b97b08f5dfc57409b07392db055ea1f0e2f7a04e78cd6d9920ca21f298c5d9c3120dc971776fb5429213d576cb91e4ae85713da704dc30a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.31.0 (2025-03-10)
6
+
7
+ - Handle unknown HTTP status codes for `RSpecRails/HttpStatus` cop. ([@viralpraxis])
8
+ - Fix a false negative for `RSpecRails/TravelAround` cop when passed as a proc to a travel method. ([@ydah])
9
+ - Make RuboCop RSpecRails work as a RuboCop plugin. ([@bquorning])
10
+
5
11
  ## 2.30.0 (2024-06-12)
6
12
 
7
13
  - Fix an runtime error for rubocop-rspec +3.0. ([@bquorning])
@@ -81,4 +87,5 @@
81
87
  [@r7kamura]: https://github.com/r7kamura
82
88
  [@splattael]: https://github.com/splattael
83
89
  [@tmaier]: https://github.com/tmaier
90
+ [@viralpraxis]: https://github.com/viralpraxis
84
91
  [@ydah]: https://github.com/ydah
data/README.md CHANGED
@@ -33,13 +33,13 @@ ways to do this:
33
33
  Put this into your `.rubocop.yml`.
34
34
 
35
35
  ```yaml
36
- require: rubocop-rspec_rails
36
+ plugins: rubocop-rspec_rails
37
37
  ```
38
38
 
39
39
  Alternatively, use the following array notation when specifying multiple extensions.
40
40
 
41
41
  ```yaml
42
- require:
42
+ plugins:
43
43
  - rubocop-rspec
44
44
  - rubocop-rspec_rails
45
45
  ```
@@ -47,17 +47,20 @@ require:
47
47
  Now you can run `rubocop` and it will automatically load the RuboCop RSpec Rails
48
48
  cops together with the standard cops.
49
49
 
50
+ > [!NOTE]
51
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
52
+
50
53
  ### Command line
51
54
 
52
55
  ```bash
53
- rubocop --require rubocop-rspec_rails
56
+ rubocop --plugin rubocop-rspec_rails
54
57
  ```
55
58
 
56
59
  ### Rake task
57
60
 
58
61
  ```ruby
59
62
  RuboCop::RakeTask.new do |task|
60
- task.requires << 'rubocop-rspec_rails'
63
+ task.plugins << 'rubocop-rspec_rails'
61
64
  end
62
65
  ```
63
66
 
@@ -15,6 +15,7 @@ module RuboCop
15
15
  # So, this cop does not check if a method starting with `be_*` is used
16
16
  # when setting for `EnforcedStyle: symbolic` or
17
17
  # `EnforcedStyle: numeric`.
18
+ # This cop is also capable of detecting unknown HTTP status codes.
18
19
  #
19
20
  # @example `EnforcedStyle: symbolic` (default)
20
21
  # # bad
@@ -57,6 +58,12 @@ module RuboCop
57
58
  # it { is_expected.to have_http_status :success }
58
59
  # it { is_expected.to have_http_status :error }
59
60
  #
61
+ # @example
62
+ # # bad
63
+ # it { is_expected.to have_http_status :oki_doki }
64
+ #
65
+ # # good
66
+ # it { is_expected.to have_http_status :ok }
60
67
  class HttpStatus < ::RuboCop::Cop::Base
61
68
  extend AutoCorrector
62
69
  include ConfigurableEnforcedStyle
@@ -67,7 +74,7 @@ module RuboCop
67
74
  (send nil? :have_http_status ${int sym str})
68
75
  PATTERN
69
76
 
70
- def on_send(node)
77
+ def on_send(node) # rubocop:disable Metrics/MethodLength
71
78
  return unless defined?(::Rack::Utils::SYMBOL_TO_STATUS_CODE)
72
79
 
73
80
  http_status(node) do |arg|
@@ -78,6 +85,8 @@ module RuboCop
78
85
 
79
86
  add_offense(checker.offense_range,
80
87
  message: checker.message) do |corrector|
88
+ next unless checker.autocorrectable?
89
+
81
90
  corrector.replace(checker.offense_range, checker.prefer)
82
91
  end
83
92
  end
@@ -93,6 +102,10 @@ module RuboCop
93
102
  NumericStyleChecker
94
103
  when :be_status
95
104
  BeStatusStyleChecker
105
+ else
106
+ # :nocov:
107
+ :noop
108
+ # :nocov:
96
109
  end
97
110
  end
98
111
 
@@ -100,6 +113,7 @@ module RuboCop
100
113
  class StyleCheckerBase
101
114
  MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
102
115
  'to describe HTTP status code.'
116
+ MSG_UNKNOWN_STATUS_CODE = 'Unknown status code.'
103
117
  ALLOWED_STATUSES = %i[error success missing redirect].freeze
104
118
 
105
119
  attr_reader :node
@@ -109,7 +123,11 @@ module RuboCop
109
123
  end
110
124
 
111
125
  def message
112
- format(MSG, prefer: prefer, current: current)
126
+ if autocorrectable?
127
+ format(MSG, prefer: prefer, current: current)
128
+ else
129
+ MSG_UNKNOWN_STATUS_CODE
130
+ end
113
131
  end
114
132
 
115
133
  def current
@@ -136,6 +154,10 @@ module RuboCop
136
154
  !node.sym_type? && !custom_http_status_code?
137
155
  end
138
156
 
157
+ def autocorrectable?
158
+ !!symbol
159
+ end
160
+
139
161
  def prefer
140
162
  symbol.inspect
141
163
  end
@@ -157,6 +179,10 @@ module RuboCop
157
179
  !node.int_type? && !allowed_symbol?
158
180
  end
159
181
 
182
+ def autocorrectable?
183
+ !!number
184
+ end
185
+
160
186
  def prefer
161
187
  number.to_s
162
188
  end
@@ -179,22 +205,30 @@ module RuboCop
179
205
  (!node.int_type? && !allowed_symbol?)
180
206
  end
181
207
 
208
+ def autocorrectable?
209
+ !!status_code
210
+ end
211
+
182
212
  def offense_range
183
213
  node.parent
184
214
  end
185
215
 
186
216
  def prefer
217
+ "be_#{status_code}"
218
+ end
219
+
220
+ private
221
+
222
+ def status_code
187
223
  if node.sym_type?
188
- "be_#{node.value}"
224
+ node.value
189
225
  elsif node.int_type?
190
- "be_#{symbol}"
191
- elsif node.str_type?
192
- "be_#{normalize_str}"
226
+ symbol
227
+ else
228
+ normalize_str
193
229
  end
194
230
  end
195
231
 
196
- private
197
-
198
232
  def symbol
199
233
  ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(number)
200
234
  end
@@ -207,7 +241,7 @@ module RuboCop
207
241
  str = node.value.to_s
208
242
  if str.match?(/\A\d+\z/)
209
243
  ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(str.to_i)
210
- else
244
+ elsif ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key?(str.to_sym)
211
245
  str
212
246
  end
213
247
  end
@@ -93,6 +93,7 @@ module RuboCop
93
93
 
94
94
  # @param [RuboCop::AST::Node] node
95
95
  # @return [Parser::Source::Range]
96
+ # rubocop:disable Metrics/MethodLength
96
97
  def remove_range(node)
97
98
  if node.left_sibling
98
99
  node.source_range.with(
@@ -102,8 +103,13 @@ module RuboCop
102
103
  node.source_range.with(
103
104
  end_pos: node.right_sibling.source_range.begin_pos
104
105
  )
106
+ else
107
+ # :nocov:
108
+ :noop
109
+ # :nocov:
105
110
  end
106
111
  end
112
+ # rubocop:enable Metrics/MethodLength
107
113
 
108
114
  # @param [RuboCop::AST::PairNode] node
109
115
  # @return [RuboCop::AST::Node]
@@ -39,7 +39,9 @@ module RuboCop
39
39
  attr_reader :expected, :actual, :failure_message
40
40
 
41
41
  def self.minitest_assertion
42
+ # :nocov:
42
43
  raise NotImplementedError
44
+ # :nocov:
43
45
  end
44
46
 
45
47
  def initialize(expected, actual, failure_message)
@@ -62,7 +64,9 @@ module RuboCop
62
64
  end
63
65
 
64
66
  def assertion
67
+ # :nocov:
65
68
  raise NotImplementedError
69
+ # :nocov:
66
70
  end
67
71
  end
68
72
 
@@ -64,6 +64,10 @@ module RuboCop
64
64
  be_invalid?(node)
65
65
  when :be_invalid
66
66
  not_to?(node)
67
+ else
68
+ # :nocov:
69
+ :noop
70
+ # :nocov:
67
71
  end
68
72
  end
69
73
 
@@ -81,6 +85,10 @@ module RuboCop
81
85
  'not_to'
82
86
  when :be_invalid
83
87
  'to'
88
+ else
89
+ # :nocov:
90
+ :noop
91
+ # :nocov:
84
92
  end
85
93
  end
86
94
 
@@ -90,6 +98,10 @@ module RuboCop
90
98
  'be_valid'
91
99
  when :be_invalid
92
100
  'be_invalid'
101
+ else
102
+ # :nocov:
103
+ :noop
104
+ # :nocov:
93
105
  end
94
106
  end
95
107
  end
@@ -21,8 +21,14 @@ module RuboCop
21
21
  # end
22
22
  # end
23
23
  #
24
+ # # bad
25
+ # around do |example|
26
+ # freeze_time(&example)
27
+ # end
28
+ #
24
29
  # # good
25
30
  # before { freeze_time }
31
+ #
26
32
  class TravelAround < ::RuboCop::Cop::Base
27
33
  extend AutoCorrector
28
34
 
@@ -43,6 +49,13 @@ module RuboCop
43
49
  )
44
50
  PATTERN
45
51
 
52
+ # @!method extract_travel_with_block_pass(node)
53
+ def_node_search :extract_travel_with_block_pass, <<~PATTERN
54
+ $(send _ TRAVEL_METHOD_NAMES
55
+ (block_pass $lvar)
56
+ )
57
+ PATTERN
58
+
46
59
  # @!method match_around_each?(node)
47
60
  def_node_matcher :match_around_each?, <<~PATTERN
48
61
  (block
@@ -52,29 +65,39 @@ module RuboCop
52
65
  PATTERN
53
66
 
54
67
  def on_block(node)
55
- run_node = extract_run_in_travel(node)
56
- return unless run_node
68
+ extract_run_in_travel(node) do |run_node|
69
+ run_in_travel(node, run_node)
70
+ end
71
+ extract_travel_with_block_pass(node) do |travel_node, lvar|
72
+ travel_with_block_pass(travel_node, lvar)
73
+ end
74
+ end
75
+ alias on_numblock on_block
76
+
77
+ private
57
78
 
79
+ def run_in_travel(node, run_node)
58
80
  around_node = extract_surrounding_around_block(run_node)
59
81
  return unless around_node
60
82
 
61
83
  add_offense(node) do |corrector|
62
- autocorrect(corrector, node, run_node, around_node)
84
+ corrector.replace(node, node.body.source)
85
+ corrector.insert_before(around_node,
86
+ "before { #{run_node.source} }\n\n")
63
87
  end
64
88
  end
65
- alias on_numblock on_block
66
89
 
67
- private
90
+ def travel_with_block_pass(node, lvar)
91
+ around_node = extract_surrounding_around_block(node)
92
+ return unless around_node
68
93
 
69
- def autocorrect(corrector, node, run_node, around_node)
70
- corrector.replace(
71
- node,
72
- node.body.source
73
- )
74
- corrector.insert_before(
75
- around_node,
76
- "before { #{run_node.source} }\n\n"
77
- )
94
+ add_offense(node) do |corrector|
95
+ corrector.replace(node, "#{lvar.name}.run")
96
+ corrector.insert_before(
97
+ around_node,
98
+ "before { #{node.method_name} }\n\n"
99
+ )
100
+ end
78
101
  end
79
102
 
80
103
  # @param node [RuboCop::AST::BlockNode]
@@ -57,8 +57,8 @@ module RuboCop
57
57
  end
58
58
 
59
59
  def cop_subclass?
60
- yardoc.superclass.path == RSPEC_RAILS_COP_CLASS_NAME ||
61
- yardoc.superclass.path == RUBOCOP_COP_CLASS_NAME
60
+ [RSPEC_RAILS_COP_CLASS_NAME,
61
+ RUBOCOP_COP_CLASS_NAME].include?(yardoc.superclass.path)
62
62
  end
63
63
 
64
64
  def abstract?
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module RSpecRails
7
+ # A plugin that integrates RuboCop RSpecRails with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ # :nocov:
10
+ def about
11
+ LintRoller::About.new(
12
+ name: 'rubocop-rspec_rails',
13
+ version: Version::STRING,
14
+ homepage: 'https://github.com/rubocop/rubocop-rspec_rails',
15
+ description: 'Code style checking for RSpec Rails files.'
16
+ )
17
+ end
18
+ # :nocov:
19
+
20
+ def supported?(context)
21
+ context.engine == :rubocop
22
+ end
23
+
24
+ def rules(_context)
25
+ project_root = Pathname.new(__dir__).join('../../..')
26
+
27
+ LintRoller::Rules.new(
28
+ type: :path,
29
+ config_format: :rubocop,
30
+ value: project_root.join('config/default.yml')
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpecRails
5
5
  # Version information for the RSpec Rails RuboCop plugin.
6
6
  module Version
7
- STRING = '2.30.0'
7
+ STRING = '2.31.0'
8
8
  end
9
9
  end
10
10
  end
@@ -6,27 +6,8 @@ require 'yaml'
6
6
  require 'rubocop'
7
7
  require 'rubocop/rspec/language'
8
8
 
9
+ require_relative 'rubocop/rspec_rails/plugin'
9
10
  require_relative 'rubocop/rspec_rails/version'
10
11
 
11
12
  require 'rubocop/cop/rspec/base'
12
13
  require_relative 'rubocop/cop/rspec_rails_cops'
13
-
14
- project_root = File.join(__dir__, '..')
15
- RuboCop::ConfigLoader.inject_defaults!(project_root)
16
-
17
- # FIXME: This is a workaround for the following issue:
18
- # https://github.com/rubocop/rubocop-rspec_rails/issues/8
19
- module RuboCop
20
- module Cop
21
- class Registry # rubocop:disable Style/Documentation
22
- prepend(Module.new do
23
- def qualified_cop_name(name, path, warn: true)
24
- return super unless name == 'RSpec/Rails/HttpStatus'
25
-
26
- badge = Badge.parse(name)
27
- resolve_badge(badge, qualify_badge(badge).first, path)
28
- end
29
- end)
30
- end
31
- end
32
- end
metadata CHANGED
@@ -1,56 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.30.0
4
+ version: 2.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Quorning
8
8
  - Phil Pirozhkov
9
9
  - Maxim Krizhanovsky
10
10
  - Yudai Takada
11
- autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2024-06-11 00:00:00.000000000 Z
13
+ date: 2025-03-10 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
- name: rubocop
16
+ name: lint_roller
18
17
  requirement: !ruby/object:Gem::Requirement
19
18
  requirements:
20
19
  - - "~>"
21
20
  - !ruby/object:Gem::Version
22
- version: '1.61'
21
+ version: '1.1'
23
22
  type: :runtime
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - "~>"
28
27
  - !ruby/object:Gem::Version
29
- version: '1.61'
28
+ version: '1.1'
30
29
  - !ruby/object:Gem::Dependency
31
- name: rubocop-rspec
30
+ name: rubocop
32
31
  requirement: !ruby/object:Gem::Requirement
33
32
  requirements:
34
33
  - - "~>"
35
34
  - !ruby/object:Gem::Version
36
- version: '3'
35
+ version: '1.72'
37
36
  - - ">="
38
37
  - !ruby/object:Gem::Version
39
- version: 3.0.1
38
+ version: 1.72.1
40
39
  type: :runtime
41
40
  prerelease: false
42
41
  version_requirements: !ruby/object:Gem::Requirement
43
42
  requirements:
44
43
  - - "~>"
45
44
  - !ruby/object:Gem::Version
46
- version: '3'
45
+ version: '1.72'
47
46
  - - ">="
48
47
  - !ruby/object:Gem::Version
49
- version: 3.0.1
48
+ version: 1.72.1
49
+ - !ruby/object:Gem::Dependency
50
+ name: rubocop-rspec
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.5'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.5'
50
63
  description: |
51
64
  Code style checking for RSpec Rails files.
52
65
  A plugin for the RuboCop code style enforcing & linting tool.
53
- email:
54
66
  executables: []
55
67
  extensions: []
56
68
  extra_rdoc_files:
@@ -74,6 +86,7 @@ files:
74
86
  - lib/rubocop/rspec_rails/config_formatter.rb
75
87
  - lib/rubocop/rspec_rails/cop/generator.rb
76
88
  - lib/rubocop/rspec_rails/description_extractor.rb
89
+ - lib/rubocop/rspec_rails/plugin.rb
77
90
  - lib/rubocop/rspec_rails/version.rb
78
91
  homepage: https://github.com/rubocop/rubocop-rspec_rails
79
92
  licenses:
@@ -82,7 +95,7 @@ metadata:
82
95
  changelog_uri: https://github.com/rubocop/rubocop-rspec_rails/blob/master/CHANGELOG.md
83
96
  documentation_uri: https://docs.rubocop.org/rubocop-rspec_rails/
84
97
  rubygems_mfa_required: 'true'
85
- post_install_message:
98
+ default_lint_roller_plugin: RuboCop::RSpecRails::Plugin
86
99
  rdoc_options: []
87
100
  require_paths:
88
101
  - lib
@@ -97,8 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
110
  - !ruby/object:Gem::Version
98
111
  version: '0'
99
112
  requirements: []
100
- rubygems_version: 3.5.9
101
- signing_key:
113
+ rubygems_version: 3.6.2
102
114
  specification_version: 4
103
115
  summary: Code style checking for RSpec Rails files
104
116
  test_files: []