sevencop 0.24.4 → 0.25.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: e9088cb86686701cb1c115190aeff24d1e4828ff5db228981edbcfbd0303b941
4
- data.tar.gz: a1ae55865f74bd7e4707be7df3d53964c622c048484f4e679e90fc7604383456
3
+ metadata.gz: 922dc5655a1c67a3c6cbe88b4f5b4ca72fc6a504acb678451ca2aece5a7ac0b8
4
+ data.tar.gz: f00c654f92a7c6a26e4b6514dbaf68adc3a0a6c62efd7f113740675b0104a53f
5
5
  SHA512:
6
- metadata.gz: a871f2e1ce6a83aa0e78a77f2445f73fffb33c4019fbb99f91cfc9bd717ad9fd46548322de8816dcc745113a1304bc0024ecacf28629a745e93612d1286f3d58
7
- data.tar.gz: 58765fd6530c476d4a3c411cce6373c3f9f42b804e4b91a6f5e6ac43fbb923ade08e538ccdf27c3d2b94da24a43feb33392e94841e25a33ac2e65e5f11d3017d
6
+ metadata.gz: 6f21bb92a5a4409c777ba0770728f2e03d9ddc3fcebd75f5204f628155b99dbbf25006f37af1f5fdd58742cdce53400e201708194d5db46da5a53d5a269bc004
7
+ data.tar.gz: 7c1ecca97ecacebad51e38ff1005e7c500586b85f6d4ee3de816dc3ddb846cd0faeca19520ca5dd1edf1f0296b94a6fc631a53deaf8bb4745021f4fdfccdb08c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.24.4)
4
+ sevencop (0.25.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
data/config/default.yml CHANGED
@@ -139,6 +139,7 @@ Sevencop/RSpecExamplesInSameGroup:
139
139
  Combine examples in the same groups in the time-consuming kinds of specs.
140
140
  Enabled: false
141
141
  VersionAdded: '0.17'
142
+ IncludeSharedExamples: false
142
143
  Include:
143
144
  - spec/controllers/**/*
144
145
  - spec/requests/**/*
@@ -6,7 +6,6 @@ module RuboCop
6
6
  # Combine examples in same group in the time-consuming kinds of specs.
7
7
  #
8
8
  # @example
9
- #
10
9
  # # bad
11
10
  # context 'when user is logged in' do
12
11
  # it 'returns 200' do
@@ -27,20 +26,42 @@ module RuboCop
27
26
  # end
28
27
  # end
29
28
  #
29
+ # # bad - IncludeSharedExamples: true
30
+ # context 'when user is logged in' do
31
+ # it 'returns 200' do
32
+ # subject
33
+ # expect(response).to have_http_status(200)
34
+ # end
35
+ #
36
+ # includes_examples 'creates Foo'
37
+ # end
30
38
  class RSpecExamplesInSameGroup < Base
31
- EXAMPLE_METHOD_NAMES_REGULAR = ::Set[
39
+ METHOD_NAMES_FOR_REGULAR_EXAMPLE = ::Set[
40
+ :example,
32
41
  :it,
33
42
  :its,
34
- :specify,
35
- :example,
36
43
  :scenario,
44
+ :specify
37
45
  ].freeze
38
46
 
47
+ METHOD_NAMES_FOR_SHARED_EXAMPLES = ::Set[
48
+ :include_examples,
49
+ :it_behaves_like,
50
+ :it_should_behave_like
51
+ ]
52
+
39
53
  MSG = 'Combine examples in the same group in the time-consuming kinds of specs.'
40
54
 
41
- # @param node [RuboCop::AST::BlockNode]
55
+ RESTRICT_ON_SEND = [
56
+ *METHOD_NAMES_FOR_REGULAR_EXAMPLE,
57
+ *METHOD_NAMES_FOR_SHARED_EXAMPLES
58
+ ].freeze
59
+
60
+ # @param node [RuboCop::AST::SendNode]
42
61
  # @return [void]
43
- def on_block(node)
62
+ def on_send(node)
63
+ node = node.block_node || node
64
+
44
65
  return unless example?(node)
45
66
 
46
67
  previous_sibling_example = previous_sibling_example_of(node)
@@ -48,27 +69,45 @@ module RuboCop
48
69
 
49
70
  add_offense(node)
50
71
  end
51
- alias on_numblock on_block
52
72
 
53
73
  private
54
74
 
55
- # @!method example?(node)
56
- # @param node [RuboCop::AST::Node]
57
- # @return [Boolean]
58
- def_node_matcher :example?, <<~PATTERN
59
- (block
60
- (send nil? EXAMPLE_METHOD_NAMES_REGULAR ...)
61
- ...
62
- )
63
- PATTERN
75
+ # @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
76
+ # @return [Boolean]
77
+ def example?(node)
78
+ if include_shared_examples?
79
+ regular_example?(node) || shared_example?(node)
80
+ else
81
+ regular_example?(node)
82
+ end
83
+ end
84
+
85
+ # @return [Boolean]
86
+ def include_shared_examples?
87
+ cop_config['IncludeSharedExamples']
88
+ end
64
89
 
65
- # @param node [RuboCop::AST::BlockNode]
66
- # @return [RuboCop::AST::BlockNode, nil]
90
+ # @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
91
+ # @return [RuboCop::AST::BlockNode, RuboCop::AST::SendNode, nil]
67
92
  def previous_sibling_example_of(node)
93
+ return unless node.parent&.begin_type?
94
+
68
95
  node.left_siblings.find do |sibling|
69
96
  sibling.is_a?(::RuboCop::AST::Node) && example?(sibling)
70
97
  end
71
98
  end
99
+
100
+ # @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
101
+ # @return [Boolean]
102
+ def regular_example?(node)
103
+ METHOD_NAMES_FOR_REGULAR_EXAMPLE.include?(node.method_name)
104
+ end
105
+
106
+ # @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
107
+ # @return [Boolean]
108
+ def shared_example?(node)
109
+ METHOD_NAMES_FOR_SHARED_EXAMPLES.include?(node.method_name)
110
+ end
72
111
  end
73
112
  end
74
113
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.24.4'
4
+ VERSION = '0.25.0'
5
5
  end
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.24.4
4
+ version: 0.25.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: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2022-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport