sevencop 0.42.0 → 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: 3948e119b6a873e0226f93921268a1120b1c0bd8067c6dd2eedf80cd449db92d
4
- data.tar.gz: bd864bf33c85003b21ac7a14dd88bfb581f383edc3f1b072d1b59f4b14739e9d
3
+ metadata.gz: 27ef12a9d73af780d2df174d7f5e76a7c882a364310a90de25a5b74a7f805c89
4
+ data.tar.gz: 41b9ec3b0ba6639bd6b12b60da6d70cd7c7ded19f35bb1d97527ec98ecdaeca3
5
5
  SHA512:
6
- metadata.gz: c25ad4ee15137b961661fc5ec92a3e930116c53fd19c01d28a5886448668c0307d30448b990367f3890d2bfc2f4c2aaafc4b1e5f9fb8143b8c54822071d5005e
7
- data.tar.gz: 2815ccf2f38067606967043985d1aa898c3220694a20098fc3e28fdb7ca5faa9456363579a69a5bc7decf4c3e61fe571ea4579f7115bcf71864194636fd5c4e0
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.0)
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
@@ -67,12 +67,16 @@ Sevencop/RailsRouteAs:
67
67
  Description: |
68
68
  Always use `as` option on routing methods.
69
69
  Enabled: false
70
+ Include:
71
+ - config/routes.rb
70
72
 
71
73
  Sevencop/RailsRouteOrdered:
72
74
  Description: |
73
75
  Sort routes by path and HTTP method.
74
76
  Enabled: false
75
77
  Safe: false
78
+ Include:
79
+ - config/routes.rb
76
80
 
77
81
  Sevencop/RailsSpecificActionName:
78
82
  Description: |
@@ -145,3 +149,11 @@ Sevencop/RSpecRailsHaveHttpStatus:
145
149
  Include:
146
150
  - "**/spec/controllers/**/*.rb"
147
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.0'
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.0
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