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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41302972abfb2a785a3a9fcffb8b9b229d34d8182125f75cc34062720ef7262c
4
- data.tar.gz: ac07370e67a54572895b3d49c5992da0521aa474de7e9e47d3b998a740b9f087
3
+ metadata.gz: 8f8b9af448980183de77764548e3b31c6e402816213fdeb8700a9ab619b2703a
4
+ data.tar.gz: b534ee269ff21655204b2eeb2397703f3c378c34c0e0c3d4702b59c2f96afb2d
5
5
  SHA512:
6
- metadata.gz: 05fccfbdc29de4b5f0dda00caa7a30528068e98e665ba6ace777d1531c968dedce672c429226b4c0c5c167d986b0fcfb9ead8d7244ea359abd27b1edc8d15b3b
7
- data.tar.gz: 07a7d923cc6f06c0b9df3ede1de081b23ea116d1bba328faf9529fe6b2174d691ab1c99ea3f6eaa175d8e762e7b61b2c1dc34457cbe5d6ace012b58a0be83066
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.36.0)
4
+ sevencop (0.37.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.36.0'
4
+ VERSION = '0.37.0'
5
5
  end
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.36.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-27 00:00:00.000000000 Z
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