sevencop 0.42.1 → 0.43.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: d6458ef2aecd8e03654e70a76fc22ff59d2dd509f1eb377f65977b363dd3d43c
4
- data.tar.gz: 8566e27a40c3eb6bd51ae2afa1f592758641a18019492d599cf7c95e811465b1
3
+ metadata.gz: 27ef12a9d73af780d2df174d7f5e76a7c882a364310a90de25a5b74a7f805c89
4
+ data.tar.gz: 41b9ec3b0ba6639bd6b12b60da6d70cd7c7ded19f35bb1d97527ec98ecdaeca3
5
5
  SHA512:
6
- metadata.gz: ca075075040e44c561fed97593c321375f831a5d034deb7a4c7e1510efbe70d2623196d901546123c453abce3a8c3aa3bc198041cd85d9ff8d671c1ff03dceea
7
- data.tar.gz: b38e408140a08a3a173c8700ecc6006950666a9f0d77fd9858e8110fc7676bfa9878c07d6bbfdba40fba039b35d9cf5d001704af77a646e16d91e79ae44dc9a2
6
+ metadata.gz: f96546be70eefad0cc889efdf726aabd3417db9e3e29af83e2961f8066bff6cfa1974b6f058c2c96a9366a6e7309441c34139cc50f716fd05ee92fc6673ffdde
7
+ data.tar.gz: 278fbde7bc95f4a592f5e249aafb16f22874b75961e85336d814dd4726f446165058682ac3acfb9318add398841c1a81e6bdbb47a3024ee76bc53721ab3420a9
data/.rubocop.yml CHANGED
@@ -42,6 +42,7 @@ RSpec/FilePath:
42
42
  RSpecMatcherConsistentParentheses: rspec_matcher_consistent_parentheses
43
43
  RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
44
44
  RSpecRailsHaveHttpStatus: rspec_rails_have_http_status
45
+ RSpecRailsStatusCodeCheckBySubject: rspec_rails_status_code_check_by_subject
45
46
 
46
47
  RSpec/MultipleExpectations:
47
48
  Enabled: false
@@ -54,6 +55,7 @@ RSpec/SpecFilePathFormat:
54
55
  RSpecMatcherConsistentParentheses: rspec_matcher_consistent_parentheses
55
56
  RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
56
57
  RSpecRailsHaveHttpStatus: rspec_rails_have_http_status
58
+ RSpecRailsStatusCodeCheckBySubject: rspec_rails_status_code_check_by_subject
57
59
 
58
60
  Sevencop/AutoloadOrdered:
59
61
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.42.1)
4
+ sevencop (0.43.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.1.3.2)
11
+ activesupport (7.1.3.3)
12
12
  base64
13
13
  bigdecimal
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -29,7 +29,7 @@ GEM
29
29
  concurrent-ruby (~> 1.0)
30
30
  json (2.7.1)
31
31
  language_server-protocol (3.17.0.3)
32
- minitest (5.22.3)
32
+ minitest (5.23.1)
33
33
  mutex_m (0.2.0)
34
34
  parallel (1.24.0)
35
35
  parser (3.3.0.5)
data/README.md CHANGED
@@ -50,6 +50,7 @@ Note that all cops are `Enabled: false` by default.
50
50
  - [Sevencop/RSpecMatcherConsistentParentheses](lib/rubocop/cop/sevencop/rspec_matcher_consistent_parentheses.rb)
51
51
  - [Sevencop/RSpecMemoizedHelperBlockDelimiter](lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb)
52
52
  - [Sevencop/RSpecRailsHaveHttpStatus](lib/rubocop/cop/sevencop/rspec_rails_have_http_status.rb)
53
+ - [Sevencop/RSpecRailsStatusCodeCheckBySubject](lib/rubocop/cop/sevencop/rspec_rails_status_code_check_by_subject.rb)
53
54
 
54
55
  ## Notes
55
56
 
data/config/default.yml CHANGED
@@ -149,3 +149,11 @@ Sevencop/RSpecRailsHaveHttpStatus:
149
149
  Include:
150
150
  - "**/spec/controllers/**/*.rb"
151
151
  - "**/spec/requests/**/*.rb"
152
+
153
+ Sevencop/RSpecRailsStatusCodeCheckBySubject:
154
+ Description: |
155
+ Use `expect(response).to have_http_status(code)` instead of `is_expected.to eq(code)`.
156
+ Enabled: false
157
+ Include:
158
+ - "**/spec/controllers/**/*.rb"
159
+ - "**/spec/requests/**/*.rb"
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sevencop
6
+ # Use `expect(response).to have_http_status(code)` instead of `is_expected.to eq(code)`.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # is_expected.to eq(200)
11
+ #
12
+ # # good
13
+ # expect(response).to have_http_status(200)
14
+ #
15
+ # # bad
16
+ # is_expected.to eq(:ok)
17
+ #
18
+ # # good
19
+ # expect(response).to have_http_status(:ok)
20
+ class RSpecRailsStatusCodeCheckBySubject < Base
21
+ extend AutoCorrector
22
+
23
+ MSG = 'Use `expect(response).to have_http_status(code)` instead of `is_expected.to eq(code)`.'
24
+
25
+ RESTRICT_ON_SEND = %i[
26
+ to
27
+ ].freeze
28
+
29
+ # @param [RuboCop::AST::SendNode] node
30
+ # @return [void]
31
+ def on_send(node)
32
+ return unless is_expected_to_eq_code?(node)
33
+
34
+ add_offense(node) do |corrector|
35
+ corrector.insert_before(node, "subject\n")
36
+ corrector.replace(node.receiver, 'expect(response)')
37
+ corrector.replace(node.first_argument.location.selector, 'have_http_status')
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ # @!method is_expected_to_eq_code?(node)
44
+ # @param [RuboCop::AST::SendNode] node
45
+ # @return [Boolean]
46
+ def_node_matcher :is_expected_to_eq_code?, <<~PATTERN
47
+ (send (send nil? :is_expected) :to (send nil? :eq {int sym}))
48
+ PATTERN
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.42.1'
4
+ VERSION = '0.43.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -26,3 +26,4 @@ require_relative 'rubocop/cop/sevencop/rspec_examples_in_same_group'
26
26
  require_relative 'rubocop/cop/sevencop/rspec_matcher_consistent_parentheses'
27
27
  require_relative 'rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter'
28
28
  require_relative 'rubocop/cop/sevencop/rspec_rails_have_http_status'
29
+ require_relative 'rubocop/cop/sevencop/rspec_rails_status_code_check_by_subject'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevencop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.42.1
4
+ version: 0.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-13 00:00:00.000000000 Z
11
+ date: 2024-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -78,6 +78,7 @@ files:
78
78
  - lib/rubocop/cop/sevencop/rspec_matcher_consistent_parentheses.rb
79
79
  - lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb
80
80
  - lib/rubocop/cop/sevencop/rspec_rails_have_http_status.rb
81
+ - lib/rubocop/cop/sevencop/rspec_rails_status_code_check_by_subject.rb
81
82
  - lib/sevencop.rb
82
83
  - lib/sevencop/config_loader.rb
83
84
  - lib/sevencop/cop_concerns.rb