rubocop-rspec 1.43.2 → 2.0.1

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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -4
  3. data/README.md +5 -1
  4. data/config/default.yml +183 -67
  5. data/lib/rubocop-rspec.rb +7 -8
  6. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +7 -3
  7. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +7 -3
  8. data/lib/rubocop/cop/rspec/around_block.rb +2 -2
  9. data/lib/rubocop/cop/rspec/base.rb +7 -54
  10. data/lib/rubocop/cop/rspec/be.rb +2 -2
  11. data/lib/rubocop/cop/rspec/before_after_all.rb +3 -3
  12. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +2 -2
  13. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -2
  14. data/lib/rubocop/cop/rspec/describe_class.rb +34 -15
  15. data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
  16. data/lib/rubocop/cop/rspec/described_class.rb +1 -2
  17. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -2
  18. data/lib/rubocop/cop/rspec/dialect.rb +1 -1
  19. data/lib/rubocop/cop/rspec/empty_example_group.rb +33 -38
  20. data/lib/rubocop/cop/rspec/empty_hook.rb +1 -1
  21. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +1 -1
  22. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  23. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
  24. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
  25. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +2 -2
  26. data/lib/rubocop/cop/rspec/expect_actual.rb +2 -1
  27. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  28. data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
  29. data/lib/rubocop/cop/rspec/file_path.rb +1 -1
  30. data/lib/rubocop/cop/rspec/focus.rb +13 -7
  31. data/lib/rubocop/cop/rspec/hook_argument.rb +2 -4
  32. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -2
  33. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +1 -2
  34. data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -1
  35. data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
  36. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
  37. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
  38. data/lib/rubocop/cop/rspec/iterated_expectation.rb +1 -1
  39. data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -2
  40. data/lib/rubocop/cop/rspec/let_setup.rb +7 -4
  41. data/lib/rubocop/cop/rspec/message_spies.rb +3 -3
  42. data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +51 -0
  43. data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
  44. data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
  45. data/lib/rubocop/cop/rspec/mixin/variable.rb +20 -0
  46. data/lib/rubocop/cop/rspec/multiple_describes.rb +2 -3
  47. data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
  48. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +3 -1
  49. data/lib/rubocop/cop/rspec/named_subject.rb +8 -12
  50. data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
  51. data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -1
  52. data/lib/rubocop/cop/rspec/pending.rb +13 -5
  53. data/lib/rubocop/cop/rspec/predicate_matcher.rb +3 -3
  54. data/lib/rubocop/cop/rspec/repeated_include_example.rb +104 -0
  55. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  56. data/lib/rubocop/cop/rspec/shared_context.rb +18 -11
  57. data/lib/rubocop/cop/rspec/shared_examples.rb +3 -1
  58. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +1 -1
  59. data/lib/rubocop/cop/rspec/stubbed_mock.rb +172 -0
  60. data/lib/rubocop/cop/rspec/subject_stub.rb +20 -10
  61. data/lib/rubocop/cop/rspec/variable_definition.rb +1 -1
  62. data/lib/rubocop/cop/rspec/variable_name.rb +1 -1
  63. data/lib/rubocop/cop/rspec_cops.rb +2 -1
  64. data/lib/rubocop/rspec/align_let_brace.rb +1 -1
  65. data/lib/rubocop/rspec/concept.rb +2 -2
  66. data/lib/rubocop/rspec/config_formatter.rb +5 -3
  67. data/lib/rubocop/rspec/corrector/move_node.rb +1 -1
  68. data/lib/rubocop/rspec/example_group.rb +15 -5
  69. data/lib/rubocop/rspec/hook.rb +2 -6
  70. data/lib/rubocop/rspec/inject.rb +4 -2
  71. data/lib/rubocop/rspec/language.rb +144 -105
  72. data/lib/rubocop/rspec/language/node_pattern.rb +7 -24
  73. data/lib/rubocop/rspec/node.rb +1 -1
  74. data/lib/rubocop/rspec/version.rb +1 -1
  75. metadata +25 -13
  76. data/lib/rubocop/cop/rspec/cop.rb +0 -10
  77. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +0 -41
  78. data/lib/rubocop/rspec.rb +0 -12
  79. data/lib/rubocop/rspec/empty_line_separation.rb +0 -48
  80. data/lib/rubocop/rspec/final_end_location.rb +0 -17
  81. data/lib/rubocop/rspec/top_level_describe.rb +0 -52
  82. data/lib/rubocop/rspec/top_level_group.rb +0 -57
  83. 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
- # Common node matchers used for matching against the rspec DSL
6
+ # Helper methods to detect RSpec DSL used with send and block
7
7
  module NodePattern
8
- extend RuboCop::NodePattern::Macros
8
+ def send_pattern(string)
9
+ "(send #rspec? #{string} ...)"
10
+ end
9
11
 
10
- def_node_matcher :rspec?, '{(const {nil? cbase} :RSpec) nil?}'
11
-
12
- def_node_matcher :example_group?, ExampleGroups::ALL.block_pattern
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module RSpec
5
- # RuboCop-RSpec specific extensions of RuboCop::AST::Node
5
+ # RuboCop RSpec specific extensions of RuboCop::AST::Node
6
6
  module Node
7
7
  # In various cops we want to regard const as literal althought it's not
8
8
  # strictly literal.
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec RuboCop plugin.
6
6
  module Version
7
- STRING = '1.43.2'
7
+ STRING = '2.0.1'
8
8
  end
9
9
  end
10
10
  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: 1.43.2
4
+ version: 2.0.1
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-08-25 00:00:00.000000000 Z
13
+ date: 2020-12-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -18,14 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '0.87'
21
+ version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '0.87'
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
@@ -203,12 +219,14 @@ files:
203
219
  - lib/rubocop/cop/rspec/repeated_example.rb
204
220
  - lib/rubocop/cop/rspec/repeated_example_group_body.rb
205
221
  - lib/rubocop/cop/rspec/repeated_example_group_description.rb
222
+ - lib/rubocop/cop/rspec/repeated_include_example.rb
206
223
  - lib/rubocop/cop/rspec/return_from_stub.rb
207
224
  - lib/rubocop/cop/rspec/scattered_let.rb
208
225
  - lib/rubocop/cop/rspec/scattered_setup.rb
209
226
  - lib/rubocop/cop/rspec/shared_context.rb
210
227
  - lib/rubocop/cop/rspec/shared_examples.rb
211
228
  - lib/rubocop/cop/rspec/single_argument_message_chain.rb
229
+ - lib/rubocop/cop/rspec/stubbed_mock.rb
212
230
  - lib/rubocop/cop/rspec/subject_stub.rb
213
231
  - lib/rubocop/cop/rspec/unspecified_exception.rb
214
232
  - lib/rubocop/cop/rspec/variable_definition.rb
@@ -217,25 +235,19 @@ files:
217
235
  - lib/rubocop/cop/rspec/void_expect.rb
218
236
  - lib/rubocop/cop/rspec/yield.rb
219
237
  - lib/rubocop/cop/rspec_cops.rb
220
- - lib/rubocop/rspec.rb
221
238
  - lib/rubocop/rspec/align_let_brace.rb
222
239
  - lib/rubocop/rspec/concept.rb
223
240
  - lib/rubocop/rspec/config_formatter.rb
224
241
  - lib/rubocop/rspec/corrector/move_node.rb
225
242
  - lib/rubocop/rspec/description_extractor.rb
226
- - lib/rubocop/rspec/empty_line_separation.rb
227
243
  - lib/rubocop/rspec/example.rb
228
244
  - lib/rubocop/rspec/example_group.rb
229
245
  - lib/rubocop/rspec/factory_bot.rb
230
- - lib/rubocop/rspec/final_end_location.rb
231
246
  - lib/rubocop/rspec/hook.rb
232
247
  - lib/rubocop/rspec/inject.rb
233
248
  - lib/rubocop/rspec/language.rb
234
249
  - lib/rubocop/rspec/language/node_pattern.rb
235
250
  - lib/rubocop/rspec/node.rb
236
- - lib/rubocop/rspec/top_level_describe.rb
237
- - lib/rubocop/rspec/top_level_group.rb
238
- - lib/rubocop/rspec/variable.rb
239
251
  - lib/rubocop/rspec/version.rb
240
252
  - lib/rubocop/rspec/wording.rb
241
253
  homepage: https://github.com/rubocop-hq/rubocop-rspec
@@ -243,7 +255,7 @@ licenses:
243
255
  - MIT
244
256
  metadata:
245
257
  changelog_uri: https://github.com/rubocop-hq/rubocop-rspec/blob/master/CHANGELOG.md
246
- documentation_uri: https://rubocop-rspec.readthedocs.io/
258
+ documentation_uri: https://docs.rubocop.org/rubocop-rspec/
247
259
  post_install_message:
248
260
  rdoc_options: []
249
261
  require_paths:
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- # @deprecated Use ::RuboCop::Cop::RSpec::Base instead
7
- Cop = Base
8
- end
9
- end
10
- end
@@ -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
@@ -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