rubocop-rspec 2.0.0.pre → 2.0.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 +12 -2
- data/README.md +4 -0
- data/config/default.yml +100 -18
- data/lib/rubocop-rspec.rb +7 -8
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +7 -3
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +7 -3
- data/lib/rubocop/cop/rspec/base.rb +6 -55
- data/lib/rubocop/cop/rspec/be.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +2 -2
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -2
- data/lib/rubocop/cop/rspec/describe_class.rb +1 -1
- data/lib/rubocop/cop/rspec/describe_method.rb +1 -1
- data/lib/rubocop/cop/rspec/described_class.rb +1 -2
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -2
- data/lib/rubocop/cop/rspec/dialect.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_example_group.rb +6 -45
- data/lib/rubocop/cop/rspec/empty_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_subject.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/file_path.rb +1 -1
- data/lib/rubocop/cop/rspec/focus.rb +13 -7
- data/lib/rubocop/cop/rspec/hook_argument.rb +2 -4
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -2
- data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
- data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -2
- data/lib/rubocop/cop/rspec/let_setup.rb +7 -4
- data/lib/rubocop/cop/rspec/message_spies.rb +1 -1
- data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +51 -0
- data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
- data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
- data/lib/rubocop/cop/rspec/mixin/variable.rb +20 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +3 -1
- data/lib/rubocop/cop/rspec/named_subject.rb +8 -12
- data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -1
- data/lib/rubocop/cop/rspec/pending.rb +13 -5
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +3 -3
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -2
- data/lib/rubocop/cop/rspec/shared_context.rb +16 -6
- data/lib/rubocop/cop/rspec/shared_examples.rb +3 -1
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +2 -2
- data/lib/rubocop/cop/rspec/variable_definition.rb +1 -1
- data/lib/rubocop/cop/rspec/variable_name.rb +1 -1
- data/lib/rubocop/cop/rspec_cops.rb +0 -1
- data/lib/rubocop/rspec/align_let_brace.rb +1 -1
- data/lib/rubocop/rspec/concept.rb +2 -2
- data/lib/rubocop/rspec/config_formatter.rb +3 -3
- data/lib/rubocop/rspec/corrector/move_node.rb +1 -1
- data/lib/rubocop/rspec/example_group.rb +15 -5
- data/lib/rubocop/rspec/hook.rb +1 -1
- data/lib/rubocop/rspec/inject.rb +4 -2
- data/lib/rubocop/rspec/language.rb +143 -109
- data/lib/rubocop/rspec/language/node_pattern.rb +7 -24
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +22 -12
- data/lib/rubocop/cop/rspec/cop.rb +0 -10
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +0 -41
- data/lib/rubocop/rspec.rb +0 -12
- data/lib/rubocop/rspec/empty_line_separation.rb +0 -48
- data/lib/rubocop/rspec/final_end_location.rb +0 -17
- data/lib/rubocop/rspec/top_level_describe.rb +0 -52
- data/lib/rubocop/rspec/top_level_group.rb +0 -57
- data/lib/rubocop/rspec/variable.rb +0 -16
@@ -3,32 +3,15 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module RSpec
|
5
5
|
module Language
|
6
|
-
#
|
6
|
+
# Helper methods to detect RSpec DSL used with send and block
|
7
7
|
module NodePattern
|
8
|
-
|
8
|
+
def send_pattern(string)
|
9
|
+
"(send #rspec? #{string} ...)"
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern
|
14
|
-
|
15
|
-
spec_groups = ExampleGroups::ALL + SharedGroups::ALL
|
16
|
-
def_node_matcher :spec_group?, spec_groups.block_pattern
|
17
|
-
|
18
|
-
def_node_matcher :example_group_with_body?, <<-PATTERN
|
19
|
-
(block #{ExampleGroups::ALL.send_pattern} args !nil?)
|
20
|
-
PATTERN
|
21
|
-
|
22
|
-
def_node_matcher :example?, Examples::ALL.block_pattern
|
23
|
-
|
24
|
-
def_node_matcher :hook?, Hooks::ALL.block_pattern
|
25
|
-
|
26
|
-
def_node_matcher :let?, Helpers::ALL.block_or_block_pass_pattern
|
27
|
-
|
28
|
-
def_node_matcher :include?,
|
29
|
-
Includes::ALL.send_or_block_or_block_pass_pattern
|
30
|
-
|
31
|
-
def_node_matcher :subject?, Subject::ALL.block_pattern
|
12
|
+
def block_pattern(string)
|
13
|
+
"(block #{send_pattern(string)} ...)"
|
14
|
+
end
|
32
15
|
end
|
33
16
|
end
|
34
17
|
end
|
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.0.0
|
4
|
+
version: 2.0.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: 2020-
|
13
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rubocop-ast
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.1.0
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.1.0
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: rack
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +156,6 @@ files:
|
|
142
156
|
- lib/rubocop/cop/rspec/capybara/visibility_matcher.rb
|
143
157
|
- lib/rubocop/cop/rspec/context_method.rb
|
144
158
|
- lib/rubocop/cop/rspec/context_wording.rb
|
145
|
-
- lib/rubocop/cop/rspec/cop.rb
|
146
159
|
- lib/rubocop/cop/rspec/describe_class.rb
|
147
160
|
- lib/rubocop/cop/rspec/describe_method.rb
|
148
161
|
- lib/rubocop/cop/rspec/describe_symbol.rb
|
@@ -175,7 +188,6 @@ files:
|
|
175
188
|
- lib/rubocop/cop/rspec/implicit_subject.rb
|
176
189
|
- lib/rubocop/cop/rspec/instance_spy.rb
|
177
190
|
- lib/rubocop/cop/rspec/instance_variable.rb
|
178
|
-
- lib/rubocop/cop/rspec/invalid_predicate_matcher.rb
|
179
191
|
- lib/rubocop/cop/rspec/it_behaves_like.rb
|
180
192
|
- lib/rubocop/cop/rspec/iterated_expectation.rb
|
181
193
|
- lib/rubocop/cop/rspec/leading_subject.rb
|
@@ -186,6 +198,10 @@ files:
|
|
186
198
|
- lib/rubocop/cop/rspec/message_expectation.rb
|
187
199
|
- lib/rubocop/cop/rspec/message_spies.rb
|
188
200
|
- lib/rubocop/cop/rspec/missing_example_group_argument.rb
|
201
|
+
- lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
|
202
|
+
- lib/rubocop/cop/rspec/mixin/final_end_location.rb
|
203
|
+
- lib/rubocop/cop/rspec/mixin/top_level_group.rb
|
204
|
+
- lib/rubocop/cop/rspec/mixin/variable.rb
|
189
205
|
- lib/rubocop/cop/rspec/multiple_describes.rb
|
190
206
|
- lib/rubocop/cop/rspec/multiple_expectations.rb
|
191
207
|
- lib/rubocop/cop/rspec/multiple_memoized_helpers.rb
|
@@ -219,25 +235,19 @@ files:
|
|
219
235
|
- lib/rubocop/cop/rspec/void_expect.rb
|
220
236
|
- lib/rubocop/cop/rspec/yield.rb
|
221
237
|
- lib/rubocop/cop/rspec_cops.rb
|
222
|
-
- lib/rubocop/rspec.rb
|
223
238
|
- lib/rubocop/rspec/align_let_brace.rb
|
224
239
|
- lib/rubocop/rspec/concept.rb
|
225
240
|
- lib/rubocop/rspec/config_formatter.rb
|
226
241
|
- lib/rubocop/rspec/corrector/move_node.rb
|
227
242
|
- lib/rubocop/rspec/description_extractor.rb
|
228
|
-
- lib/rubocop/rspec/empty_line_separation.rb
|
229
243
|
- lib/rubocop/rspec/example.rb
|
230
244
|
- lib/rubocop/rspec/example_group.rb
|
231
245
|
- lib/rubocop/rspec/factory_bot.rb
|
232
|
-
- lib/rubocop/rspec/final_end_location.rb
|
233
246
|
- lib/rubocop/rspec/hook.rb
|
234
247
|
- lib/rubocop/rspec/inject.rb
|
235
248
|
- lib/rubocop/rspec/language.rb
|
236
249
|
- lib/rubocop/rspec/language/node_pattern.rb
|
237
250
|
- lib/rubocop/rspec/node.rb
|
238
|
-
- lib/rubocop/rspec/top_level_describe.rb
|
239
|
-
- lib/rubocop/rspec/top_level_group.rb
|
240
|
-
- lib/rubocop/rspec/variable.rb
|
241
251
|
- lib/rubocop/rspec/version.rb
|
242
252
|
- lib/rubocop/rspec/wording.rb
|
243
253
|
homepage: https://github.com/rubocop-hq/rubocop-rspec
|
@@ -257,9 +267,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
267
|
version: 2.4.0
|
258
268
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
269
|
requirements:
|
260
|
-
- - "
|
270
|
+
- - ">="
|
261
271
|
- !ruby/object:Gem::Version
|
262
|
-
version:
|
272
|
+
version: '0'
|
263
273
|
requirements: []
|
264
274
|
rubygems_version: 3.0.3
|
265
275
|
signing_key:
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module RSpec
|
6
|
-
# Checks invalid usage for predicate matcher.
|
7
|
-
#
|
8
|
-
# Predicate matcher does not need a question.
|
9
|
-
# This cop checks an unnecessary question in predicate matcher.
|
10
|
-
#
|
11
|
-
# @example
|
12
|
-
#
|
13
|
-
# # bad
|
14
|
-
# expect(foo).to be_something?
|
15
|
-
#
|
16
|
-
# # good
|
17
|
-
# expect(foo).to be_something
|
18
|
-
class InvalidPredicateMatcher < Base
|
19
|
-
MSG = 'Omit `?` from `%<matcher>s`.'
|
20
|
-
|
21
|
-
def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
|
22
|
-
(send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?))
|
23
|
-
PATTERN
|
24
|
-
|
25
|
-
def on_send(node)
|
26
|
-
invalid_predicate_matcher?(node) do |predicate|
|
27
|
-
add_offense(predicate,
|
28
|
-
message: format(MSG, matcher: predicate.method_name))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def predicate?(name)
|
35
|
-
name = name.to_s
|
36
|
-
name.start_with?('be_', 'have_') && name.end_with?('?')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/rubocop/rspec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
# RuboCop RSpec project namespace
|
5
|
-
module RSpec
|
6
|
-
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
7
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
8
|
-
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
9
|
-
|
10
|
-
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
11
|
-
end
|
12
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helps determine the offending location if there is not an empty line
|
6
|
-
# following the node. Allows comments to follow directly after.
|
7
|
-
module EmptyLineSeparation
|
8
|
-
include FinalEndLocation
|
9
|
-
include RuboCop::Cop::RangeHelp
|
10
|
-
|
11
|
-
def missing_separating_line_offense(node)
|
12
|
-
return if last_child?(node)
|
13
|
-
|
14
|
-
missing_separating_line(node) do |location|
|
15
|
-
msg = yield(node.method_name)
|
16
|
-
add_offense(location, message: msg) do |corrector|
|
17
|
-
corrector.insert_after(location.end, "\n")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def missing_separating_line(node)
|
23
|
-
line = final_end_location(node).line
|
24
|
-
|
25
|
-
line += 1 while comment_line?(processed_source[line])
|
26
|
-
|
27
|
-
return if processed_source[line].blank?
|
28
|
-
|
29
|
-
yield offending_loc(line)
|
30
|
-
end
|
31
|
-
|
32
|
-
def offending_loc(last_line)
|
33
|
-
offending_line = processed_source[last_line - 1]
|
34
|
-
|
35
|
-
content_length = offending_line.lstrip.length
|
36
|
-
start = offending_line.length - content_length
|
37
|
-
|
38
|
-
source_range(processed_source.buffer, last_line, start, content_length)
|
39
|
-
end
|
40
|
-
|
41
|
-
def last_child?(node)
|
42
|
-
return true unless node.parent&.begin_type?
|
43
|
-
|
44
|
-
node.equal?(node.parent.children.last)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helps find the true end location of nodes which might contain heredocs.
|
6
|
-
module FinalEndLocation
|
7
|
-
def final_end_location(start_node)
|
8
|
-
heredoc_endings =
|
9
|
-
start_node.each_node(:str, :dstr, :xstr)
|
10
|
-
.select(&:heredoc?)
|
11
|
-
.map { |node| node.loc.heredoc_end }
|
12
|
-
|
13
|
-
[start_node.loc.end, *heredoc_endings].max_by(&:line)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helper methods for top level describe cops
|
6
|
-
module TopLevelDescribe
|
7
|
-
extend NodePattern::Macros
|
8
|
-
|
9
|
-
def on_send(node)
|
10
|
-
return unless respond_to?(:on_top_level_describe)
|
11
|
-
return unless top_level_describe?(node)
|
12
|
-
|
13
|
-
on_top_level_describe(node, node.arguments)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def top_level_describe?(node)
|
19
|
-
return false unless node.method?(:describe)
|
20
|
-
|
21
|
-
top_level_nodes.include?(node)
|
22
|
-
end
|
23
|
-
|
24
|
-
def top_level_nodes
|
25
|
-
nodes = describe_statement_children(root_node)
|
26
|
-
# If we have no top level describe statements, we need to check any
|
27
|
-
# blocks on the top level (e.g. after a require).
|
28
|
-
if nodes.empty?
|
29
|
-
nodes = root_node.each_child_node(:block).flat_map do |child|
|
30
|
-
describe_statement_children(child)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
nodes
|
35
|
-
end
|
36
|
-
|
37
|
-
def root_node
|
38
|
-
processed_source.ast
|
39
|
-
end
|
40
|
-
|
41
|
-
def single_top_level_describe?
|
42
|
-
top_level_nodes.one?
|
43
|
-
end
|
44
|
-
|
45
|
-
def describe_statement_children(node)
|
46
|
-
node.each_child_node(:send).select do |element|
|
47
|
-
element.method?(:describe)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helper methods for top level example group cops
|
6
|
-
module TopLevelGroup
|
7
|
-
extend RuboCop::NodePattern::Macros
|
8
|
-
include RuboCop::RSpec::Language
|
9
|
-
|
10
|
-
def_node_matcher :example_or_shared_group?,
|
11
|
-
(ExampleGroups::ALL + SharedGroups::ALL).block_pattern
|
12
|
-
|
13
|
-
def on_new_investigation
|
14
|
-
super
|
15
|
-
|
16
|
-
return unless root_node
|
17
|
-
|
18
|
-
top_level_groups.each do |node|
|
19
|
-
on_top_level_example_group(node) if example_group?(node)
|
20
|
-
on_top_level_group(node)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def top_level_groups
|
25
|
-
@top_level_groups ||=
|
26
|
-
top_level_nodes(root_node).select { |n| example_or_shared_group?(n) }
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
# Dummy methods to be overridden in the consumer
|
32
|
-
def on_top_level_example_group(_node); end
|
33
|
-
|
34
|
-
def on_top_level_group(_node); end
|
35
|
-
|
36
|
-
def top_level_group?(node)
|
37
|
-
top_level_groups.include?(node)
|
38
|
-
end
|
39
|
-
|
40
|
-
def top_level_nodes(node)
|
41
|
-
if node.nil?
|
42
|
-
[]
|
43
|
-
elsif node.begin_type?
|
44
|
-
node.children
|
45
|
-
elsif node.module_type? || node.class_type?
|
46
|
-
top_level_nodes(node.body)
|
47
|
-
else
|
48
|
-
[node]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def root_node
|
53
|
-
processed_source.ast
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helps check offenses with variable definitions
|
6
|
-
module Variable
|
7
|
-
include Language
|
8
|
-
extend RuboCop::NodePattern::Macros
|
9
|
-
|
10
|
-
def_node_matcher :variable_definition?, <<~PATTERN
|
11
|
-
(send nil? #{(Helpers::ALL + Subject::ALL).node_pattern_union}
|
12
|
-
$({sym str dsym dstr} ...) ...)
|
13
|
-
PATTERN
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|