rubocop-rspec 2.29.2 → 3.0.5
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 +50 -0
- data/README.md +14 -1
- data/config/default.yml +62 -264
- data/config/obsoletion.yml +15 -21
- data/lib/rubocop/cop/rspec/base.rb +0 -1
- data/lib/rubocop/cop/rspec/dialect.rb +13 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
- data/lib/rubocop/cop/rspec/indexed_let.rb +4 -3
- data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
- data/lib/rubocop/cop/rspec/metadata_style.rb +1 -6
- data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +4 -4
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +4 -5
- data/lib/rubocop/cop/rspec/named_subject.rb +5 -2
- data/lib/rubocop/cop/rspec/nested_groups.rb +2 -1
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +8 -4
- data/lib/rubocop/cop/rspec/remove_const.rb +0 -1
- data/lib/rubocop/cop/rspec/scattered_setup.rb +7 -1
- data/lib/rubocop/cop/rspec/sort_metadata.rb +1 -1
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +3 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +2 -2
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +20 -15
- data/lib/rubocop/cop/rspec_cops.rb +2 -25
- data/lib/rubocop/rspec/concept.rb +0 -1
- data/lib/rubocop/rspec/config_formatter.rb +1 -24
- data/lib/rubocop/rspec/cop/generator.rb +25 -0
- data/lib/rubocop/rspec/language.rb +0 -1
- data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop/rspec/wording.rb +2 -2
- data/lib/rubocop-rspec.rb +1 -17
- metadata +8 -70
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +0 -39
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +0 -104
- data/lib/rubocop/cop/rspec/capybara/match_style.rb +0 -38
- data/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +0 -33
- data/lib/rubocop/cop/rspec/capybara/specific_actions.rb +0 -29
- data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +0 -24
- data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +0 -35
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +0 -36
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +0 -35
- data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +0 -50
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +0 -40
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +0 -29
- data/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +0 -33
- data/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +0 -55
- data/lib/rubocop/cop/rspec/file_path.rb +0 -179
- data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +0 -27
- data/lib/rubocop/cop/rspec/rails/have_http_status.rb +0 -35
- data/lib/rubocop/cop/rspec/rails/http_status.rb +0 -61
- data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +0 -62
- data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +0 -39
- data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +0 -39
- data/lib/rubocop/cop/rspec/rails/travel_around.rb +0 -34
- data/lib/rubocop/rspec/language/node_pattern.rb +0 -48
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
|
27
27
|
# @!method expectation(node)
|
|
28
28
|
def_node_search :expectation, '(send nil? #Expectations.all ...)'
|
|
29
29
|
|
|
30
|
-
def on_block(node)
|
|
30
|
+
def on_block(node)
|
|
31
31
|
return unless hook?(node)
|
|
32
32
|
return if node.body.nil?
|
|
33
33
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module RSpec
|
|
6
|
+
# Do not use `expect` in let.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# # bad
|
|
10
|
+
# let(:foo) do
|
|
11
|
+
# expect(something).to eq 'foo'
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# # good
|
|
15
|
+
# it do
|
|
16
|
+
# expect(something).to eq 'foo'
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
class ExpectInLet < Base
|
|
20
|
+
MSG = 'Do not use `%<expect>s` in let'
|
|
21
|
+
|
|
22
|
+
# @!method expectation(node)
|
|
23
|
+
def_node_search :expectation, '(send nil? #Expectations.all ...)'
|
|
24
|
+
|
|
25
|
+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
|
26
|
+
return unless let?(node)
|
|
27
|
+
return if node.body.nil?
|
|
28
|
+
|
|
29
|
+
expectation(node.body) do |expect|
|
|
30
|
+
add_offense(expect.loc.selector, message: message(expect))
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def message(expect)
|
|
37
|
+
format(MSG, expect: expect.method_name)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -48,8 +48,8 @@ module RuboCop
|
|
|
48
48
|
include AllowedIdentifiers
|
|
49
49
|
include AllowedPattern
|
|
50
50
|
|
|
51
|
-
MSG = 'This `let` statement uses index in its name.
|
|
52
|
-
'a meaningful name.'
|
|
51
|
+
MSG = 'This `let` statement uses `%<index>s` in its name. ' \
|
|
52
|
+
'Please give it a meaningful name.'
|
|
53
53
|
|
|
54
54
|
# @!method let_name(node)
|
|
55
55
|
def_node_matcher :let_name, <<~PATTERN
|
|
@@ -66,7 +66,8 @@ module RuboCop
|
|
|
66
66
|
return unless children
|
|
67
67
|
|
|
68
68
|
filter_indexed_lets(children).each do |let_node|
|
|
69
|
-
|
|
69
|
+
index = let_name(let_node)[INDEX_REGEX]
|
|
70
|
+
add_offense(let_node, message: format(MSG, index: index))
|
|
70
71
|
end
|
|
71
72
|
end
|
|
72
73
|
|
|
@@ -45,13 +45,8 @@ module RuboCop
|
|
|
45
45
|
PATTERN
|
|
46
46
|
|
|
47
47
|
def on_metadata(symbols, hash)
|
|
48
|
-
# RSpec example groups accept two string arguments. In such a case,
|
|
49
|
-
# the rspec_metadata matcher will interpret the second string
|
|
50
|
-
# argument as a metadata symbol.
|
|
51
|
-
symbols.shift if symbols.first&.str_type?
|
|
52
|
-
|
|
53
48
|
symbols.each do |symbol|
|
|
54
|
-
on_metadata_symbol(symbol)
|
|
49
|
+
on_metadata_symbol(symbol) if symbol.sym_type?
|
|
55
50
|
end
|
|
56
51
|
|
|
57
52
|
return unless hash
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module RSpec
|
|
6
|
+
# Checks if `.to`, `not_to` or `to_not` are used.
|
|
7
|
+
#
|
|
8
|
+
# The RSpec::Expectations::ExpectationTarget must use `to`, `not_to` or
|
|
9
|
+
# `to_not` to run. Therefore, this cop checks if other methods are used.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# # bad
|
|
13
|
+
# expect(something).kind_of? Foo
|
|
14
|
+
# is_expected == 42
|
|
15
|
+
# expect{something}.eq? BarError
|
|
16
|
+
#
|
|
17
|
+
# # good
|
|
18
|
+
# expect(something).to be_a Foo
|
|
19
|
+
# is_expected.to eq 42
|
|
20
|
+
# expect{something}.to raise_error BarError
|
|
21
|
+
#
|
|
22
|
+
class MissingExpectationTargetMethod < Base
|
|
23
|
+
MSG = 'Use `.to`, `.not_to` or `.to_not` to set an expectation.'
|
|
24
|
+
RESTRICT_ON_SEND = %i[expect is_expected].freeze
|
|
25
|
+
|
|
26
|
+
# @!method expect?(node)
|
|
27
|
+
def_node_matcher :expect?, <<~PATTERN
|
|
28
|
+
{
|
|
29
|
+
(send nil? :expect ...)
|
|
30
|
+
(send nil? :is_expected)
|
|
31
|
+
}
|
|
32
|
+
PATTERN
|
|
33
|
+
|
|
34
|
+
# @!method expect_block?(node)
|
|
35
|
+
def_node_matcher :expect_block?, <<~PATTERN
|
|
36
|
+
(block #expect? (args) _body)
|
|
37
|
+
PATTERN
|
|
38
|
+
|
|
39
|
+
# @!method expectation_without_runner?(node)
|
|
40
|
+
def_node_matcher :expectation_without_runner?, <<~PATTERN
|
|
41
|
+
(send {#expect? #expect_block?} !#Runners.all ...)
|
|
42
|
+
PATTERN
|
|
43
|
+
|
|
44
|
+
def on_send(node)
|
|
45
|
+
node = node.parent if node.parent&.block_type?
|
|
46
|
+
|
|
47
|
+
expectation_without_runner?(node.parent) do
|
|
48
|
+
add_offense(node.parent.loc.selector)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
|
30
30
|
|
|
31
31
|
def on_top_level_group(node)
|
|
32
32
|
top_level_example_groups =
|
|
33
|
-
top_level_groups.select
|
|
33
|
+
top_level_groups.select { |group| example_group?(group) }
|
|
34
34
|
|
|
35
35
|
return if top_level_example_groups.one?
|
|
36
36
|
return unless top_level_example_groups.first.equal?(node)
|
|
@@ -67,12 +67,12 @@ module RuboCop
|
|
|
67
67
|
# end
|
|
68
68
|
#
|
|
69
69
|
class MultipleExpectations < Base
|
|
70
|
-
include ConfigurableMax
|
|
71
|
-
|
|
72
70
|
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
|
|
73
71
|
|
|
74
72
|
ANYTHING = ->(_node) { true }
|
|
75
|
-
|
|
73
|
+
TRUE_NODE = lambda(&:true_type?)
|
|
74
|
+
|
|
75
|
+
exclude_limit 'Max'
|
|
76
76
|
|
|
77
77
|
# @!method aggregate_failures?(node)
|
|
78
78
|
def_node_matcher :aggregate_failures?, <<~PATTERN
|
|
@@ -110,7 +110,7 @@ module RuboCop
|
|
|
110
110
|
node_with_aggregate_failures = find_aggregate_failures(example_node)
|
|
111
111
|
return false unless node_with_aggregate_failures
|
|
112
112
|
|
|
113
|
-
aggregate_failures?(node_with_aggregate_failures,
|
|
113
|
+
aggregate_failures?(node_with_aggregate_failures, TRUE_NODE)
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
def find_aggregate_failures(example_node)
|
|
@@ -82,11 +82,12 @@ module RuboCop
|
|
|
82
82
|
# end
|
|
83
83
|
#
|
|
84
84
|
class MultipleMemoizedHelpers < Base
|
|
85
|
-
include ConfigurableMax
|
|
86
85
|
include Variable
|
|
87
86
|
|
|
88
87
|
MSG = 'Example group has too many memoized helpers [%<count>d/%<max>d]'
|
|
89
88
|
|
|
89
|
+
exclude_limit 'Max'
|
|
90
|
+
|
|
90
91
|
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
|
91
92
|
return unless spec_group?(node)
|
|
92
93
|
|
|
@@ -108,10 +109,8 @@ module RuboCop
|
|
|
108
109
|
attr_reader :example_group_memoized_helpers
|
|
109
110
|
|
|
110
111
|
def all_helpers(node)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*node.each_ancestor(:block).flat_map(&method(:helpers))
|
|
114
|
-
]
|
|
112
|
+
helpers(node) +
|
|
113
|
+
node.each_ancestor(:block).flat_map { |ancestor| helpers(ancestor) }
|
|
115
114
|
end
|
|
116
115
|
|
|
117
116
|
def helpers(node)
|
|
@@ -107,8 +107,11 @@ module RuboCop
|
|
|
107
107
|
private
|
|
108
108
|
|
|
109
109
|
def ignored_shared_example?(node)
|
|
110
|
-
cop_config['IgnoreSharedExamples']
|
|
111
|
-
|
|
110
|
+
return false unless cop_config['IgnoreSharedExamples']
|
|
111
|
+
|
|
112
|
+
node.each_ancestor(:block).any? do |ancestor|
|
|
113
|
+
shared_example?(ancestor)
|
|
114
|
+
end
|
|
112
115
|
end
|
|
113
116
|
|
|
114
117
|
def check_explicit_subject(node)
|
|
@@ -92,7 +92,6 @@ module RuboCop
|
|
|
92
92
|
# end
|
|
93
93
|
#
|
|
94
94
|
class NestedGroups < Base
|
|
95
|
-
include ConfigurableMax
|
|
96
95
|
include TopLevelGroup
|
|
97
96
|
|
|
98
97
|
MSG = 'Maximum example group nesting exceeded [%<total>d/%<max>d].'
|
|
@@ -103,6 +102,8 @@ module RuboCop
|
|
|
103
102
|
"Configuration key `#{DEPRECATED_MAX_KEY}` for #{cop_name} is " \
|
|
104
103
|
'deprecated in favor of `Max`. Please use that instead.'
|
|
105
104
|
|
|
105
|
+
exclude_limit 'Max'
|
|
106
|
+
|
|
106
107
|
def on_top_level_group(node)
|
|
107
108
|
find_nested_example_groups(node) do |example_group, nesting|
|
|
108
109
|
self.max = nesting
|
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
|
32
32
|
(block $(send !nil? #predicate? ...) ...)
|
|
33
33
|
$(send !nil? #predicate? ...)})
|
|
34
34
|
$#Runners.all
|
|
35
|
-
$#boolean_matcher?)
|
|
35
|
+
$#boolean_matcher? ...)
|
|
36
36
|
PATTERN
|
|
37
37
|
|
|
38
38
|
# @!method be_bool?(node)
|
|
@@ -174,7 +174,7 @@ module RuboCop
|
|
|
174
174
|
|
|
175
175
|
def heredoc_argument?(matcher)
|
|
176
176
|
matcher.arguments.select do |arg|
|
|
177
|
-
|
|
177
|
+
arg.str_type? || arg.dstr_type? || arg.xstr_type?
|
|
178
178
|
end.any?(&:heredoc?)
|
|
179
179
|
end
|
|
180
180
|
|
|
@@ -183,8 +183,12 @@ module RuboCop
|
|
|
183
183
|
(send
|
|
184
184
|
(send nil? :expect $!nil?)
|
|
185
185
|
#Runners.all
|
|
186
|
-
{
|
|
187
|
-
|
|
186
|
+
{
|
|
187
|
+
$(send nil? #predicate_matcher_name? ...)
|
|
188
|
+
(block $(send nil? #predicate_matcher_name? ...) ...)
|
|
189
|
+
}
|
|
190
|
+
...
|
|
191
|
+
)
|
|
188
192
|
PATTERN
|
|
189
193
|
|
|
190
194
|
# @!method predicate_matcher_block?(node)
|
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
|
23
23
|
# end
|
|
24
24
|
#
|
|
25
25
|
class ScatteredSetup < Base
|
|
26
|
+
include FinalEndLocation
|
|
26
27
|
include RangeHelp
|
|
27
28
|
extend AutoCorrector
|
|
28
29
|
|
|
@@ -75,8 +76,13 @@ module RuboCop
|
|
|
75
76
|
def autocorrect(corrector, first_occurrence, occurrence)
|
|
76
77
|
return if first_occurrence == occurrence || !first_occurrence.body
|
|
77
78
|
|
|
79
|
+
# Take heredocs into account
|
|
80
|
+
body = occurrence.body&.source_range&.with(
|
|
81
|
+
end_pos: final_end_location(occurrence).begin_pos
|
|
82
|
+
)
|
|
83
|
+
|
|
78
84
|
corrector.insert_after(first_occurrence.body,
|
|
79
|
-
"\n#{
|
|
85
|
+
"\n#{body&.source}")
|
|
80
86
|
corrector.remove(range_by_whole_lines(occurrence.source_range,
|
|
81
87
|
include_final_newline: true))
|
|
82
88
|
end
|
|
@@ -136,7 +136,9 @@ module RuboCop
|
|
|
136
136
|
RESTRICT_ON_SEND = %i[to].freeze
|
|
137
137
|
|
|
138
138
|
def on_send(node)
|
|
139
|
-
expectation(node,
|
|
139
|
+
expectation(node) do |expectation, method_name, matcher|
|
|
140
|
+
on_expectation(expectation, method_name, matcher)
|
|
141
|
+
end
|
|
140
142
|
end
|
|
141
143
|
|
|
142
144
|
private
|
|
@@ -113,8 +113,8 @@ module RuboCop
|
|
|
113
113
|
PATTERN
|
|
114
114
|
|
|
115
115
|
def on_top_level_group(node)
|
|
116
|
-
@explicit_subjects = find_all_explicit(node
|
|
117
|
-
@subject_overrides = find_all_explicit(node
|
|
116
|
+
@explicit_subjects = find_all_explicit(node) { |n| subject?(n) }
|
|
117
|
+
@subject_overrides = find_all_explicit(node) { |n| let?(n) }
|
|
118
118
|
|
|
119
119
|
find_subject_expectations(node) do |stub|
|
|
120
120
|
add_offense(stub)
|
|
@@ -32,34 +32,39 @@ module RuboCop
|
|
|
32
32
|
#
|
|
33
33
|
class UnspecifiedException < Base
|
|
34
34
|
MSG = 'Specify the exception being captured'
|
|
35
|
-
RESTRICT_ON_SEND = %i[to].freeze
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
36
|
+
RESTRICT_ON_SEND = %i[
|
|
37
|
+
raise_exception
|
|
38
|
+
raise_error
|
|
39
|
+
].freeze
|
|
40
|
+
|
|
41
|
+
# @!method expect_to?(node)
|
|
42
|
+
def_node_matcher :expect_to?, <<~PATTERN
|
|
43
|
+
(send (block (send nil? :expect) ...) :to ...)
|
|
45
44
|
PATTERN
|
|
46
45
|
|
|
47
46
|
def on_send(node)
|
|
48
47
|
return unless empty_exception_matcher?(node)
|
|
49
48
|
|
|
50
|
-
add_offense(node
|
|
49
|
+
add_offense(node)
|
|
51
50
|
end
|
|
52
51
|
|
|
53
52
|
private
|
|
54
53
|
|
|
55
54
|
def empty_exception_matcher?(node)
|
|
56
|
-
|
|
57
|
-
end
|
|
55
|
+
return false if node.arguments? || node.block_literal?
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
return false unless
|
|
57
|
+
expect_to = find_expect_to(node)
|
|
58
|
+
return false unless expect_to
|
|
59
|
+
return false if expect_to.block_node&.arguments?
|
|
60
|
+
|
|
61
|
+
true
|
|
62
|
+
end
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
def find_expect_to(node)
|
|
65
|
+
node.each_ancestor(:send).find do |ancestor|
|
|
66
|
+
expect_to?(ancestor)
|
|
67
|
+
end
|
|
63
68
|
end
|
|
64
69
|
end
|
|
65
70
|
end
|
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'rspec/capybara/current_path_expectation'
|
|
4
|
-
require_relative 'rspec/capybara/feature_methods'
|
|
5
|
-
require_relative 'rspec/capybara/match_style'
|
|
6
|
-
require_relative 'rspec/capybara/negation_matcher'
|
|
7
|
-
require_relative 'rspec/capybara/specific_actions'
|
|
8
|
-
require_relative 'rspec/capybara/specific_finders'
|
|
9
|
-
require_relative 'rspec/capybara/specific_matcher'
|
|
10
|
-
require_relative 'rspec/capybara/visibility_matcher'
|
|
11
|
-
|
|
12
|
-
require_relative 'rspec/factory_bot/attribute_defined_statically'
|
|
13
|
-
require_relative 'rspec/factory_bot/consistent_parentheses_style'
|
|
14
|
-
require_relative 'rspec/factory_bot/create_list'
|
|
15
|
-
require_relative 'rspec/factory_bot/factory_class_name'
|
|
16
|
-
require_relative 'rspec/factory_bot/factory_name_style'
|
|
17
|
-
require_relative 'rspec/factory_bot/syntax_methods'
|
|
18
|
-
|
|
19
|
-
require_relative 'rspec/rails/avoid_setup_hook'
|
|
20
|
-
require_relative 'rspec/rails/have_http_status'
|
|
21
|
-
require_relative 'rspec/rails/http_status'
|
|
22
|
-
require_relative 'rspec/rails/inferred_spec_type'
|
|
23
|
-
require_relative 'rspec/rails/minitest_assertions'
|
|
24
|
-
require_relative 'rspec/rails/negation_be_valid'
|
|
25
|
-
require_relative 'rspec/rails/travel_around'
|
|
26
|
-
|
|
27
3
|
require_relative 'rspec/align_left_let_brace'
|
|
28
4
|
require_relative 'rspec/align_right_let_brace'
|
|
29
5
|
require_relative 'rspec/any_instance'
|
|
@@ -63,8 +39,8 @@ require_relative 'rspec/excessive_docstring_spacing'
|
|
|
63
39
|
require_relative 'rspec/expect_actual'
|
|
64
40
|
require_relative 'rspec/expect_change'
|
|
65
41
|
require_relative 'rspec/expect_in_hook'
|
|
42
|
+
require_relative 'rspec/expect_in_let'
|
|
66
43
|
require_relative 'rspec/expect_output'
|
|
67
|
-
require_relative 'rspec/file_path'
|
|
68
44
|
require_relative 'rspec/focus'
|
|
69
45
|
require_relative 'rspec/hook_argument'
|
|
70
46
|
require_relative 'rspec/hooks_before_examples'
|
|
@@ -88,6 +64,7 @@ require_relative 'rspec/message_expectation'
|
|
|
88
64
|
require_relative 'rspec/message_spies'
|
|
89
65
|
require_relative 'rspec/metadata_style'
|
|
90
66
|
require_relative 'rspec/missing_example_group_argument'
|
|
67
|
+
require_relative 'rspec/missing_expectation_target_method'
|
|
91
68
|
require_relative 'rspec/multiple_describes'
|
|
92
69
|
require_relative 'rspec/multiple_expectations'
|
|
93
70
|
require_relative 'rspec/multiple_memoized_helpers'
|
|
@@ -7,29 +7,7 @@ module RuboCop
|
|
|
7
7
|
# Builds a YAML config file from two config hashes
|
|
8
8
|
class ConfigFormatter
|
|
9
9
|
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
|
|
10
|
-
SUBDEPARTMENTS =
|
|
11
|
-
EXTRACTED_COPS = %(
|
|
12
|
-
RSpec/Capybara/CurrentPathExpectation
|
|
13
|
-
RSpec/Capybara/MatchStyle
|
|
14
|
-
RSpec/Capybara/NegationMatcher
|
|
15
|
-
RSpec/Capybara/SpecificActions
|
|
16
|
-
RSpec/Capybara/SpecificFinders
|
|
17
|
-
RSpec/Capybara/SpecificMatcher
|
|
18
|
-
RSpec/Capybara/VisibilityMatcher
|
|
19
|
-
RSpec/FactoryBot/AttributeDefinedStatically
|
|
20
|
-
RSpec/FactoryBot/ConsistentParenthesesStyle
|
|
21
|
-
RSpec/FactoryBot/CreateList
|
|
22
|
-
RSpec/FactoryBot/FactoryClassName
|
|
23
|
-
RSpec/FactoryBot/FactoryNameStyle
|
|
24
|
-
RSpec/FactoryBot/SyntaxMethods
|
|
25
|
-
RSpec/Rails/AvoidSetupHook
|
|
26
|
-
RSpec/Rails/HaveHttpStatus
|
|
27
|
-
RSpec/Rails/HttpStatus
|
|
28
|
-
RSpec/Rails/InferredSpecType
|
|
29
|
-
RSpec/Rails/MinitestAssertions
|
|
30
|
-
RSpec/Rails/NegationBeValid
|
|
31
|
-
RSpec/Rails/TravelAround
|
|
32
|
-
)
|
|
10
|
+
SUBDEPARTMENTS = [].freeze
|
|
33
11
|
AMENDMENTS = %(Metrics/BlockLength)
|
|
34
12
|
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/'
|
|
35
13
|
|
|
@@ -51,7 +29,6 @@ module RuboCop
|
|
|
51
29
|
def unified_config
|
|
52
30
|
cops.each_with_object(config.dup) do |cop, unified|
|
|
53
31
|
next if SUBDEPARTMENTS.include?(cop) || AMENDMENTS.include?(cop)
|
|
54
|
-
next if EXTRACTED_COPS.include?(cop)
|
|
55
32
|
|
|
56
33
|
replace_nil(unified[cop])
|
|
57
34
|
unified[cop].merge!(descriptions.fetch(cop))
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module RSpec
|
|
5
|
+
module Cop
|
|
6
|
+
# Source and spec generator for new cops
|
|
7
|
+
#
|
|
8
|
+
# This generator will take a cop name and generate a source file
|
|
9
|
+
# and spec file when given a valid qualified cop name.
|
|
10
|
+
# @api private
|
|
11
|
+
class Generator < RuboCop::Cop::Generator
|
|
12
|
+
def todo
|
|
13
|
+
<<~TODO
|
|
14
|
+
Do 4 steps:
|
|
15
|
+
1. Modify the description of #{badge} in config/default.yml
|
|
16
|
+
2. Implement your new cop in the generated file!
|
|
17
|
+
3. Add an entry about new cop to CHANGELOG.md
|
|
18
|
+
4. Commit your new cop with a message such as
|
|
19
|
+
e.g. "Add new `#{badge}` cop"
|
|
20
|
+
TODO
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -21,7 +21,7 @@ RSpec.shared_context 'with default RSpec/Language config' do
|
|
|
21
21
|
when Array
|
|
22
22
|
object.map { |item| deep_dup(item) }
|
|
23
23
|
when Hash
|
|
24
|
-
object.transform_values(
|
|
24
|
+
object.transform_values { |value| deep_dup(value) }
|
|
25
25
|
else
|
|
26
26
|
object # only collections undergo modifications and need duping
|
|
27
27
|
end
|
|
@@ -4,10 +4,10 @@ module RuboCop
|
|
|
4
4
|
module RSpec
|
|
5
5
|
# RSpec example wording rewriter
|
|
6
6
|
class Wording
|
|
7
|
-
SHOULDNT_PREFIX = /\Ashould(?:n't| not)\b/i.freeze
|
|
7
|
+
SHOULDNT_PREFIX = /\Ashould(?:n't|n’t| not)\b/i.freeze
|
|
8
8
|
SHOULDNT_BE_PREFIX = /#{SHOULDNT_PREFIX} be\b/i.freeze
|
|
9
9
|
WILL_NOT_PREFIX = /\Awill not\b/i.freeze
|
|
10
|
-
WONT_PREFIX = /\
|
|
10
|
+
WONT_PREFIX = /\Awo(?:n't|n’t)\b/i.freeze
|
|
11
11
|
ES_SUFFIX_PATTERN = /(?:o|s|x|ch|sh|z)\z/i.freeze
|
|
12
12
|
IES_SUFFIX_PATTERN = /[^aeou]y\z/i.freeze
|
|
13
13
|
|
data/lib/rubocop-rspec.rb
CHANGED
|
@@ -4,19 +4,14 @@ require 'pathname'
|
|
|
4
4
|
require 'yaml'
|
|
5
5
|
|
|
6
6
|
require 'rubocop'
|
|
7
|
-
require 'rubocop-capybara'
|
|
8
|
-
require 'rubocop-factory_bot'
|
|
9
7
|
|
|
10
8
|
require_relative 'rubocop/rspec'
|
|
11
9
|
require_relative 'rubocop/rspec/inject'
|
|
12
|
-
require_relative 'rubocop/rspec/language
|
|
10
|
+
require_relative 'rubocop/rspec/language'
|
|
13
11
|
require_relative 'rubocop/rspec/node'
|
|
14
12
|
require_relative 'rubocop/rspec/version'
|
|
15
13
|
require_relative 'rubocop/rspec/wording'
|
|
16
14
|
|
|
17
|
-
# Dependent on `RuboCop::RSpec::Language::NodePattern`.
|
|
18
|
-
require_relative 'rubocop/rspec/language'
|
|
19
|
-
|
|
20
15
|
require_relative 'rubocop/cop/rspec/mixin/file_help'
|
|
21
16
|
require_relative 'rubocop/cop/rspec/mixin/final_end_location'
|
|
22
17
|
require_relative 'rubocop/cop/rspec/mixin/inside_example_group'
|
|
@@ -39,9 +34,6 @@ require_relative 'rubocop/rspec/example'
|
|
|
39
34
|
require_relative 'rubocop/rspec/example_group'
|
|
40
35
|
require_relative 'rubocop/rspec/hook'
|
|
41
36
|
|
|
42
|
-
# need after `require 'rubocop/cop/rspec/base'``
|
|
43
|
-
require 'rubocop-rspec_rails'
|
|
44
|
-
|
|
45
37
|
RuboCop::RSpec::Inject.defaults!
|
|
46
38
|
|
|
47
39
|
require_relative 'rubocop/cop/rspec_cops'
|
|
@@ -58,12 +50,4 @@ RuboCop::Cop::Layout::ExtraSpacing.singleton_class.prepend(
|
|
|
58
50
|
end
|
|
59
51
|
)
|
|
60
52
|
|
|
61
|
-
RuboCop::Cop::Style::TrailingCommaInArguments.singleton_class.prepend(
|
|
62
|
-
Module.new do
|
|
63
|
-
def autocorrect_incompatible_with
|
|
64
|
-
super.push(RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
)
|
|
68
|
-
|
|
69
53
|
RuboCop::AST::Node.include(RuboCop::RSpec::Node)
|