rubocop-rspec 1.39.0 → 1.43.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/CODE_OF_CONDUCT.md +17 -0
  4. data/README.md +1 -61
  5. data/config/default.yml +148 -20
  6. data/lib/rubocop-rspec.rb +4 -1
  7. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +12 -19
  8. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +12 -19
  9. data/lib/rubocop/cop/rspec/any_instance.rb +1 -1
  10. data/lib/rubocop/cop/rspec/around_block.rb +1 -1
  11. data/lib/rubocop/cop/rspec/base.rb +74 -0
  12. data/lib/rubocop/cop/rspec/be.rb +2 -2
  13. data/lib/rubocop/cop/rspec/be_eql.rb +6 -6
  14. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
  15. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +19 -17
  16. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +14 -12
  17. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +27 -12
  18. data/lib/rubocop/cop/rspec/context_method.rb +7 -9
  19. data/lib/rubocop/cop/rspec/context_wording.rb +3 -3
  20. data/lib/rubocop/cop/rspec/cop.rb +2 -86
  21. data/lib/rubocop/cop/rspec/describe_class.rb +20 -27
  22. data/lib/rubocop/cop/rspec/describe_method.rb +14 -6
  23. data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
  24. data/lib/rubocop/cop/rspec/described_class.rb +12 -9
  25. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -1
  26. data/lib/rubocop/cop/rspec/dialect.rb +5 -12
  27. data/lib/rubocop/cop/rspec/empty_example_group.rb +91 -7
  28. data/lib/rubocop/cop/rspec/empty_hook.rb +6 -10
  29. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +5 -7
  30. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +5 -9
  31. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +8 -8
  32. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +5 -9
  33. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +6 -6
  34. data/lib/rubocop/cop/rspec/example_length.rb +1 -1
  35. data/lib/rubocop/cop/rspec/example_without_description.rb +1 -1
  36. data/lib/rubocop/cop/rspec/example_wording.rb +10 -11
  37. data/lib/rubocop/cop/rspec/expect_actual.rb +8 -11
  38. data/lib/rubocop/cop/rspec/expect_change.rb +10 -35
  39. data/lib/rubocop/cop/rspec/expect_in_hook.rb +3 -3
  40. data/lib/rubocop/cop/rspec/expect_output.rb +2 -2
  41. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +24 -21
  42. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +20 -22
  43. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +7 -8
  44. data/lib/rubocop/cop/rspec/file_path.rb +54 -20
  45. data/lib/rubocop/cop/rspec/focus.rb +7 -11
  46. data/lib/rubocop/cop/rspec/hook_argument.rb +16 -23
  47. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +13 -14
  48. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +1 -1
  49. data/lib/rubocop/cop/rspec/implicit_expect.rb +7 -15
  50. data/lib/rubocop/cop/rspec/implicit_subject.rb +16 -11
  51. data/lib/rubocop/cop/rspec/instance_spy.rb +18 -12
  52. data/lib/rubocop/cop/rspec/instance_variable.rb +4 -8
  53. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +3 -6
  54. data/lib/rubocop/cop/rspec/it_behaves_like.rb +5 -6
  55. data/lib/rubocop/cop/rspec/iterated_expectation.rb +1 -1
  56. data/lib/rubocop/cop/rspec/leading_subject.rb +24 -21
  57. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +2 -5
  58. data/lib/rubocop/cop/rspec/let_before_examples.rb +13 -11
  59. data/lib/rubocop/cop/rspec/let_setup.rb +21 -6
  60. data/lib/rubocop/cop/rspec/message_chain.rb +7 -6
  61. data/lib/rubocop/cop/rspec/message_expectation.rb +2 -2
  62. data/lib/rubocop/cop/rspec/message_spies.rb +2 -3
  63. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
  64. data/lib/rubocop/cop/rspec/multiple_describes.rb +11 -8
  65. data/lib/rubocop/cop/rspec/multiple_expectations.rb +7 -11
  66. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +148 -0
  67. data/lib/rubocop/cop/rspec/multiple_subjects.rb +18 -19
  68. data/lib/rubocop/cop/rspec/named_subject.rb +2 -2
  69. data/lib/rubocop/cop/rspec/nested_groups.rb +12 -13
  70. data/lib/rubocop/cop/rspec/not_to_not.rb +5 -6
  71. data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
  72. data/lib/rubocop/cop/rspec/pending.rb +1 -1
  73. data/lib/rubocop/cop/rspec/predicate_matcher.rb +32 -69
  74. data/lib/rubocop/cop/rspec/rails/http_status.rb +7 -9
  75. data/lib/rubocop/cop/rspec/receive_counts.rb +15 -17
  76. data/lib/rubocop/cop/rspec/receive_never.rb +12 -12
  77. data/lib/rubocop/cop/rspec/repeated_description.rb +1 -1
  78. data/lib/rubocop/cop/rspec/repeated_example.rb +2 -2
  79. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +12 -2
  80. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +1 -1
  81. data/lib/rubocop/cop/rspec/return_from_stub.rb +12 -22
  82. data/lib/rubocop/cop/rspec/scattered_let.rb +8 -11
  83. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  84. data/lib/rubocop/cop/rspec/shared_context.rb +8 -21
  85. data/lib/rubocop/cop/rspec/shared_examples.rb +7 -9
  86. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +15 -18
  87. data/lib/rubocop/cop/rspec/subject_stub.rb +25 -53
  88. data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -1
  89. data/lib/rubocop/cop/rspec/variable_definition.rb +56 -0
  90. data/lib/rubocop/cop/rspec/variable_name.rb +66 -0
  91. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -1
  92. data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
  93. data/lib/rubocop/cop/rspec/yield.rb +14 -11
  94. data/lib/rubocop/cop/rspec_cops.rb +3 -0
  95. data/lib/rubocop/rspec/corrector/move_node.rb +7 -5
  96. data/lib/rubocop/rspec/description_extractor.rb +2 -6
  97. data/lib/rubocop/rspec/{blank_line_separation.rb → empty_line_separation.rb} +13 -10
  98. data/lib/rubocop/rspec/example_group.rb +21 -49
  99. data/lib/rubocop/rspec/factory_bot.rb +7 -1
  100. data/lib/rubocop/rspec/language.rb +6 -4
  101. data/lib/rubocop/rspec/language/node_pattern.rb +10 -1
  102. data/lib/rubocop/rspec/top_level_describe.rb +2 -2
  103. data/lib/rubocop/rspec/top_level_group.rb +57 -0
  104. data/lib/rubocop/rspec/variable.rb +16 -0
  105. data/lib/rubocop/rspec/version.rb +1 -1
  106. metadata +32 -11
@@ -4,7 +4,13 @@ module RuboCop
4
4
  module RSpec
5
5
  # RuboCop FactoryBot project namespace
6
6
  module FactoryBot
7
- ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
7
+ ATTRIBUTE_DEFINING_METHODS = %i[
8
+ factory
9
+ ignore
10
+ trait
11
+ traits_for_enum
12
+ transient
13
+ ].freeze
8
14
 
9
15
  UNPROXIED_METHODS = %i[
10
16
  __send__
@@ -4,8 +4,6 @@ module RuboCop
4
4
  module RSpec
5
5
  # RSpec public API methods that are commonly used in cops
6
6
  module Language
7
- RSPEC = '{(const {nil? cbase} :RSpec) nil?}'
8
-
9
7
  # Set of method selectors
10
8
  class SelectorSet
11
9
  def initialize(selectors)
@@ -29,7 +27,7 @@ module RuboCop
29
27
  end
30
28
 
31
29
  def block_pass_pattern
32
- "(send #{RSPEC} #{node_pattern_union} _ block_pass)"
30
+ "(send #rspec? #{node_pattern_union} _ block_pass)"
33
31
  end
34
32
 
35
33
  def block_or_block_pass_pattern
@@ -37,7 +35,11 @@ module RuboCop
37
35
  end
38
36
 
39
37
  def send_pattern
40
- "(send #{RSPEC} #{node_pattern_union} ...)"
38
+ "(send #rspec? #{node_pattern_union} ...)"
39
+ end
40
+
41
+ def send_or_block_or_block_pass_pattern
42
+ "{#{send_pattern} #{block_pattern} #{block_pass_pattern}}"
41
43
  end
42
44
 
43
45
  def node_pattern_union
@@ -7,10 +7,16 @@ module RuboCop
7
7
  module NodePattern
8
8
  extend RuboCop::NodePattern::Macros
9
9
 
10
+ def_node_matcher :rspec?, '{(const {nil? cbase} :RSpec) nil?}'
11
+
10
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
11
17
 
12
18
  def_node_matcher :example_group_with_body?, <<-PATTERN
13
- (block #{ExampleGroups::ALL.send_pattern} args [!nil?])
19
+ (block #{ExampleGroups::ALL.send_pattern} args !nil?)
14
20
  PATTERN
15
21
 
16
22
  def_node_matcher :example?, Examples::ALL.block_pattern
@@ -19,6 +25,9 @@ module RuboCop
19
25
 
20
26
  def_node_matcher :let?, Helpers::ALL.block_or_block_pass_pattern
21
27
 
28
+ def_node_matcher :include?,
29
+ Includes::ALL.send_or_block_or_block_pass_pattern
30
+
22
31
  def_node_matcher :subject?, Subject::ALL.block_pattern
23
32
  end
24
33
  end
@@ -16,7 +16,7 @@ module RuboCop
16
16
  private
17
17
 
18
18
  def top_level_describe?(node)
19
- return false unless node.method_name == :describe
19
+ return false unless node.method?(:describe)
20
20
 
21
21
  top_level_nodes.include?(node)
22
22
  end
@@ -44,7 +44,7 @@ module RuboCop
44
44
 
45
45
  def describe_statement_children(node)
46
46
  node.each_child_node(:send).select do |element|
47
- element.method_name == :describe
47
+ element.method?(:describe)
48
48
  end
49
49
  end
50
50
  end
@@ -0,0 +1,57 @@
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
+ example_group?(node, &method(:on_top_level_example_group))
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; end
33
+
34
+ def on_top_level_group; 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
@@ -0,0 +1,16 @@
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
@@ -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.39.0'
7
+ STRING = '1.43.1'
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.39.0
4
+ version: 1.43.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Backus
8
8
  - Ian MacLeod
9
9
  - Nils Gemeinhardt
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-05-01 00:00:00.000000000 Z
13
+ date: 2020-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 0.68.1
21
+ version: '0.87'
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.68.1
28
+ version: '0.87'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rack
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '3.4'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop-performance
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.7'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.7'
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: simplecov
73
87
  requirement: !ruby/object:Gem::Requirement
@@ -110,6 +124,7 @@ extra_rdoc_files:
110
124
  - README.md
111
125
  files:
112
126
  - CHANGELOG.md
127
+ - CODE_OF_CONDUCT.md
113
128
  - MIT-LICENSE.md
114
129
  - README.md
115
130
  - config/default.yml
@@ -118,6 +133,7 @@ files:
118
133
  - lib/rubocop/cop/rspec/align_right_let_brace.rb
119
134
  - lib/rubocop/cop/rspec/any_instance.rb
120
135
  - lib/rubocop/cop/rspec/around_block.rb
136
+ - lib/rubocop/cop/rspec/base.rb
121
137
  - lib/rubocop/cop/rspec/be.rb
122
138
  - lib/rubocop/cop/rspec/be_eql.rb
123
139
  - lib/rubocop/cop/rspec/before_after_all.rb
@@ -172,6 +188,7 @@ files:
172
188
  - lib/rubocop/cop/rspec/missing_example_group_argument.rb
173
189
  - lib/rubocop/cop/rspec/multiple_describes.rb
174
190
  - lib/rubocop/cop/rspec/multiple_expectations.rb
191
+ - lib/rubocop/cop/rspec/multiple_memoized_helpers.rb
175
192
  - lib/rubocop/cop/rspec/multiple_subjects.rb
176
193
  - lib/rubocop/cop/rspec/named_subject.rb
177
194
  - lib/rubocop/cop/rspec/nested_groups.rb
@@ -194,17 +211,19 @@ files:
194
211
  - lib/rubocop/cop/rspec/single_argument_message_chain.rb
195
212
  - lib/rubocop/cop/rspec/subject_stub.rb
196
213
  - lib/rubocop/cop/rspec/unspecified_exception.rb
214
+ - lib/rubocop/cop/rspec/variable_definition.rb
215
+ - lib/rubocop/cop/rspec/variable_name.rb
197
216
  - lib/rubocop/cop/rspec/verified_doubles.rb
198
217
  - lib/rubocop/cop/rspec/void_expect.rb
199
218
  - lib/rubocop/cop/rspec/yield.rb
200
219
  - lib/rubocop/cop/rspec_cops.rb
201
220
  - lib/rubocop/rspec.rb
202
221
  - lib/rubocop/rspec/align_let_brace.rb
203
- - lib/rubocop/rspec/blank_line_separation.rb
204
222
  - lib/rubocop/rspec/concept.rb
205
223
  - lib/rubocop/rspec/config_formatter.rb
206
224
  - lib/rubocop/rspec/corrector/move_node.rb
207
225
  - lib/rubocop/rspec/description_extractor.rb
226
+ - lib/rubocop/rspec/empty_line_separation.rb
208
227
  - lib/rubocop/rspec/example.rb
209
228
  - lib/rubocop/rspec/example_group.rb
210
229
  - lib/rubocop/rspec/factory_bot.rb
@@ -215,6 +234,8 @@ files:
215
234
  - lib/rubocop/rspec/language/node_pattern.rb
216
235
  - lib/rubocop/rspec/node.rb
217
236
  - lib/rubocop/rspec/top_level_describe.rb
237
+ - lib/rubocop/rspec/top_level_group.rb
238
+ - lib/rubocop/rspec/variable.rb
218
239
  - lib/rubocop/rspec/version.rb
219
240
  - lib/rubocop/rspec/wording.rb
220
241
  homepage: https://github.com/rubocop-hq/rubocop-rspec
@@ -223,7 +244,7 @@ licenses:
223
244
  metadata:
224
245
  changelog_uri: https://github.com/rubocop-hq/rubocop-rspec/blob/master/CHANGELOG.md
225
246
  documentation_uri: https://rubocop-rspec.readthedocs.io/
226
- post_install_message:
247
+ post_install_message:
227
248
  rdoc_options: []
228
249
  require_paths:
229
250
  - lib
@@ -238,8 +259,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
259
  - !ruby/object:Gem::Version
239
260
  version: '0'
240
261
  requirements: []
241
- rubygems_version: 3.1.2
242
- signing_key:
262
+ rubygems_version: 3.0.3
263
+ signing_key:
243
264
  specification_version: 4
244
265
  summary: Code style checking for RSpec files
245
266
  test_files: []