rubocop-rspec 2.15.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +1 -1
- data/config/default.yml +54 -16
- data/lib/rubocop/cop/rspec/be.rb +2 -0
- data/lib/rubocop/cop/rspec/be_eq.rb +3 -0
- data/lib/rubocop/cop/rspec/be_eql.rb +3 -0
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +3 -3
- data/lib/rubocop/cop/rspec/capybara/match_style.rb +60 -0
- data/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/specific_actions.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +3 -5
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +1 -1
- data/lib/rubocop/cop/rspec/context_wording.rb +0 -1
- data/lib/rubocop/cop/rspec/duplicated_metadata.rb +58 -0
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +2 -0
- data/lib/rubocop/cop/rspec/expect_actual.rb +2 -0
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +5 -3
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +9 -2
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +74 -0
- data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -0
- data/lib/rubocop/cop/rspec/leading_subject.rb +2 -2
- data/lib/rubocop/cop/rspec/message_spies.rb +2 -0
- data/lib/rubocop/cop/rspec/mixin/metadata.rb +49 -0
- data/lib/rubocop/cop/rspec/pending_without_reason.rb +121 -0
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +4 -1
- data/lib/rubocop/cop/rspec/rails/have_http_status.rb +5 -2
- data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +1 -1
- data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +60 -0
- data/lib/rubocop/cop/rspec/scattered_setup.rb +2 -0
- data/lib/rubocop/cop/rspec/sort_metadata.rb +4 -35
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +3 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +0 -1
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -0
- data/lib/rubocop/cop/rspec_cops.rb +5 -0
- data/lib/rubocop/rspec/config_formatter.rb +2 -2
- data/lib/rubocop/rspec/description_extractor.rb +5 -10
- data/lib/rubocop/rspec/language.rb +6 -2
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop-rspec.rb +18 -13
- metadata +9 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module RSpec
|
|
6
|
+
# Helper methods to find RSpec metadata.
|
|
7
|
+
module Metadata
|
|
8
|
+
extend RuboCop::NodePattern::Macros
|
|
9
|
+
|
|
10
|
+
include RuboCop::RSpec::Language
|
|
11
|
+
|
|
12
|
+
# @!method rspec_metadata(node)
|
|
13
|
+
def_node_matcher :rspec_metadata, <<~PATTERN
|
|
14
|
+
(block
|
|
15
|
+
(send
|
|
16
|
+
#rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all} _ ${send str sym}* (hash $...)?)
|
|
17
|
+
...)
|
|
18
|
+
PATTERN
|
|
19
|
+
|
|
20
|
+
# @!method rspec_configure(node)
|
|
21
|
+
def_node_matcher :rspec_configure, <<~PATTERN
|
|
22
|
+
(block (send #rspec? :configure) (args (arg $_)) ...)
|
|
23
|
+
PATTERN
|
|
24
|
+
|
|
25
|
+
# @!method metadata_in_block(node)
|
|
26
|
+
def_node_search :metadata_in_block, <<~PATTERN
|
|
27
|
+
(send (lvar %) #Hooks.all _ ${send str sym}* (hash $...)?)
|
|
28
|
+
PATTERN
|
|
29
|
+
|
|
30
|
+
def on_block(node)
|
|
31
|
+
rspec_configure(node) do |block_var|
|
|
32
|
+
metadata_in_block(node, block_var) do |symbols, pairs|
|
|
33
|
+
on_metadata(symbols, pairs.flatten)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
rspec_metadata(node) do |symbols, pairs|
|
|
38
|
+
on_metadata(symbols, pairs.flatten)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
alias on_numblock on_block
|
|
42
|
+
|
|
43
|
+
def on_metadata(_symbols, _pairs)
|
|
44
|
+
raise ::NotImplementedError
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module RSpec
|
|
6
|
+
# Checks for pending or skipped examples without reason.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# # bad
|
|
10
|
+
# pending 'does something' do
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
# # bad
|
|
14
|
+
# it 'does something', :pending do
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# # bad
|
|
18
|
+
# it 'does something' do
|
|
19
|
+
# pending
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# # bad
|
|
23
|
+
# xdescribe 'something' do
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# # bad
|
|
27
|
+
# skip 'does something' do
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
# # bad
|
|
31
|
+
# it 'does something', :skip do
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# # bad
|
|
35
|
+
# it 'does something' do
|
|
36
|
+
# skip
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# # bad
|
|
40
|
+
# it 'does something'
|
|
41
|
+
#
|
|
42
|
+
# # good
|
|
43
|
+
# it 'does something' do
|
|
44
|
+
# pending 'reason'
|
|
45
|
+
# end
|
|
46
|
+
#
|
|
47
|
+
# # good
|
|
48
|
+
# it 'does something' do
|
|
49
|
+
# skip 'reason'
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# # good
|
|
53
|
+
# it 'does something', pending: 'reason' do
|
|
54
|
+
# end
|
|
55
|
+
#
|
|
56
|
+
# # good
|
|
57
|
+
# it 'does something', skip: 'reason' do
|
|
58
|
+
# end
|
|
59
|
+
class PendingWithoutReason < Base
|
|
60
|
+
MSG = 'Give the reason for pending or skip.'
|
|
61
|
+
|
|
62
|
+
# @!method pending_by_example_method?(node)
|
|
63
|
+
def_node_matcher :pending_by_example_method?, block_pattern(<<~PATTERN)
|
|
64
|
+
#Examples.pending
|
|
65
|
+
PATTERN
|
|
66
|
+
|
|
67
|
+
# @!method pending_by_metadata_without_reason?(node)
|
|
68
|
+
def_node_matcher :pending_by_metadata_without_reason?, <<~PATTERN
|
|
69
|
+
(send #rspec? {#ExampleGroups.all #Examples.all} ... {<(sym :pending) ...> (hash <(pair (sym :pending) true) ...>)})
|
|
70
|
+
PATTERN
|
|
71
|
+
|
|
72
|
+
# @!method skipped_by_example_method?(node)
|
|
73
|
+
def_node_matcher :skipped_by_example_method?, block_pattern(<<~PATTERN)
|
|
74
|
+
#Examples.skipped
|
|
75
|
+
PATTERN
|
|
76
|
+
|
|
77
|
+
# @!method skipped_by_example_group_method?(node)
|
|
78
|
+
def_node_matcher(
|
|
79
|
+
:skipped_by_example_group_method?,
|
|
80
|
+
block_pattern(<<~PATTERN)
|
|
81
|
+
#ExampleGroups.skipped
|
|
82
|
+
PATTERN
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# @!method skipped_by_metadata_without_reason?(node)
|
|
86
|
+
def_node_matcher :skipped_by_metadata_without_reason?, <<~PATTERN
|
|
87
|
+
(send #rspec? {#ExampleGroups.all #Examples.all} ... {<(sym :skip) ...> (hash <(pair (sym :skip) true) ...>)})
|
|
88
|
+
PATTERN
|
|
89
|
+
|
|
90
|
+
# @!method without_reason?(node)
|
|
91
|
+
def_node_matcher :without_reason?, <<~PATTERN
|
|
92
|
+
(send nil? ${:pending :skip})
|
|
93
|
+
PATTERN
|
|
94
|
+
|
|
95
|
+
def on_send(node)
|
|
96
|
+
if pending_without_reason?(node)
|
|
97
|
+
add_offense(node, message: 'Give the reason for pending.')
|
|
98
|
+
elsif skipped_without_reason?(node)
|
|
99
|
+
add_offense(node, message: 'Give the reason for skip.')
|
|
100
|
+
elsif without_reason?(node) && example?(node.parent)
|
|
101
|
+
add_offense(node,
|
|
102
|
+
message: "Give the reason for #{node.method_name}.")
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private
|
|
107
|
+
|
|
108
|
+
def pending_without_reason?(node)
|
|
109
|
+
pending_by_example_method?(node.block_node) ||
|
|
110
|
+
pending_by_metadata_without_reason?(node)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def skipped_without_reason?(node)
|
|
114
|
+
skipped_by_example_group_method?(node.block_node) ||
|
|
115
|
+
skipped_by_example_method?(node.block_node) ||
|
|
116
|
+
skipped_by_metadata_without_reason?(node)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -179,7 +179,8 @@ module RuboCop
|
|
|
179
179
|
|
|
180
180
|
return false if allowed_explicit_matchers.include?(name)
|
|
181
181
|
|
|
182
|
-
name.start_with?('be_', 'have_') && !name.end_with?('?')
|
|
182
|
+
name.start_with?('be_', 'have_') && !name.end_with?('?') ||
|
|
183
|
+
%w[include respond_to].include?(name)
|
|
183
184
|
end
|
|
184
185
|
|
|
185
186
|
def message_explicit(matcher)
|
|
@@ -283,6 +284,8 @@ module RuboCop
|
|
|
283
284
|
include InflectedHelper
|
|
284
285
|
include ExplicitHelper
|
|
285
286
|
|
|
287
|
+
RESTRICT_ON_SEND = Runners.all
|
|
288
|
+
|
|
286
289
|
def on_send(node)
|
|
287
290
|
case style
|
|
288
291
|
when :inflected
|
|
@@ -13,20 +13,23 @@ module RuboCop
|
|
|
13
13
|
# # good
|
|
14
14
|
# expect(response).to have_http_status(200)
|
|
15
15
|
#
|
|
16
|
-
class HaveHttpStatus < Base
|
|
16
|
+
class HaveHttpStatus < ::RuboCop::Cop::Base
|
|
17
17
|
extend AutoCorrector
|
|
18
18
|
|
|
19
19
|
MSG =
|
|
20
20
|
'Prefer `expect(response).%<to>s have_http_status(%<status>i)` ' \
|
|
21
21
|
'over `expect(response.status).%<to>s %<match>s`.'
|
|
22
22
|
|
|
23
|
+
RUNNERS = %i[to to_not not_to].to_set
|
|
24
|
+
RESTRICT_ON_SEND = RUNNERS
|
|
25
|
+
|
|
23
26
|
# @!method match_status(node)
|
|
24
27
|
def_node_matcher :match_status, <<-PATTERN
|
|
25
28
|
(send
|
|
26
29
|
(send nil? :expect
|
|
27
30
|
$(send (send nil? :response) :status)
|
|
28
31
|
)
|
|
29
|
-
|
|
32
|
+
$RUNNERS
|
|
30
33
|
$(send nil? {:be :eq :eql :equal} (int $_))
|
|
31
34
|
)
|
|
32
35
|
PATTERN
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module RSpec
|
|
6
|
+
module Rails
|
|
7
|
+
# Check if using Minitest matchers.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# # bad
|
|
11
|
+
# assert_equal(a, b)
|
|
12
|
+
# assert_equal a, b, "must be equal"
|
|
13
|
+
# refute_equal(a, b)
|
|
14
|
+
#
|
|
15
|
+
# # good
|
|
16
|
+
# expect(a).to eq(b)
|
|
17
|
+
# expect(a).to(eq(b), "must be equal")
|
|
18
|
+
# expect(a).not_to eq(b)
|
|
19
|
+
#
|
|
20
|
+
class MinitestAssertions < Base
|
|
21
|
+
extend AutoCorrector
|
|
22
|
+
|
|
23
|
+
MSG = 'Use `%<prefer>s`.'
|
|
24
|
+
RESTRICT_ON_SEND = %i[assert_equal refute_equal].freeze
|
|
25
|
+
|
|
26
|
+
# @!method minitest_assertion(node)
|
|
27
|
+
def_node_matcher :minitest_assertion, <<-PATTERN
|
|
28
|
+
(send nil? {:assert_equal :refute_equal} $_ $_ $_?)
|
|
29
|
+
PATTERN
|
|
30
|
+
|
|
31
|
+
def on_send(node)
|
|
32
|
+
minitest_assertion(node) do |expected, actual, failure_message|
|
|
33
|
+
prefer = replacement(node, expected, actual,
|
|
34
|
+
failure_message.first)
|
|
35
|
+
add_offense(node, message: message(prefer)) do |corrector|
|
|
36
|
+
corrector.replace(node, prefer)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def replacement(node, expected, actual, failure_message)
|
|
44
|
+
runner = node.method?(:assert_equal) ? 'to' : 'not_to'
|
|
45
|
+
if failure_message.nil?
|
|
46
|
+
"expect(#{expected.source}).#{runner} eq(#{actual.source})"
|
|
47
|
+
else
|
|
48
|
+
"expect(#{expected.source}).#{runner}(eq(#{actual.source}), " \
|
|
49
|
+
"#{failure_message.source})"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def message(prefer)
|
|
54
|
+
format(MSG, prefer: prefer)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -18,45 +18,12 @@ module RuboCop
|
|
|
18
18
|
#
|
|
19
19
|
class SortMetadata < Base
|
|
20
20
|
extend AutoCorrector
|
|
21
|
+
include Metadata
|
|
21
22
|
include RangeHelp
|
|
22
23
|
|
|
23
24
|
MSG = 'Sort metadata alphabetically.'
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
def_node_matcher :rspec_metadata, <<~PATTERN
|
|
27
|
-
(block
|
|
28
|
-
(send
|
|
29
|
-
#rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all} _ ${send str sym}* (hash $...)?)
|
|
30
|
-
...)
|
|
31
|
-
PATTERN
|
|
32
|
-
|
|
33
|
-
# @!method rspec_configure(node)
|
|
34
|
-
def_node_matcher :rspec_configure, <<~PATTERN
|
|
35
|
-
(block (send #rspec? :configure) (args (arg $_)) ...)
|
|
36
|
-
PATTERN
|
|
37
|
-
|
|
38
|
-
# @!method metadata_in_block(node)
|
|
39
|
-
def_node_search :metadata_in_block, <<~PATTERN
|
|
40
|
-
(send (lvar %) #Hooks.all _ ${send str sym}* (hash $...)?)
|
|
41
|
-
PATTERN
|
|
42
|
-
|
|
43
|
-
def on_block(node)
|
|
44
|
-
rspec_configure(node) do |block_var|
|
|
45
|
-
metadata_in_block(node, block_var) do |symbols, pairs|
|
|
46
|
-
investigate(symbols, pairs.flatten)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
rspec_metadata(node) do |symbols, pairs|
|
|
51
|
-
investigate(symbols, pairs.flatten)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
alias on_numblock on_block
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
def investigate(symbols, pairs)
|
|
26
|
+
def on_metadata(symbols, pairs)
|
|
60
27
|
return if sorted?(symbols, pairs)
|
|
61
28
|
|
|
62
29
|
crime_scene = crime_scene(symbols, pairs)
|
|
@@ -65,6 +32,8 @@ module RuboCop
|
|
|
65
32
|
end
|
|
66
33
|
end
|
|
67
34
|
|
|
35
|
+
private
|
|
36
|
+
|
|
68
37
|
def crime_scene(symbols, pairs)
|
|
69
38
|
metadata = symbols + pairs
|
|
70
39
|
|
|
@@ -91,7 +91,7 @@ module RuboCop
|
|
|
91
91
|
# @param node [RuboCop::AST::Node]
|
|
92
92
|
# @yield [RuboCop::AST::Node] matcher
|
|
93
93
|
def_node_matcher :matcher_with_return_block, <<~PATTERN
|
|
94
|
-
(block #message_expectation? args _) # receive(:foo) { 'bar' }
|
|
94
|
+
(block #message_expectation? (args) _) # receive(:foo) { 'bar' }
|
|
95
95
|
PATTERN
|
|
96
96
|
|
|
97
97
|
# @!method matcher_with_hash(node)
|
|
@@ -133,6 +133,8 @@ module RuboCop
|
|
|
133
133
|
}
|
|
134
134
|
PATTERN
|
|
135
135
|
|
|
136
|
+
RESTRICT_ON_SEND = %i[to].freeze
|
|
137
|
+
|
|
136
138
|
def on_send(node)
|
|
137
139
|
expectation(node, &method(:on_expectation))
|
|
138
140
|
end
|
|
@@ -12,7 +12,6 @@ module RuboCop
|
|
|
12
12
|
#
|
|
13
13
|
# @see https://robots.thoughtbot.com/don-t-stub-the-system-under-test
|
|
14
14
|
# @see https://penelope.zone/2015/12/27/introducing-rspec-smells-and-where-to-find-them.html#smell-1-stubjec
|
|
15
|
-
# @see https://github.com/rubocop-hq/rspec-style-guide#dont-stub-subject
|
|
16
15
|
#
|
|
17
16
|
# @example
|
|
18
17
|
# # bad
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'rspec/capybara/current_path_expectation'
|
|
4
4
|
require_relative 'rspec/capybara/feature_methods'
|
|
5
|
+
require_relative 'rspec/capybara/match_style'
|
|
5
6
|
require_relative 'rspec/capybara/negation_matcher'
|
|
6
7
|
require_relative 'rspec/capybara/specific_actions'
|
|
7
8
|
require_relative 'rspec/capybara/specific_finders'
|
|
@@ -12,6 +13,7 @@ require_relative 'rspec/factory_bot/attribute_defined_statically'
|
|
|
12
13
|
require_relative 'rspec/factory_bot/consistent_parentheses_style'
|
|
13
14
|
require_relative 'rspec/factory_bot/create_list'
|
|
14
15
|
require_relative 'rspec/factory_bot/factory_class_name'
|
|
16
|
+
require_relative 'rspec/factory_bot/factory_name_style'
|
|
15
17
|
require_relative 'rspec/factory_bot/syntax_methods'
|
|
16
18
|
|
|
17
19
|
require_relative 'rspec/rails/avoid_setup_hook'
|
|
@@ -22,6 +24,7 @@ rescue LoadError
|
|
|
22
24
|
# Rails/HttpStatus cannot be loaded if rack/utils is unavailable.
|
|
23
25
|
end
|
|
24
26
|
require_relative 'rspec/rails/inferred_spec_type'
|
|
27
|
+
require_relative 'rspec/rails/minitest_assertions'
|
|
25
28
|
|
|
26
29
|
require_relative 'rspec/align_left_let_brace'
|
|
27
30
|
require_relative 'rspec/align_right_let_brace'
|
|
@@ -42,6 +45,7 @@ require_relative 'rspec/describe_symbol'
|
|
|
42
45
|
require_relative 'rspec/described_class'
|
|
43
46
|
require_relative 'rspec/described_class_module_wrapping'
|
|
44
47
|
require_relative 'rspec/dialect'
|
|
48
|
+
require_relative 'rspec/duplicated_metadata'
|
|
45
49
|
require_relative 'rspec/empty_example_group'
|
|
46
50
|
require_relative 'rspec/empty_hook'
|
|
47
51
|
require_relative 'rspec/empty_line_after_example'
|
|
@@ -87,6 +91,7 @@ require_relative 'rspec/no_expectation_example'
|
|
|
87
91
|
require_relative 'rspec/not_to_not'
|
|
88
92
|
require_relative 'rspec/overwriting_setup'
|
|
89
93
|
require_relative 'rspec/pending'
|
|
94
|
+
require_relative 'rspec/pending_without_reason'
|
|
90
95
|
require_relative 'rspec/predicate_matcher'
|
|
91
96
|
require_relative 'rspec/receive_counts'
|
|
92
97
|
require_relative 'rspec/receive_never'
|
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
|
9
9
|
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
|
|
10
10
|
SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
|
|
11
11
|
AMENDMENTS = %(Metrics/BlockLength)
|
|
12
|
-
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/
|
|
12
|
+
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/'
|
|
13
13
|
|
|
14
14
|
def initialize(config, descriptions)
|
|
15
15
|
@config = config
|
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def reference(cop)
|
|
50
|
-
COP_DOC_BASE_URL + cop
|
|
50
|
+
COP_DOC_BASE_URL + cop
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
attr_reader :config, :descriptions
|
|
@@ -21,7 +21,8 @@ module RuboCop
|
|
|
21
21
|
|
|
22
22
|
# Decorator of a YARD code object for working with documented rspec cops
|
|
23
23
|
class CodeObject
|
|
24
|
-
|
|
24
|
+
RSPEC_COP_CLASS_NAME = 'RuboCop::Cop::RSpec::Base'
|
|
25
|
+
RUBOCOP_COP_CLASS_NAME = 'RuboCop::Cop::Base'
|
|
25
26
|
RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec'
|
|
26
27
|
|
|
27
28
|
def initialize(yardoc)
|
|
@@ -32,10 +33,7 @@ module RuboCop
|
|
|
32
33
|
#
|
|
33
34
|
# @return [Boolean]
|
|
34
35
|
def rspec_cop?
|
|
35
|
-
|
|
36
|
-
rspec_cop_namespace? &&
|
|
37
|
-
cop_subclass? &&
|
|
38
|
-
!abstract?
|
|
36
|
+
cop_subclass? && !abstract? && rspec_cop_namespace?
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
# Configuration for the documented cop that would live in default.yml
|
|
@@ -55,10 +53,6 @@ module RuboCop
|
|
|
55
53
|
yardoc.docstring.split("\n\n").first.to_s
|
|
56
54
|
end
|
|
57
55
|
|
|
58
|
-
def class_documentation?
|
|
59
|
-
yardoc.type.equal?(:class)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
56
|
def rspec_cop_namespace?
|
|
63
57
|
documented_constant.start_with?(RSPEC_NAMESPACE)
|
|
64
58
|
end
|
|
@@ -68,7 +62,8 @@ module RuboCop
|
|
|
68
62
|
end
|
|
69
63
|
|
|
70
64
|
def cop_subclass?
|
|
71
|
-
yardoc.superclass.path ==
|
|
65
|
+
yardoc.superclass.path == RSPEC_COP_CLASS_NAME ||
|
|
66
|
+
yardoc.superclass.path == RUBOCOP_COP_CLASS_NAME
|
|
72
67
|
end
|
|
73
68
|
|
|
74
69
|
def abstract?
|
|
@@ -160,8 +160,12 @@ module RuboCop
|
|
|
160
160
|
|
|
161
161
|
module Runners # :nodoc:
|
|
162
162
|
ALL = %i[to to_not not_to].freeze
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
class << self
|
|
164
|
+
def all(element = nil)
|
|
165
|
+
return ALL if element.nil?
|
|
166
|
+
|
|
167
|
+
ALL.include?(element)
|
|
168
|
+
end
|
|
165
169
|
end
|
|
166
170
|
end
|
|
167
171
|
|
data/lib/rubocop-rspec.rb
CHANGED
|
@@ -6,34 +6,39 @@ require 'yaml'
|
|
|
6
6
|
require 'rubocop'
|
|
7
7
|
|
|
8
8
|
require_relative 'rubocop/rspec'
|
|
9
|
-
require_relative 'rubocop/rspec/version'
|
|
10
9
|
require_relative 'rubocop/rspec/inject'
|
|
10
|
+
require_relative 'rubocop/rspec/language/node_pattern'
|
|
11
11
|
require_relative 'rubocop/rspec/node'
|
|
12
|
+
require_relative 'rubocop/rspec/version'
|
|
12
13
|
require_relative 'rubocop/rspec/wording'
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
# Dependent on `RuboCop::RSpec::Language::NodePattern`.
|
|
14
16
|
require_relative 'rubocop/rspec/language'
|
|
15
17
|
|
|
16
18
|
require_relative 'rubocop/rspec/factory_bot/language'
|
|
17
19
|
|
|
18
|
-
require_relative 'rubocop/cop/rspec/mixin/
|
|
19
|
-
require_relative 'rubocop/cop/rspec/mixin/
|
|
20
|
+
require_relative 'rubocop/cop/rspec/mixin/capybara_help'
|
|
21
|
+
require_relative 'rubocop/cop/rspec/mixin/css_selector'
|
|
20
22
|
require_relative 'rubocop/cop/rspec/mixin/final_end_location'
|
|
21
|
-
require_relative 'rubocop/cop/rspec/mixin/comments_help'
|
|
22
|
-
require_relative 'rubocop/cop/rspec/mixin/empty_line_separation'
|
|
23
23
|
require_relative 'rubocop/cop/rspec/mixin/inside_example_group'
|
|
24
|
+
require_relative 'rubocop/cop/rspec/mixin/metadata'
|
|
24
25
|
require_relative 'rubocop/cop/rspec/mixin/namespace'
|
|
25
|
-
require_relative 'rubocop/cop/rspec/mixin/css_selector'
|
|
26
26
|
require_relative 'rubocop/cop/rspec/mixin/skip_or_pending'
|
|
27
|
-
require_relative 'rubocop/cop/rspec/mixin/
|
|
27
|
+
require_relative 'rubocop/cop/rspec/mixin/top_level_group'
|
|
28
|
+
require_relative 'rubocop/cop/rspec/mixin/variable'
|
|
29
|
+
|
|
30
|
+
# Dependent on `RuboCop::Cop::RSpec::FinalEndLocation`.
|
|
31
|
+
require_relative 'rubocop/cop/rspec/mixin/comments_help'
|
|
32
|
+
require_relative 'rubocop/cop/rspec/mixin/empty_line_separation'
|
|
28
33
|
|
|
29
|
-
require_relative 'rubocop/rspec/concept'
|
|
30
|
-
require_relative 'rubocop/rspec/example_group'
|
|
31
|
-
require_relative 'rubocop/rspec/example'
|
|
32
|
-
require_relative 'rubocop/rspec/hook'
|
|
33
34
|
require_relative 'rubocop/cop/rspec/base'
|
|
34
35
|
require_relative 'rubocop/rspec/align_let_brace'
|
|
35
|
-
require_relative 'rubocop/rspec/
|
|
36
|
+
require_relative 'rubocop/rspec/concept'
|
|
36
37
|
require_relative 'rubocop/rspec/corrector/move_node'
|
|
38
|
+
require_relative 'rubocop/rspec/example'
|
|
39
|
+
require_relative 'rubocop/rspec/example_group'
|
|
40
|
+
require_relative 'rubocop/rspec/factory_bot'
|
|
41
|
+
require_relative 'rubocop/rspec/hook'
|
|
37
42
|
|
|
38
43
|
RuboCop::RSpec::Inject.defaults!
|
|
39
44
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-rspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Backus
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rubocop
|
|
@@ -58,6 +58,7 @@ files:
|
|
|
58
58
|
- lib/rubocop/cop/rspec/before_after_all.rb
|
|
59
59
|
- lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
|
|
60
60
|
- lib/rubocop/cop/rspec/capybara/feature_methods.rb
|
|
61
|
+
- lib/rubocop/cop/rspec/capybara/match_style.rb
|
|
61
62
|
- lib/rubocop/cop/rspec/capybara/negation_matcher.rb
|
|
62
63
|
- lib/rubocop/cop/rspec/capybara/specific_actions.rb
|
|
63
64
|
- lib/rubocop/cop/rspec/capybara/specific_finders.rb
|
|
@@ -73,6 +74,7 @@ files:
|
|
|
73
74
|
- lib/rubocop/cop/rspec/described_class.rb
|
|
74
75
|
- lib/rubocop/cop/rspec/described_class_module_wrapping.rb
|
|
75
76
|
- lib/rubocop/cop/rspec/dialect.rb
|
|
77
|
+
- lib/rubocop/cop/rspec/duplicated_metadata.rb
|
|
76
78
|
- lib/rubocop/cop/rspec/empty_example_group.rb
|
|
77
79
|
- lib/rubocop/cop/rspec/empty_hook.rb
|
|
78
80
|
- lib/rubocop/cop/rspec/empty_line_after_example.rb
|
|
@@ -92,6 +94,7 @@ files:
|
|
|
92
94
|
- lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb
|
|
93
95
|
- lib/rubocop/cop/rspec/factory_bot/create_list.rb
|
|
94
96
|
- lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb
|
|
97
|
+
- lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb
|
|
95
98
|
- lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb
|
|
96
99
|
- lib/rubocop/cop/rspec/file_path.rb
|
|
97
100
|
- lib/rubocop/cop/rspec/focus.rb
|
|
@@ -119,6 +122,7 @@ files:
|
|
|
119
122
|
- lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
|
|
120
123
|
- lib/rubocop/cop/rspec/mixin/final_end_location.rb
|
|
121
124
|
- lib/rubocop/cop/rspec/mixin/inside_example_group.rb
|
|
125
|
+
- lib/rubocop/cop/rspec/mixin/metadata.rb
|
|
122
126
|
- lib/rubocop/cop/rspec/mixin/namespace.rb
|
|
123
127
|
- lib/rubocop/cop/rspec/mixin/skip_or_pending.rb
|
|
124
128
|
- lib/rubocop/cop/rspec/mixin/top_level_group.rb
|
|
@@ -133,11 +137,13 @@ files:
|
|
|
133
137
|
- lib/rubocop/cop/rspec/not_to_not.rb
|
|
134
138
|
- lib/rubocop/cop/rspec/overwriting_setup.rb
|
|
135
139
|
- lib/rubocop/cop/rspec/pending.rb
|
|
140
|
+
- lib/rubocop/cop/rspec/pending_without_reason.rb
|
|
136
141
|
- lib/rubocop/cop/rspec/predicate_matcher.rb
|
|
137
142
|
- lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
|
|
138
143
|
- lib/rubocop/cop/rspec/rails/have_http_status.rb
|
|
139
144
|
- lib/rubocop/cop/rspec/rails/http_status.rb
|
|
140
145
|
- lib/rubocop/cop/rspec/rails/inferred_spec_type.rb
|
|
146
|
+
- lib/rubocop/cop/rspec/rails/minitest_assertions.rb
|
|
141
147
|
- lib/rubocop/cop/rspec/receive_counts.rb
|
|
142
148
|
- lib/rubocop/cop/rspec/receive_never.rb
|
|
143
149
|
- lib/rubocop/cop/rspec/repeated_description.rb
|
|
@@ -203,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
203
209
|
- !ruby/object:Gem::Version
|
|
204
210
|
version: '0'
|
|
205
211
|
requirements: []
|
|
206
|
-
rubygems_version: 3.
|
|
212
|
+
rubygems_version: 3.3.7
|
|
207
213
|
signing_key:
|
|
208
214
|
specification_version: 4
|
|
209
215
|
summary: Code style checking for RSpec files
|