sevencop 0.36.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/config/default.yml +8 -0
- data/lib/rubocop/cop/sevencop/rspec_rails_have_http_status.rb +66 -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: 8f8b9af448980183de77764548e3b31c6e402816213fdeb8700a9ab619b2703a
|
4
|
+
data.tar.gz: b534ee269ff21655204b2eeb2397703f3c378c34c0e0c3d4702b59c2f96afb2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7eeff888f7f8f708ef105d9842a9c16db91da60984076528f3c9d4e364bce4934bb04e5fe108c2af2841a1b71438dcad3d82afd963256613ff95adf6ecf95b3
|
7
|
+
data.tar.gz: a0a838e1f7ae5eb4c12a0bb30a327140cb5b4bddbfc1c5e089bc1fbc200e19144eab18a263fca11ab1574d9d2d4de4a735e62ee6e3787b6fc6cb96a50a59d648
|
data/.rubocop.yml
CHANGED
@@ -19,6 +19,7 @@ Layout/LineLength:
|
|
19
19
|
Lint/UselessAccessModifier:
|
20
20
|
MethodCreatingMethods:
|
21
21
|
- def_node_matcher
|
22
|
+
- def_node_search
|
22
23
|
|
23
24
|
Metrics:
|
24
25
|
Enabled: false
|
@@ -39,6 +40,7 @@ RSpec/FilePath:
|
|
39
40
|
RSpecEmptyLineAfterLet: rspec_empty_line_after_let
|
40
41
|
RSpecExamplesInSameGroup: rspec_examples_in_same_group
|
41
42
|
RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
|
43
|
+
RSpecRailsHaveHttpStatus: rspec_rails_have_http_status
|
42
44
|
|
43
45
|
RSpec/MultipleExpectations:
|
44
46
|
Enabled: false
|
@@ -49,6 +51,7 @@ RSpec/SpecFilePathFormat:
|
|
49
51
|
RSpecEmptyLineAfterLet: rspec_empty_line_after_let
|
50
52
|
RSpecExamplesInSameGroup: rspec_examples_in_same_group
|
51
53
|
RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
|
54
|
+
RSpecRailsHaveHttpStatus: rspec_rails_have_http_status
|
52
55
|
|
53
56
|
Sevencop/AutoloadOrdered:
|
54
57
|
Enabled: true
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -48,6 +48,7 @@ Note that all cops are `Enabled: false` by default.
|
|
48
48
|
- [Sevencop/RSpecEmptyLineAfterLet](lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb)
|
49
49
|
- [Sevencop/RSpecExamplesInSameGroup](lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb)
|
50
50
|
- [Sevencop/RSpecMemoizedHelperBlockDelimiter](lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb)
|
51
|
+
- [Sevencop/RSpecRailsHaveHttpStatus](lib/rubocop/cop/sevencop/rspec_rails_have_http_status.rb)
|
51
52
|
|
52
53
|
## Notes
|
53
54
|
|
data/config/default.yml
CHANGED
@@ -146,3 +146,11 @@ Sevencop/RSpecMemoizedHelperBlockDelimiter:
|
|
146
146
|
Enabled: false
|
147
147
|
Include:
|
148
148
|
- spec/**/*
|
149
|
+
|
150
|
+
Sevencop/RSpecRailsHaveHttpStatus:
|
151
|
+
Description: |
|
152
|
+
Always check status code with `have_http_status`.
|
153
|
+
Enabled: false
|
154
|
+
Include:
|
155
|
+
- spec/controllers/**/*
|
156
|
+
- spec/requests/**/*
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sevencop
|
6
|
+
# Always check status code with `have_http_status`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# it 'creates a new post' do
|
11
|
+
# expect { subject }.to change(Post, :count).by(1)
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# it 'creates a new post' do
|
16
|
+
# expect { subject }.to change(Post, :count).by(1)
|
17
|
+
# expect(response).to have_http_status(200)
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# it 'creates a new post' do
|
22
|
+
# expect { subject }.to change(Post, :count).by(1)
|
23
|
+
# expect(response).to redirect_to(posts_path)
|
24
|
+
# end
|
25
|
+
class RSpecRailsHaveHttpStatus < Base
|
26
|
+
MSG = 'Always check status code with `have_http_status`.'
|
27
|
+
|
28
|
+
EXAMPLE_METHOD_NAMES = %i[
|
29
|
+
example
|
30
|
+
it
|
31
|
+
specify
|
32
|
+
].to_set.freeze
|
33
|
+
|
34
|
+
STATUS_CHECK_METHOD_NAMES = %i[
|
35
|
+
have_http_status
|
36
|
+
redirect_to
|
37
|
+
].to_set.freeze
|
38
|
+
|
39
|
+
# @param [RuboCop::AST::BlockNode] node
|
40
|
+
# @return [void]
|
41
|
+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
42
|
+
return unless example_method?(node)
|
43
|
+
return if including_status_check_method?(node)
|
44
|
+
|
45
|
+
add_offense(node)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# @!method example_method?(node)
|
51
|
+
# @param [RuboCop::AST::BlockNode] node
|
52
|
+
# @return [Boolean]
|
53
|
+
def_node_matcher :example_method?, <<~PATTERN
|
54
|
+
(block (send nil? EXAMPLE_METHOD_NAMES ...) ...)
|
55
|
+
PATTERN
|
56
|
+
|
57
|
+
# @!method including_status_check_method?(node)
|
58
|
+
# @param [RuboCop::AST::BlockNode] node
|
59
|
+
# @return [Boolean]
|
60
|
+
def_node_search :including_status_check_method?, <<~PATTERN
|
61
|
+
(send nil? STATUS_CHECK_METHOD_NAMES ...)
|
62
|
+
PATTERN
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/sevencop/version.rb
CHANGED
data/lib/sevencop.rb
CHANGED
@@ -24,3 +24,4 @@ require_relative 'rubocop/cop/sevencop/rspec_describe_http_endpoint'
|
|
24
24
|
require_relative 'rubocop/cop/sevencop/rspec_empty_line_after_let'
|
25
25
|
require_relative 'rubocop/cop/sevencop/rspec_examples_in_same_group'
|
26
26
|
require_relative 'rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter'
|
27
|
+
require_relative 'rubocop/cop/sevencop/rspec_rails_have_http_status'
|
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.37.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-01
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb
|
77
77
|
- lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb
|
78
78
|
- lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb
|
79
|
+
- lib/rubocop/cop/sevencop/rspec_rails_have_http_status.rb
|
79
80
|
- lib/sevencop.rb
|
80
81
|
- lib/sevencop/config_loader.rb
|
81
82
|
- lib/sevencop/cop_concerns.rb
|