rubocop-rspec 1.41.0 → 1.42.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 +4 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +11 -18
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +11 -18
- data/lib/rubocop/cop/rspec/be.rb +1 -1
- data/lib/rubocop/cop/rspec/be_eql.rb +5 -5
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +18 -16
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +8 -9
- data/lib/rubocop/cop/rspec/context_method.rb +5 -7
- data/lib/rubocop/cop/rspec/cop.rb +1 -1
- data/lib/rubocop/cop/rspec/described_class.rb +10 -7
- data/lib/rubocop/cop/rspec/dialect.rb +4 -11
- data/lib/rubocop/cop/rspec/empty_hook.rb +5 -9
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +5 -3
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +5 -5
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +4 -1
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +5 -5
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +4 -1
- data/lib/rubocop/cop/rspec/example_wording.rb +6 -7
- data/lib/rubocop/cop/rspec/expect_actual.rb +7 -10
- data/lib/rubocop/cop/rspec/expect_change.rb +9 -34
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +18 -18
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +10 -16
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +6 -7
- data/lib/rubocop/cop/rspec/hook_argument.rb +11 -17
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +12 -13
- data/lib/rubocop/cop/rspec/implicit_expect.rb +6 -14
- data/lib/rubocop/cop/rspec/implicit_subject.rb +8 -5
- data/lib/rubocop/cop/rspec/instance_spy.rb +17 -11
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +2 -5
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +4 -5
- data/lib/rubocop/cop/rspec/leading_subject.rb +13 -13
- data/lib/rubocop/cop/rspec/let_before_examples.rb +12 -10
- data/lib/rubocop/cop/rspec/message_chain.rb +6 -5
- data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/message_spies.rb +1 -2
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +17 -18
- data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/not_to_not.rb +4 -5
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +23 -53
- data/lib/rubocop/cop/rspec/rails/http_status.rb +4 -8
- data/lib/rubocop/cop/rspec/receive_counts.rb +14 -16
- data/lib/rubocop/cop/rspec/receive_never.rb +10 -10
- data/lib/rubocop/cop/rspec/return_from_stub.rb +8 -19
- data/lib/rubocop/cop/rspec/scattered_let.rb +7 -10
- data/lib/rubocop/cop/rspec/shared_context.rb +7 -20
- data/lib/rubocop/cop/rspec/shared_examples.rb +5 -8
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +14 -17
- data/lib/rubocop/cop/rspec/yield.rb +13 -10
- data/lib/rubocop/rspec/blank_line_separation.rb +0 -8
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c377178f53790f52ca57f4e777d0847d69e673e0ca54139e073d7d5f33ef051b
|
4
|
+
data.tar.gz: baf53df9cbd5041398fc1f41d028a521f0d05a566a765a6198d1015dd31ae9f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 676ea9472397bc4cd47b7777a1e690f036011ebeedd90c5953b4958ca120bd5178d3a669a8b5392af5945fed792e2c3b50438bb048a50a6e4de86387c31942e7
|
7
|
+
data.tar.gz: d4351174b8a17c0af13be4d4417396450e86e6ef5b4a19b3c87d5b6c7fa582e5ee54b3b4172967907d5202b3ca732b4bf2970bc574652fdfffb760cbf23086ea
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 1.42.0 (2020-07-09)
|
6
|
+
|
7
|
+
* Update RuboCop dependency to 0.87.0 because of changes to internal APIs. ([@bquorning][], [@Darhazer][])
|
8
|
+
|
5
9
|
## 1.41.0 (2020-07-03)
|
6
10
|
|
7
11
|
* Extend the list of Rails spec types for `RSpec/DescribeClass`. ([@pirj][])
|
@@ -18,35 +18,28 @@ module RuboCop
|
|
18
18
|
# let(:a) { b }
|
19
19
|
#
|
20
20
|
class AlignLeftLetBrace < Cop
|
21
|
+
extend AutoCorrector
|
22
|
+
|
21
23
|
MSG = 'Align left let brace'
|
22
24
|
|
23
25
|
def self.autocorrect_incompatible_with
|
24
26
|
[Layout::ExtraSpacing]
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
29
|
+
def on_new_investigation
|
28
30
|
return if processed_source.blank?
|
29
31
|
|
30
|
-
token_aligner
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
32
|
+
token_aligner =
|
33
|
+
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
token_aligner.offending_tokens.each do |let|
|
36
|
+
add_offense(let.loc.begin) do |corrector|
|
37
|
+
corrector.insert_before(
|
38
|
+
let.loc.begin, token_aligner.indent_for(let)
|
39
|
+
)
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def token_aligner
|
47
|
-
@token_aligner ||=
|
48
|
-
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
|
49
|
-
end
|
50
43
|
end
|
51
44
|
end
|
52
45
|
end
|
@@ -18,35 +18,28 @@ module RuboCop
|
|
18
18
|
# let(:a) { b }
|
19
19
|
#
|
20
20
|
class AlignRightLetBrace < Cop
|
21
|
+
extend AutoCorrector
|
22
|
+
|
21
23
|
MSG = 'Align right let brace'
|
22
24
|
|
23
25
|
def self.autocorrect_incompatible_with
|
24
26
|
[Layout::ExtraSpacing]
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
29
|
+
def on_new_investigation
|
28
30
|
return if processed_source.blank?
|
29
31
|
|
30
|
-
token_aligner
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
32
|
+
token_aligner =
|
33
|
+
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
token_aligner.offending_tokens.each do |let|
|
36
|
+
add_offense(let.loc.end) do |corrector|
|
37
|
+
corrector.insert_before(
|
38
|
+
let.loc.end, token_aligner.indent_for(let)
|
39
|
+
)
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def token_aligner
|
47
|
-
@token_aligner ||=
|
48
|
-
RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
|
49
|
-
end
|
50
43
|
end
|
51
44
|
end
|
52
45
|
end
|
data/lib/rubocop/cop/rspec/be.rb
CHANGED
@@ -36,6 +36,8 @@ module RuboCop
|
|
36
36
|
# coerce objects for comparison.
|
37
37
|
#
|
38
38
|
class BeEql < Cop
|
39
|
+
extend AutoCorrector
|
40
|
+
|
39
41
|
MSG = 'Prefer `be` over `eql`.'
|
40
42
|
|
41
43
|
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
@@ -44,13 +46,11 @@ module RuboCop
|
|
44
46
|
|
45
47
|
def on_send(node)
|
46
48
|
eql_type_with_identity(node) do |eql|
|
47
|
-
add_offense(eql
|
49
|
+
add_offense(eql.loc.selector) do |corrector|
|
50
|
+
corrector.replace(eql.loc.selector, 'be')
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
|
-
|
51
|
-
def autocorrect(node)
|
52
|
-
->(corrector) { corrector.replace(node.loc.selector, 'be') }
|
53
|
-
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -24,6 +24,8 @@ module RuboCop
|
|
24
24
|
# expect(page).to have_current_path(/widgets/)
|
25
25
|
#
|
26
26
|
class CurrentPathExpectation < Cop
|
27
|
+
extend AutoCorrector
|
28
|
+
|
27
29
|
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
|
28
30
|
'Capybara feature specs - instead, use the ' \
|
29
31
|
'`have_current_path` matcher on `page`'
|
@@ -47,30 +49,30 @@ module RuboCop
|
|
47
49
|
|
48
50
|
def on_send(node)
|
49
51
|
expectation_set_on_current_path(node) do
|
50
|
-
add_offense(node
|
52
|
+
add_offense(node.loc.selector) do |corrector|
|
53
|
+
next unless node.chained?
|
54
|
+
|
55
|
+
autocorrect(corrector, node)
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
|
-
|
55
|
-
lambda do |corrector|
|
56
|
-
return unless node.chained?
|
60
|
+
private
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
def autocorrect(corrector, node)
|
63
|
+
as_is_matcher(node.parent) do |to_sym, matcher_node|
|
64
|
+
rewrite_expectation(corrector, node, to_sym, matcher_node)
|
65
|
+
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
67
|
+
regexp_str_matcher(node.parent) do |to_sym, matcher_node, regexp|
|
68
|
+
rewrite_expectation(corrector, node, to_sym, matcher_node)
|
69
|
+
convert_regexp_str_to_literal(corrector, matcher_node, regexp)
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
|
-
private
|
70
|
-
|
71
73
|
def rewrite_expectation(corrector, node, to_symbol, matcher_node)
|
72
74
|
current_path_node = node.first_argument
|
73
|
-
corrector.replace(current_path_node
|
75
|
+
corrector.replace(current_path_node, 'page')
|
74
76
|
corrector.replace(node.parent.loc.selector, 'to')
|
75
77
|
matcher_method = if to_symbol == :to
|
76
78
|
'have_current_path'
|
@@ -84,7 +86,7 @@ module RuboCop
|
|
84
86
|
def convert_regexp_str_to_literal(corrector, matcher_node, regexp_str)
|
85
87
|
str_node = matcher_node.first_argument
|
86
88
|
regexp_expr = Regexp.new(regexp_str).inspect
|
87
|
-
corrector.replace(str_node
|
89
|
+
corrector.replace(str_node, regexp_expr)
|
88
90
|
end
|
89
91
|
|
90
92
|
# `have_current_path` with no options will include the querystring
|
@@ -97,7 +99,7 @@ module RuboCop
|
|
97
99
|
return if %i[regexp str].include?(expectation_last_child.type)
|
98
100
|
|
99
101
|
corrector.insert_after(
|
100
|
-
expectation_last_child
|
102
|
+
expectation_last_child,
|
101
103
|
', ignore_query: true'
|
102
104
|
)
|
103
105
|
end
|
@@ -41,6 +41,8 @@ module RuboCop
|
|
41
41
|
# end
|
42
42
|
# end
|
43
43
|
class FeatureMethods < Cop
|
44
|
+
extend AutoCorrector
|
45
|
+
|
44
46
|
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
|
45
47
|
|
46
48
|
# https://git.io/v7Kwr
|
@@ -71,18 +73,15 @@ module RuboCop
|
|
71
73
|
feature_method(node) do |send_node, match|
|
72
74
|
next if enabled?(match)
|
73
75
|
|
74
|
-
add_offense(
|
75
|
-
send_node,
|
76
|
-
|
77
|
-
message: format(MSG, method: match, replacement: MAP[match])
|
78
|
-
)
|
76
|
+
add_offense(send_node.loc.selector) do |corrector|
|
77
|
+
corrector.replace(send_node.loc.selector, MAP[match].to_s)
|
78
|
+
end
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
end
|
82
|
+
def message(range)
|
83
|
+
name = range.source.to_sym
|
84
|
+
format(MSG, method: name, replacement: MAP[name])
|
86
85
|
end
|
87
86
|
|
88
87
|
private
|
@@ -24,6 +24,8 @@ module RuboCop
|
|
24
24
|
# # ...
|
25
25
|
# end
|
26
26
|
class ContextMethod < Cop
|
27
|
+
extend AutoCorrector
|
28
|
+
|
27
29
|
MSG = 'Use `describe` for testing methods.'
|
28
30
|
|
29
31
|
def_node_matcher :context_method, <<-PATTERN
|
@@ -32,13 +34,9 @@ module RuboCop
|
|
32
34
|
|
33
35
|
def on_block(node)
|
34
36
|
context_method(node) do |context|
|
35
|
-
add_offense(context)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def autocorrect(node)
|
40
|
-
lambda do |corrector|
|
41
|
-
corrector.replace(node.parent.loc.selector, 'describe')
|
37
|
+
add_offense(context) do |corrector|
|
38
|
+
corrector.replace(node.send_node.loc.selector, 'describe')
|
39
|
+
end
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
@@ -55,6 +55,7 @@ module RuboCop
|
|
55
55
|
# end
|
56
56
|
#
|
57
57
|
class DescribedClass < Cop
|
58
|
+
extend AutoCorrector
|
58
59
|
include ConfigurableEnforcedStyle
|
59
60
|
|
60
61
|
DESCRIBED_CLASS = 'described_class'
|
@@ -85,22 +86,24 @@ module RuboCop
|
|
85
86
|
return unless body
|
86
87
|
|
87
88
|
find_usage(body) do |match|
|
88
|
-
|
89
|
+
msg = message(match.const_name)
|
90
|
+
add_offense(match, message: msg) do |corrector|
|
91
|
+
autocorrect(corrector, match)
|
92
|
+
end
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
92
|
-
|
96
|
+
private
|
97
|
+
|
98
|
+
def autocorrect(corrector, match)
|
93
99
|
replacement = if style == :described_class
|
94
100
|
DESCRIBED_CLASS
|
95
101
|
else
|
96
102
|
@described_class.const_name
|
97
103
|
end
|
98
|
-
lambda do |corrector|
|
99
|
-
corrector.replace(node.loc.expression, replacement)
|
100
|
-
end
|
101
|
-
end
|
102
104
|
|
103
|
-
|
105
|
+
corrector.replace(match, replacement)
|
106
|
+
end
|
104
107
|
|
105
108
|
def find_usage(node, &block)
|
106
109
|
yield(node) if offensive?(node)
|
@@ -42,6 +42,7 @@ module RuboCop
|
|
42
42
|
# # ...
|
43
43
|
# end
|
44
44
|
class Dialect < Cop
|
45
|
+
extend AutoCorrector
|
45
46
|
include MethodPreference
|
46
47
|
|
47
48
|
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
|
@@ -52,24 +53,16 @@ module RuboCop
|
|
52
53
|
return unless rspec_method?(node)
|
53
54
|
return unless preferred_methods[node.method_name]
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
msg = format(MSG, prefer: preferred_method(node.method_name),
|
57
|
+
current: node.method_name)
|
57
58
|
|
58
|
-
|
59
|
-
lambda do |corrector|
|
59
|
+
add_offense(node, message: msg) do |corrector|
|
60
60
|
current = node.loc.selector
|
61
61
|
preferred = preferred_method(current.source)
|
62
62
|
|
63
63
|
corrector.replace(current, preferred)
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def message(node)
|
70
|
-
format(MSG, prefer: preferred_method(node.method_name),
|
71
|
-
current: node.method_name)
|
72
|
-
end
|
73
66
|
end
|
74
67
|
end
|
75
68
|
end
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
# end
|
24
24
|
# after(:all) { cleanup_feed }
|
25
25
|
class EmptyHook < Cop
|
26
|
+
extend AutoCorrector
|
26
27
|
include RuboCop::Cop::RangeHelp
|
27
28
|
|
28
29
|
MSG = 'Empty hook detected.'
|
@@ -33,15 +34,10 @@ module RuboCop
|
|
33
34
|
|
34
35
|
def on_block(node)
|
35
36
|
empty_hook?(node) do |hook|
|
36
|
-
add_offense(hook)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def autocorrect(node)
|
41
|
-
lambda do |corrector|
|
42
|
-
block = node.parent
|
43
|
-
range = range_with_surrounding_space(range: block.loc.expression)
|
44
|
-
corrector.remove(range)
|
37
|
+
add_offense(hook) do |corrector|
|
38
|
+
range = range_with_surrounding_space(range: node.loc.expression)
|
39
|
+
corrector.remove(range)
|
40
|
+
end
|
45
41
|
end
|
46
42
|
end
|
47
43
|
end
|
@@ -42,6 +42,7 @@ module RuboCop
|
|
42
42
|
# end
|
43
43
|
#
|
44
44
|
class EmptyLineAfterExample < Cop
|
45
|
+
extend AutoCorrector
|
45
46
|
include RuboCop::RSpec::BlankLineSeparation
|
46
47
|
|
47
48
|
MSG = 'Add an empty line after `%<example>s`.'
|
@@ -52,9 +53,10 @@ module RuboCop
|
|
52
53
|
return if allowed_one_liner?(node)
|
53
54
|
|
54
55
|
missing_separating_line(node) do |location|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
msg = format(MSG, example: node.method_name)
|
57
|
+
add_offense(location, message: msg) do |corrector|
|
58
|
+
corrector.insert_after(location.end, "\n")
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
@@ -24,6 +24,7 @@ module RuboCop
|
|
24
24
|
# end
|
25
25
|
#
|
26
26
|
class EmptyLineAfterExampleGroup < Cop
|
27
|
+
extend AutoCorrector
|
27
28
|
include RuboCop::RSpec::BlankLineSeparation
|
28
29
|
|
29
30
|
MSG = 'Add an empty line after `%<example_group>s`.'
|
@@ -33,11 +34,10 @@ module RuboCop
|
|
33
34
|
return if last_child?(node)
|
34
35
|
|
35
36
|
missing_separating_line(node) do |location|
|
36
|
-
|
37
|
-
|
38
|
-
location
|
39
|
-
|
40
|
-
)
|
37
|
+
msg = format(MSG, example_group: node.method_name)
|
38
|
+
add_offense(location, message: msg) do |corrector|
|
39
|
+
corrector.insert_after(location.end, "\n")
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -17,6 +17,7 @@ module RuboCop
|
|
17
17
|
#
|
18
18
|
# it { does_something }
|
19
19
|
class EmptyLineAfterFinalLet < Cop
|
20
|
+
extend AutoCorrector
|
20
21
|
include RuboCop::RSpec::BlankLineSeparation
|
21
22
|
|
22
23
|
MSG = 'Add an empty line after the last `let` block.'
|
@@ -30,7 +31,9 @@ module RuboCop
|
|
30
31
|
return if last_child?(latest_let)
|
31
32
|
|
32
33
|
missing_separating_line(latest_let) do |location|
|
33
|
-
add_offense(
|
34
|
+
add_offense(location) do |corrector|
|
35
|
+
corrector.insert_after(location.end, "\n")
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|