rubocop-rspec_rails 2.31.0 → 2.32.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: a532f361a0657a600a657dd22a2344028ce648996179c8c4df27ea29302537ac
4
- data.tar.gz: f7d10a791b1c5ee7d6a4444ee15eea12622cec6ecfd2174fafe037d37651a6bb
3
+ metadata.gz: 6a750fc4e562218ed87ba5242d34797589b5df5598ad0cac33799546bf2a0230
4
+ data.tar.gz: 76e8e5c35753d371fa4fd4fdb41ced69adb33c2168d0232f6b2ba5f73a82b5da
5
5
  SHA512:
6
- metadata.gz: 976d9b3320ea2923c627597dc7cffb0e0f212ea16430084e60c53345093cebc4dff74e28ee7730900e0955920e2f7fee8f7206c4b583731d9cc58d5c67d67688
7
- data.tar.gz: 657c590a5cb85f4f3b97b08f5dfc57409b07392db055ea1f0e2f7a04e78cd6d9920ca21f298c5d9c3120dc971776fb5429213d576cb91e4ae85713da704dc30a
6
+ metadata.gz: 8929c0661a8c342e41d652597c24549eefef4a3fad2ad566588df2bae35aeed79d68c44ea2a1d7270ee91d089c698095889e41b3f9012b3cddad2fadba6a4d48
7
+ data.tar.gz: a4a1dfde481062a1d2445100d753bfb66df082537c0157a2189ba6af9ab4f5dd8a459561278db7e2b80c434009455b908927549f201a7aa692f66fc4b28f1adc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.32.0 (2025-11-12)
6
+
7
+ - Add `RSpecRails/HttpStatusNameConsistency` cop. ([@taketo1113])
8
+ - Support correcting `assert_response` assertion in in `RSpec/Rails/MinitestAssertions`. ([@nzlaura])
9
+
5
10
  ## 2.31.0 (2025-03-10)
6
11
 
7
12
  - Handle unknown HTTP status codes for `RSpecRails/HttpStatus` cop. ([@viralpraxis])
@@ -82,10 +87,12 @@
82
87
  [@jojos003]: https://github.com/jojos003
83
88
  [@mothonmars]: https://github.com/MothOnMars
84
89
  [@mvz]: https://github.com/mvz
90
+ [@nzlaura]: https://github.com/nzlaura
85
91
  [@paydaylight]: https://github.com/paydaylight
86
92
  [@pirj]: https://github.com/pirj
87
93
  [@r7kamura]: https://github.com/r7kamura
88
94
  [@splattael]: https://github.com/splattael
95
+ [@taketo1113]: https://github.com/taketo1113
89
96
  [@tmaier]: https://github.com/tmaier
90
97
  [@viralpraxis]: https://github.com/viralpraxis
91
98
  [@ydah]: https://github.com/ydah
data/config/default.yml CHANGED
@@ -35,6 +35,12 @@ RSpecRails/HttpStatus:
35
35
  VersionChanged: '2.20'
36
36
  Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HttpStatus
37
37
 
38
+ RSpecRails/HttpStatusNameConsistency:
39
+ Description: Enforces consistency by using the current HTTP status names.
40
+ Enabled: pending
41
+ VersionAdded: '2.32'
42
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HttpStatusNameConsistency
43
+
38
44
  RSpecRails/InferredSpecType:
39
45
  Description: Identifies redundant spec type.
40
46
  Enabled: pending
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpecRails
6
+ # Enforces consistency by using the current HTTP status names.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # it { is_expected.to have_http_status :unprocessable_entity }
12
+ #
13
+ # # good
14
+ # it { is_expected.to have_http_status :unprocessable_content }
15
+ #
16
+ class HttpStatusNameConsistency < ::RuboCop::Cop::Base
17
+ extend AutoCorrector
18
+
19
+ requires_gem 'rack', '>= 3.1.0'
20
+
21
+ MSG = 'Use `Prefer `:%<preferred>s` over `:%<current>s`.'
22
+
23
+ RESTRICT_ON_SEND = %i[have_http_status].freeze
24
+
25
+ PREFERRED_STATUSES = {
26
+ unprocessable_entity: :unprocessable_content,
27
+ payload_too_large: :content_too_large
28
+ }.freeze
29
+
30
+ # @!method http_status(node)
31
+ def_node_matcher :http_status, <<~PATTERN
32
+ (send nil? :have_http_status ${sym})
33
+ PATTERN
34
+
35
+ def on_send(node)
36
+ http_status(node) do |arg|
37
+ check_status_name_consistency(arg)
38
+ end
39
+ end
40
+ alias on_csend on_send
41
+
42
+ private
43
+
44
+ def check_status_name_consistency(node)
45
+ return unless node.sym_type? && PREFERRED_STATUSES.key?(node.value)
46
+
47
+ current_status = node.value
48
+ preferred_status = PREFERRED_STATUSES[current_status]
49
+
50
+ message = format(MSG, current: current_status,
51
+ preferred: preferred_status)
52
+
53
+ add_offense(node, message: message) do |corrector|
54
+ corrector.replace(node, ":#{preferred_status}")
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -18,6 +18,7 @@ module RuboCop
18
18
  # refute_empty(b)
19
19
  # assert_true(a)
20
20
  # assert_false(a)
21
+ # assert_response :ok
21
22
  #
22
23
  # # good
23
24
  # expect(b).to eq(a)
@@ -28,6 +29,7 @@ module RuboCop
28
29
  # expect(a).not_to be_empty
29
30
  # expect(a).to be(true)
30
31
  # expect(a).to be(false)
32
+ # expect(response).to have_http_status(:ok)
31
33
  #
32
34
  class MinitestAssertions < ::RuboCop::Cop::Base
33
35
  extend AutoCorrector
@@ -315,6 +317,28 @@ module RuboCop
315
317
  end
316
318
  end
317
319
 
320
+ # :nodoc:
321
+ class ResponseAssertion < BasicAssertion
322
+ MATCHERS = %i[
323
+ assert_response
324
+ ].freeze
325
+
326
+ ASSERT_ACTUAL_NODE = Struct.new(:source).new('response')
327
+
328
+ # @!method self.minitest_assertion(node)
329
+ def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective
330
+ (send nil? {:assert_response} $_ $_?)
331
+ PATTERN
332
+
333
+ def self.match(expected, failure_message)
334
+ new(expected, ASSERT_ACTUAL_NODE, failure_message.first)
335
+ end
336
+
337
+ def assertion
338
+ "have_http_status(#{expected})"
339
+ end
340
+ end
341
+
318
342
  MSG = 'Use `%<prefer>s`.'
319
343
 
320
344
  # TODO: replace with `BasicAssertion.subclasses` in Ruby 3.1+
@@ -3,6 +3,7 @@
3
3
  require_relative 'rspec_rails/avoid_setup_hook'
4
4
  require_relative 'rspec_rails/have_http_status'
5
5
  require_relative 'rspec_rails/http_status'
6
+ require_relative 'rspec_rails/http_status_name_consistency'
6
7
  require_relative 'rspec_rails/inferred_spec_type'
7
8
  require_relative 'rspec_rails/minitest_assertions'
8
9
  require_relative 'rspec_rails/negation_be_valid'
@@ -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.31.0'
7
+ STRING = '2.32.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_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.31.0
4
+ version: 2.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Quorning
@@ -10,7 +10,7 @@ authors:
10
10
  - Yudai Takada
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-03-10 00:00:00.000000000 Z
13
+ date: 1980-01-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: lint_roller
@@ -78,6 +78,7 @@ files:
78
78
  - lib/rubocop/cop/rspec_rails/avoid_setup_hook.rb
79
79
  - lib/rubocop/cop/rspec_rails/have_http_status.rb
80
80
  - lib/rubocop/cop/rspec_rails/http_status.rb
81
+ - lib/rubocop/cop/rspec_rails/http_status_name_consistency.rb
81
82
  - lib/rubocop/cop/rspec_rails/inferred_spec_type.rb
82
83
  - lib/rubocop/cop/rspec_rails/minitest_assertions.rb
83
84
  - lib/rubocop/cop/rspec_rails/negation_be_valid.rb
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubygems_version: 3.6.2
114
+ rubygems_version: 3.6.9
114
115
  specification_version: 4
115
116
  summary: Code style checking for RSpec Rails files
116
117
  test_files: []