sevencop 0.42.1 → 0.43.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/Gemfile.lock +3 -3
- data/README.md +1 -0
- data/config/default.yml +9 -0
- data/lib/rubocop/cop/sevencop/rspec_rails_status_code_check_by_subject.rb +52 -0
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cfed8aa90917558e096385531b8d1b7f24794cb41b2153763fe1c217f0f84f7
|
4
|
+
data.tar.gz: 258f17c6bf2c728943af990aca94d21cdb41de6b8a0d227abfcf4c874fa63fe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56f863333bae7ab6cc68af8227a8177c2f7160ae40dbcf1f4a2cc5387014e0241cbfff0230fbc9295638bb60fd49511adbe25bf52a968a2b84a026504e6fd394
|
7
|
+
data.tar.gz: bbb45e0b9d173fed7c302973b807453f6b27ea42e00057633d70375f6fc949954b73c1f10434dfdc457e393147860e84b0a9062bae86295b278dbb810be2df18
|
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.
|
4
|
+
sevencop (0.43.1)
|
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.
|
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.
|
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,12 @@ 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"
|
160
|
+
Safe: false
|
@@ -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
|
data/lib/sevencop/version.rb
CHANGED
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.
|
4
|
+
version: 0.43.1
|
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-
|
11
|
+
date: 2024-05-29 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
|