rubocop-rspec 2.7.0 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/config/default.yml +144 -92
- data/lib/rubocop/cop/rspec/be_eq.rb +45 -0
- data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
- data/lib/rubocop/cop/rspec/be_nil.rb +74 -0
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +11 -7
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +3 -2
- data/lib/rubocop/cop/rspec/empty_example_group.rb +6 -6
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +3 -9
- data/lib/rubocop/cop/rspec/leading_subject.rb +3 -7
- data/lib/rubocop/cop/rspec/mixin/inside_example_group.rb +2 -2
- data/lib/rubocop/cop/rspec/subject_stub.rb +44 -18
- data/lib/rubocop/cop/rspec/verified_double_reference.rb +111 -0
- data/lib/rubocop/cop/rspec/yield.rb +1 -1
- data/lib/rubocop/cop/rspec_cops.rb +3 -0
- data/lib/rubocop/rspec/config_formatter.rb +3 -4
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop-rspec.rb +14 -9
- metadata +5 -2
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Check for expectations where `be(...)` can replace `eq(...)`.
|
7
|
+
#
|
8
|
+
# The `be` matcher compares by identity while the `eq` matcher compares
|
9
|
+
# using `==`. Booleans and nil can be compared by identity and therefore
|
10
|
+
# the `be` matcher is preferable as it is a more strict test.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# expect(foo).to eq(true)
|
16
|
+
# expect(foo).to eq(false)
|
17
|
+
# expect(foo).to eq(nil)
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# expect(foo).to be(true)
|
21
|
+
# expect(foo).to be(false)
|
22
|
+
# expect(foo).to be(nil)
|
23
|
+
#
|
24
|
+
class BeEq < Base
|
25
|
+
extend AutoCorrector
|
26
|
+
|
27
|
+
MSG = 'Prefer `be` over `eq`.'
|
28
|
+
RESTRICT_ON_SEND = %i[eq].freeze
|
29
|
+
|
30
|
+
# @!method eq_type_with_identity?(node)
|
31
|
+
def_node_matcher :eq_type_with_identity?, <<-PATTERN
|
32
|
+
(send nil? :eq {true false nil})
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
return unless eq_type_with_identity?(node)
|
37
|
+
|
38
|
+
add_offense(node.loc.selector) do |corrector|
|
39
|
+
corrector.replace(node.loc.selector, 'be')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
|
44
44
|
# @!method eql_type_with_identity(node)
|
45
45
|
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
46
|
-
(send _ :to $(send nil? :eql {true false int float sym
|
46
|
+
(send _ :to $(send nil? :eql {true false int float sym nil}))
|
47
47
|
PATTERN
|
48
48
|
|
49
49
|
def on_send(node)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Ensures a consistent style is used when matching `nil`.
|
7
|
+
#
|
8
|
+
# You can either use the more specific `be_nil` matcher, or the more
|
9
|
+
# generic `be` matcher with a `nil` argument.
|
10
|
+
#
|
11
|
+
# This cop can be configured using the `EnforcedStyle` option
|
12
|
+
#
|
13
|
+
# @example `EnforcedStyle: be_nil` (default)
|
14
|
+
# # bad
|
15
|
+
# expect(foo).to be(nil)
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# expect(foo).to be_nil
|
19
|
+
#
|
20
|
+
# @example `EnforcedStyle: be`
|
21
|
+
# # bad
|
22
|
+
# expect(foo).to be_nil
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# expect(foo).to be(nil)
|
26
|
+
#
|
27
|
+
class BeNil < Base
|
28
|
+
extend AutoCorrector
|
29
|
+
include ConfigurableEnforcedStyle
|
30
|
+
|
31
|
+
BE_MSG = 'Prefer `be(nil)` over `be_nil`.'
|
32
|
+
BE_NIL_MSG = 'Prefer `be_nil` over `be(nil)`.'
|
33
|
+
RESTRICT_ON_SEND = %i[be be_nil].freeze
|
34
|
+
|
35
|
+
# @!method be_nil_matcher?(node)
|
36
|
+
def_node_matcher :be_nil_matcher?, <<-PATTERN
|
37
|
+
(send nil? :be_nil)
|
38
|
+
PATTERN
|
39
|
+
|
40
|
+
# @!method nil_value_expectation?(node)
|
41
|
+
def_node_matcher :nil_value_expectation?, <<-PATTERN
|
42
|
+
(send nil? :be nil)
|
43
|
+
PATTERN
|
44
|
+
|
45
|
+
def on_send(node)
|
46
|
+
case style
|
47
|
+
when :be
|
48
|
+
check_be_style(node)
|
49
|
+
when :be_nil
|
50
|
+
check_be_nil_style(node)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def check_be_style(node)
|
57
|
+
return unless be_nil_matcher?(node)
|
58
|
+
|
59
|
+
add_offense(node, message: BE_MSG) do |corrector|
|
60
|
+
corrector.replace(node.loc.expression, 'be(nil)')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def check_be_nil_style(node)
|
65
|
+
return unless nil_value_expectation?(node)
|
66
|
+
|
67
|
+
add_offense(node, message: BE_NIL_MSG) do |corrector|
|
68
|
+
corrector.replace(node.loc.expression, 'be_nil')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -6,13 +6,13 @@ module RuboCop
|
|
6
6
|
module Capybara
|
7
7
|
# Checks that no expectations are set on Capybara's `current_path`.
|
8
8
|
#
|
9
|
-
# The
|
10
|
-
# teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
9
|
+
# The
|
10
|
+
# https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
|
11
|
+
# should be used on `page` to set expectations on Capybara's
|
12
|
+
# current path, since it uses
|
13
|
+
# https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
|
14
|
+
# which ensures that preceding actions (like `click_link`) have
|
15
|
+
# completed.
|
16
16
|
#
|
17
17
|
# @example
|
18
18
|
# # bad
|
@@ -52,6 +52,10 @@ module RuboCop
|
|
52
52
|
$(send nil? :match (str $_)))
|
53
53
|
PATTERN
|
54
54
|
|
55
|
+
def self.autocorrect_incompatible_with
|
56
|
+
[Style::TrailingCommaInArguments]
|
57
|
+
end
|
58
|
+
|
55
59
|
def on_send(node)
|
56
60
|
expectation_set_on_current_path(node) do
|
57
61
|
add_offense(node.loc.selector) do |corrector|
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module RSpec
|
6
6
|
module Capybara
|
7
|
-
# Checks for boolean visibility in
|
7
|
+
# Checks for boolean visibility in Capybara finders.
|
8
8
|
#
|
9
9
|
# Capybara lets you find elements that match a certain visibility using
|
10
10
|
# the `:visible` option. `:visible` accepts both boolean and symbols as
|
@@ -12,7 +12,8 @@ module RuboCop
|
|
12
12
|
# false` does not find just invisible elements, but both visible and
|
13
13
|
# invisible elements. For expressiveness and clarity, use one of the
|
14
14
|
# symbol values, `:all`, `:hidden` or `:visible`.
|
15
|
-
#
|
15
|
+
# Read more in
|
16
|
+
# https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
|
16
17
|
#
|
17
18
|
# @example
|
18
19
|
#
|
@@ -145,7 +145,7 @@ module RuboCop
|
|
145
145
|
return true unless body
|
146
146
|
return false if conditionals_with_examples?(body)
|
147
147
|
|
148
|
-
if body.if_type?
|
148
|
+
if body.if_type? || body.case_type?
|
149
149
|
!examples_in_branches?(body)
|
150
150
|
else
|
151
151
|
!examples?(body)
|
@@ -153,15 +153,15 @@ module RuboCop
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def conditionals_with_examples?(body)
|
156
|
-
return unless body.begin_type?
|
156
|
+
return unless body.begin_type? || body.case_type?
|
157
157
|
|
158
|
-
body.each_descendant(:if).any? do |
|
159
|
-
examples_in_branches?(
|
158
|
+
body.each_descendant(:if, :case).any? do |condition_node|
|
159
|
+
examples_in_branches?(condition_node)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
-
def examples_in_branches?(
|
164
|
-
|
163
|
+
def examples_in_branches?(condition_node)
|
164
|
+
condition_node.branches.any? { |branch| examples?(branch) }
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
@@ -17,24 +17,18 @@ module RuboCop
|
|
17
17
|
class EmptyLineAfterSubject < Base
|
18
18
|
extend AutoCorrector
|
19
19
|
include EmptyLineSeparation
|
20
|
+
include InsideExampleGroup
|
20
21
|
|
21
22
|
MSG = 'Add an empty line after `%<subject>s`.'
|
22
23
|
|
23
24
|
def on_block(node)
|
24
|
-
return unless subject?(node)
|
25
|
+
return unless subject?(node)
|
26
|
+
return unless inside_example_group?(node)
|
25
27
|
|
26
28
|
missing_separating_line_offense(node) do |method|
|
27
29
|
format(MSG, subject: method)
|
28
30
|
end
|
29
31
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def in_spec_block?(node)
|
34
|
-
node.each_ancestor(:block).any? do |ancestor|
|
35
|
-
Examples.all(ancestor.method_name)
|
36
|
-
end
|
37
|
-
end
|
38
32
|
end
|
39
33
|
end
|
40
34
|
end
|
@@ -33,11 +33,13 @@ module RuboCop
|
|
33
33
|
#
|
34
34
|
class LeadingSubject < Base
|
35
35
|
extend AutoCorrector
|
36
|
+
include InsideExampleGroup
|
36
37
|
|
37
38
|
MSG = 'Declare `subject` above any other `%<offending>s` declarations.'
|
38
39
|
|
39
40
|
def on_block(node)
|
40
|
-
return unless subject?(node)
|
41
|
+
return unless subject?(node)
|
42
|
+
return unless inside_example_group?(node)
|
41
43
|
|
42
44
|
check_previous_nodes(node)
|
43
45
|
end
|
@@ -78,12 +80,6 @@ module RuboCop
|
|
78
80
|
spec_group?(node) ||
|
79
81
|
include?(node)
|
80
82
|
end
|
81
|
-
|
82
|
-
def in_spec_block?(node)
|
83
|
-
node.each_ancestor(:block).any? do |ancestor|
|
84
|
-
example?(ancestor)
|
85
|
-
end
|
86
|
-
end
|
87
83
|
end
|
88
84
|
end
|
89
85
|
end
|
@@ -9,11 +9,11 @@ module RuboCop
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def inside_example_group?(node)
|
12
|
-
return
|
12
|
+
return spec_group?(node) if example_group_root?(node)
|
13
13
|
|
14
14
|
root = node.ancestors.find { |parent| example_group_root?(parent) }
|
15
15
|
|
16
|
-
|
16
|
+
spec_group?(root)
|
17
17
|
end
|
18
18
|
|
19
19
|
def example_group_root?(node)
|
@@ -7,6 +7,9 @@ module RuboCop
|
|
7
7
|
module RSpec
|
8
8
|
# Checks for stubbed test subjects.
|
9
9
|
#
|
10
|
+
# Checks nested subject stubs for innermost subject definition
|
11
|
+
# when subject is also defined in parent example groups.
|
12
|
+
#
|
10
13
|
# @see https://robots.thoughtbot.com/don-t-stub-the-system-under-test
|
11
14
|
# @see https://samphippen.com/introducing-rspec-smells-and-where-to-find-them#smell-1-stubject
|
12
15
|
# @see https://github.com/rubocop-hq/rspec-style-guide#dont-stub-subject
|
@@ -22,6 +25,20 @@ module RuboCop
|
|
22
25
|
# end
|
23
26
|
# end
|
24
27
|
#
|
28
|
+
# # bad
|
29
|
+
# describe Article do
|
30
|
+
# subject(:foo) { Article.new }
|
31
|
+
#
|
32
|
+
# context 'nested subject' do
|
33
|
+
# subject(:article) { Article.new }
|
34
|
+
#
|
35
|
+
# it 'indicates that the author is unknown' do
|
36
|
+
# allow(article).to receive(:author).and_return(nil)
|
37
|
+
# expect(article.description).to include('by an unknown author')
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
25
42
|
# # good
|
26
43
|
# describe Article do
|
27
44
|
# subject(:article) { Article.new(author: nil) }
|
@@ -36,27 +53,35 @@ module RuboCop
|
|
36
53
|
|
37
54
|
MSG = 'Do not stub methods of the object under test.'
|
38
55
|
|
39
|
-
# @!method subject(node)
|
56
|
+
# @!method subject?(node)
|
40
57
|
# Find a named or unnamed subject definition
|
41
58
|
#
|
42
59
|
# @example anonymous subject
|
43
|
-
# subject(parse('subject { foo }').ast) do |name|
|
60
|
+
# subject?(parse('subject { foo }').ast) do |name|
|
44
61
|
# name # => :subject
|
45
62
|
# end
|
46
63
|
#
|
47
64
|
# @example named subject
|
48
|
-
# subject(parse('subject(:thing) { foo }').ast) do |name|
|
65
|
+
# subject?(parse('subject(:thing) { foo }').ast) do |name|
|
49
66
|
# name # => :thing
|
50
67
|
# end
|
51
68
|
#
|
52
69
|
# @param node [RuboCop::AST::Node]
|
53
70
|
#
|
54
71
|
# @yield [Symbol] subject name
|
55
|
-
def_node_matcher :subject
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
72
|
+
def_node_matcher :subject?, <<-PATTERN
|
73
|
+
(block
|
74
|
+
(send nil?
|
75
|
+
{:subject (sym $_) | $:subject}
|
76
|
+
) args ...)
|
77
|
+
PATTERN
|
78
|
+
|
79
|
+
# @!method let?(node)
|
80
|
+
# Find a memoized helper
|
81
|
+
def_node_matcher :let?, <<-PATTERN
|
82
|
+
(block
|
83
|
+
(send nil? :let (sym $_)
|
84
|
+
) args ...)
|
60
85
|
PATTERN
|
61
86
|
|
62
87
|
# @!method message_expectation?(node, method_name)
|
@@ -73,7 +98,7 @@ module RuboCop
|
|
73
98
|
def_node_matcher :message_expectation?, <<-PATTERN
|
74
99
|
(send
|
75
100
|
{
|
76
|
-
(send nil? { :expect :allow } (send nil?
|
101
|
+
(send nil? { :expect :allow } (send nil? %))
|
77
102
|
(send nil? :is_expected)
|
78
103
|
}
|
79
104
|
#Runners.all
|
@@ -89,7 +114,8 @@ module RuboCop
|
|
89
114
|
PATTERN
|
90
115
|
|
91
116
|
def on_top_level_group(node)
|
92
|
-
@explicit_subjects =
|
117
|
+
@explicit_subjects = find_all_explicit(node, &method(:subject?))
|
118
|
+
@subject_overrides = find_all_explicit(node, &method(:let?))
|
93
119
|
|
94
120
|
find_subject_expectations(node) do |stub|
|
95
121
|
add_offense(stub)
|
@@ -98,12 +124,12 @@ module RuboCop
|
|
98
124
|
|
99
125
|
private
|
100
126
|
|
101
|
-
def
|
127
|
+
def find_all_explicit(node)
|
102
128
|
node.each_descendant(:block).with_object({}) do |child, h|
|
103
|
-
name =
|
129
|
+
name = yield(child)
|
104
130
|
next unless name
|
105
131
|
|
106
|
-
outer_example_group = child.each_ancestor.find do |a|
|
132
|
+
outer_example_group = child.each_ancestor(:block).find do |a|
|
107
133
|
example_group?(a)
|
108
134
|
end
|
109
135
|
|
@@ -113,14 +139,14 @@ module RuboCop
|
|
113
139
|
end
|
114
140
|
|
115
141
|
def find_subject_expectations(node, subject_names = [], &block)
|
116
|
-
subject_names =
|
142
|
+
subject_names = [*subject_names, *@explicit_subjects[node]]
|
143
|
+
subject_names -= @subject_overrides[node] if @subject_overrides[node]
|
117
144
|
|
118
|
-
|
119
|
-
|
120
|
-
end
|
145
|
+
names = Set[*subject_names, :subject]
|
146
|
+
expectation_detected = message_expectation?(node, names)
|
121
147
|
return yield(node) if expectation_detected
|
122
148
|
|
123
|
-
node.each_child_node do |child|
|
149
|
+
node.each_child_node(:send, :def, :block, :begin) do |child|
|
124
150
|
find_subject_expectations(child, subject_names, &block)
|
125
151
|
end
|
126
152
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Checks for consistent verified double reference style.
|
7
|
+
#
|
8
|
+
# Only investigates references that are one of the supported styles.
|
9
|
+
#
|
10
|
+
# @see https://relishapp.com/rspec/rspec-mocks/docs/verifying-doubles
|
11
|
+
#
|
12
|
+
# This cop can be configured in your configuration using the
|
13
|
+
# `EnforcedStyle` option and supports `--auto-gen-config`.
|
14
|
+
#
|
15
|
+
# @example `EnforcedStyle: constant` (default)
|
16
|
+
# # bad
|
17
|
+
# let(:foo) do
|
18
|
+
# instance_double('ClassName', method_name: 'returned_value')
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# let(:foo) do
|
23
|
+
# instance_double(ClassName, method_name: 'returned_value')
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# @example `EnforcedStyle: string`
|
27
|
+
# # bad
|
28
|
+
# let(:foo) do
|
29
|
+
# instance_double(ClassName, method_name: 'returned_value')
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# let(:foo) do
|
34
|
+
# instance_double('ClassName', method_name: 'returned_value')
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# @example Reference is not in the supported style list. No enforcement
|
38
|
+
#
|
39
|
+
# # good
|
40
|
+
# let(:foo) do
|
41
|
+
# instance_double(@klass, method_name: 'returned_value')
|
42
|
+
# end
|
43
|
+
class VerifiedDoubleReference < Base
|
44
|
+
extend AutoCorrector
|
45
|
+
include ConfigurableEnforcedStyle
|
46
|
+
|
47
|
+
MSG = 'Use a %<style>s class reference for verified doubles.'
|
48
|
+
|
49
|
+
RESTRICT_ON_SEND = Set[
|
50
|
+
:class_double,
|
51
|
+
:class_spy,
|
52
|
+
:instance_double,
|
53
|
+
:instance_spy,
|
54
|
+
:mock_model,
|
55
|
+
:object_double,
|
56
|
+
:object_spy,
|
57
|
+
:stub_model
|
58
|
+
].freeze
|
59
|
+
|
60
|
+
REFERENCE_TYPE_STYLES = {
|
61
|
+
str: :string,
|
62
|
+
const: :constant
|
63
|
+
}.freeze
|
64
|
+
|
65
|
+
# @!method verified_double(node)
|
66
|
+
def_node_matcher :verified_double, <<~PATTERN
|
67
|
+
(send
|
68
|
+
nil?
|
69
|
+
RESTRICT_ON_SEND
|
70
|
+
$_class_reference
|
71
|
+
...)
|
72
|
+
PATTERN
|
73
|
+
|
74
|
+
def on_send(node)
|
75
|
+
verified_double(node) do |class_reference|
|
76
|
+
break correct_style_detected unless opposing_style?(class_reference)
|
77
|
+
|
78
|
+
message = format(MSG, style: style)
|
79
|
+
expression = class_reference.loc.expression
|
80
|
+
|
81
|
+
add_offense(expression, message: message) do |corrector|
|
82
|
+
violation = class_reference.children.last.to_s
|
83
|
+
corrector.replace(expression, correct_style(violation))
|
84
|
+
|
85
|
+
opposite_style_detected
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def opposing_style?(class_reference)
|
93
|
+
class_reference_style = REFERENCE_TYPE_STYLES[class_reference.type]
|
94
|
+
|
95
|
+
# Only enforce supported styles
|
96
|
+
return false unless class_reference_style
|
97
|
+
|
98
|
+
class_reference_style != style
|
99
|
+
end
|
100
|
+
|
101
|
+
def correct_style(violation)
|
102
|
+
if style == :string
|
103
|
+
"'#{violation}'"
|
104
|
+
else
|
105
|
+
violation
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -21,7 +21,9 @@ require_relative 'rspec/align_right_let_brace'
|
|
21
21
|
require_relative 'rspec/any_instance'
|
22
22
|
require_relative 'rspec/around_block'
|
23
23
|
require_relative 'rspec/be'
|
24
|
+
require_relative 'rspec/be_eq'
|
24
25
|
require_relative 'rspec/be_eql'
|
26
|
+
require_relative 'rspec/be_nil'
|
25
27
|
require_relative 'rspec/before_after_all'
|
26
28
|
require_relative 'rspec/context_method'
|
27
29
|
require_relative 'rspec/context_wording'
|
@@ -95,6 +97,7 @@ require_relative 'rspec/subject_stub'
|
|
95
97
|
require_relative 'rspec/unspecified_exception'
|
96
98
|
require_relative 'rspec/variable_definition'
|
97
99
|
require_relative 'rspec/variable_name'
|
100
|
+
require_relative 'rspec/verified_double_reference'
|
98
101
|
require_relative 'rspec/verified_doubles'
|
99
102
|
require_relative 'rspec/void_expect'
|
100
103
|
require_relative 'rspec/yield'
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
class ConfigFormatter
|
9
9
|
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
|
10
10
|
SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
|
11
|
-
|
11
|
+
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'
|
12
12
|
|
13
13
|
def initialize(config, descriptions)
|
14
14
|
@config = config
|
@@ -27,9 +27,8 @@ module RuboCop
|
|
27
27
|
cops.each_with_object(config.dup) do |cop, unified|
|
28
28
|
next if SUBDEPARTMENTS.include?(cop)
|
29
29
|
|
30
|
-
unified[cop]
|
31
|
-
|
32
|
-
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
|
30
|
+
unified[cop].merge!(descriptions.fetch(cop))
|
31
|
+
unified[cop]['Reference'] = COP_DOC_BASE_URL + cop.sub('RSpec/', '')
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -37,16 +37,21 @@ require_relative 'rubocop/cop/rspec_cops'
|
|
37
37
|
# We have to register our autocorrect incompatibilities in RuboCop's cops
|
38
38
|
# as well so we do not hit infinite loops
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
[RSpec::AlignLeftLetBrace, RSpec::AlignRightLetBrace]
|
46
|
-
end
|
47
|
-
end
|
40
|
+
RuboCop::Cop::Layout::ExtraSpacing.singleton_class.prepend(
|
41
|
+
Module.new do
|
42
|
+
def autocorrect_incompatible_with
|
43
|
+
super.push(RuboCop::Cop::RSpec::AlignLeftLetBrace)
|
44
|
+
.push(RuboCop::Cop::RSpec::AlignRightLetBrace)
|
48
45
|
end
|
49
46
|
end
|
50
|
-
|
47
|
+
)
|
48
|
+
|
49
|
+
RuboCop::Cop::Style::TrailingCommaInArguments.singleton_class.prepend(
|
50
|
+
Module.new do
|
51
|
+
def autocorrect_incompatible_with
|
52
|
+
super.push(RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
)
|
51
56
|
|
52
57
|
RuboCop::AST::Node.include(RuboCop::RSpec::Node)
|
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.10.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: 2022-04-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -135,7 +135,9 @@ files:
|
|
135
135
|
- lib/rubocop/cop/rspec/around_block.rb
|
136
136
|
- lib/rubocop/cop/rspec/base.rb
|
137
137
|
- lib/rubocop/cop/rspec/be.rb
|
138
|
+
- lib/rubocop/cop/rspec/be_eq.rb
|
138
139
|
- lib/rubocop/cop/rspec/be_eql.rb
|
140
|
+
- lib/rubocop/cop/rspec/be_nil.rb
|
139
141
|
- lib/rubocop/cop/rspec/before_after_all.rb
|
140
142
|
- lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
|
141
143
|
- lib/rubocop/cop/rspec/capybara/feature_methods.rb
|
@@ -224,6 +226,7 @@ files:
|
|
224
226
|
- lib/rubocop/cop/rspec/unspecified_exception.rb
|
225
227
|
- lib/rubocop/cop/rspec/variable_definition.rb
|
226
228
|
- lib/rubocop/cop/rspec/variable_name.rb
|
229
|
+
- lib/rubocop/cop/rspec/verified_double_reference.rb
|
227
230
|
- lib/rubocop/cop/rspec/verified_doubles.rb
|
228
231
|
- lib/rubocop/cop/rspec/void_expect.rb
|
229
232
|
- lib/rubocop/cop/rspec/yield.rb
|