rubocop-rspec 2.2.0 → 2.6.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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -0
  3. data/README.md +3 -5
  4. data/config/default.yml +79 -3
  5. data/lib/rubocop/cop/rspec/around_block.rb +2 -0
  6. data/lib/rubocop/cop/rspec/be.rb +1 -0
  7. data/lib/rubocop/cop/rspec/be_eql.rb +1 -0
  8. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -0
  9. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +3 -0
  10. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -0
  11. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +2 -0
  12. data/lib/rubocop/cop/rspec/context_method.rb +1 -0
  13. data/lib/rubocop/cop/rspec/context_wording.rb +7 -1
  14. data/lib/rubocop/cop/rspec/describe_class.rb +3 -0
  15. data/lib/rubocop/cop/rspec/describe_method.rb +1 -0
  16. data/lib/rubocop/cop/rspec/describe_symbol.rb +1 -0
  17. data/lib/rubocop/cop/rspec/described_class.rb +6 -1
  18. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +2 -1
  19. data/lib/rubocop/cop/rspec/dialect.rb +1 -0
  20. data/lib/rubocop/cop/rspec/empty_hook.rb +5 -1
  21. data/lib/rubocop/cop/rspec/example_length.rb +26 -12
  22. data/lib/rubocop/cop/rspec/example_without_description.rb +1 -0
  23. data/lib/rubocop/cop/rspec/example_wording.rb +4 -0
  24. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +100 -0
  25. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -0
  26. data/lib/rubocop/cop/rspec/expect_change.rb +5 -3
  27. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -0
  28. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +3 -0
  29. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +3 -0
  30. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -0
  31. data/lib/rubocop/cop/rspec/file_path.rb +13 -9
  32. data/lib/rubocop/cop/rspec/focus.rb +3 -0
  33. data/lib/rubocop/cop/rspec/hook_argument.rb +3 -1
  34. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -0
  35. data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +38 -0
  36. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +3 -0
  37. data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -0
  38. data/lib/rubocop/cop/rspec/implicit_subject.rb +18 -1
  39. data/lib/rubocop/cop/rspec/instance_spy.rb +2 -0
  40. data/lib/rubocop/cop/rspec/instance_variable.rb +4 -0
  41. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -0
  42. data/lib/rubocop/cop/rspec/iterated_expectation.rb +4 -0
  43. data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -0
  44. data/lib/rubocop/cop/rspec/let_setup.rb +3 -0
  45. data/lib/rubocop/cop/rspec/message_expectation.rb +2 -0
  46. data/lib/rubocop/cop/rspec/message_spies.rb +2 -0
  47. data/lib/rubocop/cop/rspec/mixin/variable.rb +1 -0
  48. data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -0
  49. data/lib/rubocop/cop/rspec/named_subject.rb +3 -0
  50. data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
  51. data/lib/rubocop/cop/rspec/not_to_not.rb +1 -0
  52. data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -0
  53. data/lib/rubocop/cop/rspec/pending.rb +4 -0
  54. data/lib/rubocop/cop/rspec/predicate_matcher.rb +5 -0
  55. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +44 -0
  56. data/lib/rubocop/cop/rspec/rails/http_status.rb +1 -0
  57. data/lib/rubocop/cop/rspec/receive_counts.rb +2 -0
  58. data/lib/rubocop/cop/rspec/receive_never.rb +1 -0
  59. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +8 -1
  60. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +4 -0
  61. data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -0
  62. data/lib/rubocop/cop/rspec/return_from_stub.rb +5 -0
  63. data/lib/rubocop/cop/rspec/shared_context.rb +4 -0
  64. data/lib/rubocop/cop/rspec/shared_examples.rb +1 -0
  65. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +2 -0
  66. data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -0
  67. data/lib/rubocop/cop/rspec/subject_declaration.rb +47 -0
  68. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -0
  69. data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -0
  70. data/lib/rubocop/cop/rspec/variable_definition.rb +19 -2
  71. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -0
  72. data/lib/rubocop/cop/rspec/void_expect.rb +2 -0
  73. data/lib/rubocop/cop/rspec/yield.rb +3 -0
  74. data/lib/rubocop/cop/rspec_cops.rb +4 -0
  75. data/lib/rubocop/rspec/align_let_brace.rb +2 -1
  76. data/lib/rubocop/rspec/config_formatter.rb +3 -0
  77. data/lib/rubocop/rspec/example.rb +5 -0
  78. data/lib/rubocop/rspec/hook.rb +1 -0
  79. data/lib/rubocop/rspec/language.rb +10 -0
  80. data/lib/rubocop/rspec/version.rb +1 -1
  81. metadata +17 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1531e973244c7aac66856335d340dee502696e988f9816bf74e7f5555d80d90
4
- data.tar.gz: b634d15c53e126f497928eca6adfa6fae08b095ccb1a93f3d906826bca56efd4
3
+ metadata.gz: ec6f02aa20957826bdff135547211062ac19bdac9b260d2a008c45973944ff16
4
+ data.tar.gz: 57454e8f60b40062ad5da0ef9e4ce83c8539aea78d13d8412af24f43c01c2e1d
5
5
  SHA512:
6
- metadata.gz: e91e8656f9f82f02fa041d5795d01eba023460aad4e3c06b55167b3f92fc0d22324250e1d116eb63c3b60e915240347f0a36cbe14c8b3752f7c6a63ea9949bd4
7
- data.tar.gz: 8c470782145e23962f3653beb13b4543d461a3de9bbea201d5fb0c66fc8bfebb5695afad7bc545b37dba664362dee8edb0f579441f0bafcd963ab86f503b0415
6
+ metadata.gz: 51333677ad7c458afd2446b21c6e900c5f4ba597d2659cc2e389e5c9e223fe1885e54c8d427a8213519bd9176c0bfbc146910d6cd3c5dea7c9a69450ac34ce97
7
+ data.tar.gz: 5f6cffcb89273ddca1615907f8de6e619697c63c1255b630320b3852a9266aef4d260d295a6ee57ea1c91e862ad584750fac2784a2a536aea37887f829a14bd5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,42 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.6.0 (2021-11-08)
6
+
7
+ * Fix merging RSpec DSL configuration from third-party gems. ([@pirj][])
8
+ * Fix `RSpec/ExcessiveDocstringSpacing` false positive for multi-line indented strings. ([@G-Rath][])
9
+ * Fix `Include` configuration for sub-departments. ([@pirj][])
10
+ * Ignore heredocs in `RSpec/ExcessiveDocstringSpacing`. ([@G-Rath][])
11
+ * Stop `RSpec/ExampleWording` from trying to correct heredocs. ([@G-Rath][])
12
+ * Add autocorrect support for `RSpec/VariableDefinition`. ([@r7kamura][])
13
+
14
+ ## 2.5.0 (2021-09-21)
15
+
16
+ * Declare autocorrect as unsafe for `ExpectChange`. ([@francois-ferrandis][])
17
+ * Fix each example for `RSpec/HookArgument`. ([@lokhi][])
18
+ * Exclude unrelated Rails directories from `RSpec/DescribeClass`. ([@MothOnMars][])
19
+ * Add `RSpec/ExcessiveDocstringSpacing` cop. ([@G-Rath][])
20
+ * Add `RSpec/SubjectDeclaration` cop. ([@dswij][])
21
+ * Fix excessive whitespace removal in `RSpec/EmptyHook` autocorrection. ([@pirj][])
22
+ * Bump RuboCop requirement to v1.19.0. ([@pirj][])
23
+ * Fix false positive in `RSpec/IteratedExpectation` when there is single, non-expectation statement in the block body. ([@Darhazer][])
24
+
25
+ ## 2.4.0 (2021-06-09)
26
+
27
+ * Update `RSpec/FilePath` to check suffix when given a non-constant top-level node (e.g. features). ([@topalovic][])
28
+ * Add missing documentation for `single_statement_only` style of `RSpec/ImplicitSubject` cop. ([@tejasbubane][])
29
+ * Fix an exception in `DescribedClass` when accessing a constant on a variable in a spec that is nested in a namespace. ([@rrosenblum][])
30
+ * Add new `RSpec/IdenticalEqualityAssertion` cop. ([@tejasbubane][])
31
+ * Add `RSpec/Rails/AvoidSetupHook` cop. ([@paydaylight][])
32
+ * Fix false negative in `RSpec/ExpectChange` cop with block style and chained method call. ([@tejasbubane][])
33
+
34
+ ## 2.3.0 (2021-04-28)
35
+
36
+ * Allow `RSpec/ContextWording` to accept multi-word prefixes. ([@hosamaly][])
37
+ * Drop support for ruby 2.4. ([@bquorning][])
38
+ * Add `CountAsOne` configuration option to `RSpec/ExampleLength`. ([@stephannv][])
39
+ * Fix a false positive for `RSpec/RepeatedExampleGroupBody` when `pending` or `skip` have argument(s). ([@Tietew][])
40
+
5
41
  ## 2.2.0 (2021-02-02)
6
42
 
7
43
  * Fix `HooksBeforeExamples`, `LeadingSubject`, `LetBeforeExamples` and `ScatteredLet` autocorrection to take into account inline comments and comments immediately before the moved node. ([@Darhazer][])
@@ -603,3 +639,15 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
603
639
  [@sl4vr]: https://github.com/sl4vr
604
640
  [@ahukkanen]: https://github.com/ahukkanen
605
641
  [@dvandersluis]: https://github.com/dvandersluis
642
+ [@hosamaly]: https://github.com/hosamaly
643
+ [@stephannv]: https://github.com/stephannv
644
+ [@Tietew]: https://github.com/Tietew
645
+ [@rrosenblum]: https://github.com/rrosenblum
646
+ [@paydaylight]: https://github.com/paydaylight
647
+ [@topalovic]: https://github.com/topalovic
648
+ [@lokhi]: https://github.com/lokhi
649
+ [@MothOnMars]: https://github.com/MothOnMars
650
+ [@G-Rath]: https://github.com/G-Rath
651
+ [@dswij]: https://github.com/dswij
652
+ [@francois-ferrandis]: https://github.com/francois-ferrandis
653
+ [@r7kamura]: https://github.com/r7kamura
data/README.md CHANGED
@@ -2,12 +2,10 @@
2
2
 
3
3
  [![Join the chat at https://gitter.im/rubocop-rspec/Lobby](https://badges.gitter.im/rubocop-rspec/Lobby.svg)](https://gitter.im/rubocop-rspec/Lobby)
4
4
  [![Gem Version](https://badge.fury.io/rb/rubocop-rspec.svg)](https://rubygems.org/gems/rubocop-rspec)
5
- [![CircleCI](https://circleci.com/gh/rubocop-hq/rubocop-rspec.svg?style=svg)](https://circleci.com/gh/rubocop-hq/rubocop-rspec)
6
- [![Test Coverage](https://api.codeclimate.com/v1/badges/8ffaabf633c968c22bdd/test_coverage)](https://codeclimate.com/github/rubocop-hq/rubocop-rspec/test_coverage)
7
- [![Maintainability](https://api.codeclimate.com/v1/badges/8ffaabf633c968c22bdd/maintainability)](https://codeclimate.com/github/rubocop-hq/rubocop-rspec/maintainability)
5
+ ![CI](https://github.com/rubocop-hq/rubocop-rspec/workflows/CI/badge.svg)
8
6
 
9
7
  RSpec-specific analysis for your projects, as an extension to
10
- [RuboCop](https://github.com/rubocop-hq/rubocop).
8
+ [RuboCop](https://github.com/rubocop/rubocop).
11
9
 
12
10
  ## Installation
13
11
 
@@ -67,7 +65,7 @@ end
67
65
 
68
66
  ### Code Climate
69
67
 
70
- rubocop-rspec is available on Code Climate as part of the rubocop engine. [Learn More](https://codeclimate.com/changelog/55a433bbe30ba00852000fac).
68
+ rubocop-rspec is available on Code Climate as part of the rubocop engine. [Learn More](https://marketing.codeclimate.com/changelog/55a433bbe30ba00852000fac/).
71
69
 
72
70
  ## Documentation
73
71
 
data/config/default.yml CHANGED
@@ -1,11 +1,24 @@
1
1
  ---
2
2
  RSpec:
3
3
  Enabled: true
4
- Include:
4
+ Include: &1
5
5
  - "**/*_spec.rb"
6
6
  - "**/spec/**/*"
7
- Language:
7
+ Language: &2
8
+ inherit_mode:
9
+ merge:
10
+ - Expectations
11
+ - Helpers
12
+ - Hooks
13
+ - HookScopes
14
+ - Runners
15
+ - Subjects
8
16
  ExampleGroups:
17
+ inherit_mode:
18
+ merge:
19
+ - Regular
20
+ - Skipped
21
+ - Focused
9
22
  Regular:
10
23
  - describe
11
24
  - context
@@ -20,6 +33,12 @@ RSpec:
20
33
  - fcontext
21
34
  - ffeature
22
35
  Examples:
36
+ inherit_mode:
37
+ merge:
38
+ - Regular
39
+ - Skipped
40
+ - Focused
41
+ - Pending
23
42
  Regular:
24
43
  - it
25
44
  - specify
@@ -62,6 +81,10 @@ RSpec:
62
81
  - all
63
82
  - suite
64
83
  Includes:
84
+ inherit_mode:
85
+ merge:
86
+ - Examples
87
+ - Context
65
88
  Examples:
66
89
  - it_behaves_like
67
90
  - it_should_behave_like
@@ -73,6 +96,10 @@ RSpec:
73
96
  - to_not
74
97
  - not_to
75
98
  SharedGroups:
99
+ inherit_mode:
100
+ merge:
101
+ - Examples
102
+ - Context
76
103
  Examples:
77
104
  - shared_examples
78
105
  - shared_examples_for
@@ -148,6 +175,12 @@ RSpec/ContextWording:
148
175
  RSpec/DescribeClass:
149
176
  Description: Check that the first argument to the top-level describe is a constant.
150
177
  Enabled: true
178
+ Exclude:
179
+ - "**/spec/features/**/*"
180
+ - "**/spec/requests/**/*"
181
+ - "**/spec/routing/**/*"
182
+ - "**/spec/system/**/*"
183
+ - "**/spec/views/**/*"
151
184
  IgnoredMetadata:
152
185
  type:
153
186
  - channel
@@ -164,7 +197,7 @@ RSpec/DescribeClass:
164
197
  - mailbox
165
198
  - aruba
166
199
  VersionAdded: '1.0'
167
- VersionChanged: '1.44'
200
+ VersionChanged: '2.5'
168
201
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
169
202
 
170
203
  RSpec/DescribeMethod:
@@ -253,7 +286,9 @@ RSpec/ExampleLength:
253
286
  Description: Checks for long examples.
254
287
  Enabled: true
255
288
  Max: 5
289
+ CountAsOne: []
256
290
  VersionAdded: '1.5'
291
+ VersionChanged: '2.3'
257
292
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleLength
258
293
 
259
294
  RSpec/ExampleWithoutDescription:
@@ -267,6 +302,12 @@ RSpec/ExampleWithoutDescription:
267
302
  VersionAdded: '1.22'
268
303
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWithoutDescription
269
304
 
305
+ RSpec/ExcessiveDocstringSpacing:
306
+ Description: Checks for excessive whitespace in example descriptions.
307
+ Enabled: pending
308
+ VersionAdded: '2.5'
309
+ StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExcessiveDocstringSpacing
310
+
270
311
  RSpec/ExampleWording:
271
312
  Description: Checks for common mistakes in example descriptions.
272
313
  Enabled: true
@@ -295,7 +336,9 @@ RSpec/ExpectChange:
295
336
  SupportedStyles:
296
337
  - method_call
297
338
  - block
339
+ SafeAutoCorrect: false
298
340
  VersionAdded: '1.22'
341
+ VersionChanged: '2.5'
299
342
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectChange
300
343
 
301
344
  RSpec/ExpectInHook:
@@ -349,6 +392,12 @@ RSpec/HooksBeforeExamples:
349
392
  VersionAdded: '1.29'
350
393
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HooksBeforeExamples
351
394
 
395
+ RSpec/IdenticalEqualityAssertion:
396
+ Description: Checks for equality assertions with identical expressions on both sides.
397
+ Enabled: pending
398
+ VersionAdded: '2.4'
399
+ StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IdenticalEqualityAssertion
400
+
352
401
  RSpec/ImplicitBlockExpectation:
353
402
  Description: Check that implicit block expectation syntax is not used.
354
403
  Enabled: true
@@ -635,6 +684,12 @@ RSpec/StubbedMock:
635
684
  VersionAdded: '1.44'
636
685
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StubbedMock
637
686
 
687
+ RSpec/SubjectDeclaration:
688
+ Description: Ensure that subject is defined using subject helper.
689
+ Enabled: pending
690
+ VersionAdded: '2.5'
691
+ StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectDeclaration
692
+
638
693
  RSpec/SubjectStub:
639
694
  Description: Checks for stubbed test subjects.
640
695
  Enabled: true
@@ -690,6 +745,11 @@ RSpec/Yield:
690
745
  VersionAdded: '1.32'
691
746
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Yield
692
747
 
748
+ RSpec/Capybara:
749
+ Enabled: true
750
+ Include: *1
751
+ Language: *2
752
+
693
753
  RSpec/Capybara/CurrentPathExpectation:
694
754
  Description: Checks that no expectations are set on Capybara's `current_path`.
695
755
  Enabled: true
@@ -712,6 +772,11 @@ RSpec/Capybara/VisibilityMatcher:
712
772
  VersionChanged: '2.0'
713
773
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/VisibilityMatcher
714
774
 
775
+ RSpec/FactoryBot:
776
+ Enabled: true
777
+ Include: *1
778
+ Language: *2
779
+
715
780
  RSpec/FactoryBot/AttributeDefinedStatically:
716
781
  Description: Always declare attribute values as blocks.
717
782
  Enabled: true
@@ -751,6 +816,17 @@ RSpec/FactoryBot/FactoryClassName:
751
816
  VersionChanged: '2.0'
752
817
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName
753
818
 
819
+ RSpec/Rails:
820
+ Enabled: true
821
+ Include: *1
822
+ Language: *2
823
+
824
+ RSpec/Rails/AvoidSetupHook:
825
+ Description: Checks that tests use RSpec `before` hook over Rails `setup` method.
826
+ Enabled: pending
827
+ VersionAdded: '2.4'
828
+ StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/AvoidSetupHook
829
+
754
830
  RSpec/Rails/HttpStatus:
755
831
  Description: Enforces use of symbolic or numeric value to describe HTTP status.
756
832
  Enabled: true
@@ -30,10 +30,12 @@ module RuboCop
30
30
  MSG_UNUSED_ARG = 'You should call `%<arg>s.call` ' \
31
31
  'or `%<arg>s.run`.'
32
32
 
33
+ # @!method hook(node)
33
34
  def_node_matcher :hook, <<-PATTERN
34
35
  (block (send nil? :around sym ?) (args $...) ...)
35
36
  PATTERN
36
37
 
38
+ # @!method find_arg_usage(node)
37
39
  def_node_search :find_arg_usage, <<-PATTERN
38
40
  {(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
39
41
  PATTERN
@@ -22,6 +22,7 @@ module RuboCop
22
22
  class Be < Base
23
23
  MSG = "Don't use `be` without an argument."
24
24
 
25
+ # @!method be_without_args(node)
25
26
  def_node_matcher :be_without_args, <<-PATTERN
26
27
  (send _ #Runners.all $(send nil? :be))
27
28
  PATTERN
@@ -41,6 +41,7 @@ module RuboCop
41
41
  MSG = 'Prefer `be` over `eql`.'
42
42
  RESTRICT_ON_SEND = %i[to].freeze
43
43
 
44
+ # @!method eql_type_with_identity(node)
44
45
  def_node_matcher :eql_type_with_identity, <<-PATTERN
45
46
  (send _ :to $(send nil? :eql {true false int float sym nil_type?}))
46
47
  PATTERN
@@ -31,6 +31,7 @@ module RuboCop
31
31
 
32
32
  RESTRICT_ON_SEND = %i[before after].freeze
33
33
 
34
+ # @!method before_or_after_all(node)
34
35
  def_node_matcher :before_or_after_all, <<-PATTERN
35
36
  $(send _ {:before :after} (sym {:all :context}))
36
37
  PATTERN
@@ -32,17 +32,20 @@ module RuboCop
32
32
 
33
33
  RESTRICT_ON_SEND = %i[expect].freeze
34
34
 
35
+ # @!method expectation_set_on_current_path(node)
35
36
  def_node_matcher :expectation_set_on_current_path, <<-PATTERN
36
37
  (send nil? :expect (send {(send nil? :page) nil?} :current_path))
37
38
  PATTERN
38
39
 
39
40
  # Supported matchers: eq(...) / match(/regexp/) / match('regexp')
41
+ # @!method as_is_matcher(node)
40
42
  def_node_matcher :as_is_matcher, <<-PATTERN
41
43
  (send
42
44
  #expectation_set_on_current_path $#Runners.all
43
45
  ${(send nil? :eq ...) (send nil? :match (regexp ...))})
44
46
  PATTERN
45
47
 
48
+ # @!method regexp_str_matcher(node)
46
49
  def_node_matcher :regexp_str_matcher, <<-PATTERN
47
50
  (send
48
51
  #expectation_set_on_current_path $#Runners.all
@@ -55,16 +55,19 @@ module RuboCop
55
55
  feature: :describe
56
56
  }.freeze
57
57
 
58
+ # @!method capybara_speak(node)
58
59
  def_node_matcher :capybara_speak, <<-PATTERN
59
60
  {#{MAP.keys.map(&:inspect).join(' ')}}
60
61
  PATTERN
61
62
 
63
+ # @!method spec?(node)
62
64
  def_node_matcher :spec?, <<-PATTERN
63
65
  (block
64
66
  (send #rspec? {:describe :feature} ...)
65
67
  ...)
66
68
  PATTERN
67
69
 
70
+ # @!method feature_method(node)
68
71
  def_node_matcher :feature_method, <<-PATTERN
69
72
  (block
70
73
  $(send #rspec? $#capybara_speak ...)
@@ -46,10 +46,12 @@ module RuboCop
46
46
 
47
47
  RESTRICT_ON_SEND = CAPYBARA_MATCHER_METHODS
48
48
 
49
+ # @!method visible_true?(node)
49
50
  def_node_matcher :visible_true?, <<~PATTERN
50
51
  (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) true) ...>))
51
52
  PATTERN
52
53
 
54
+ # @!method visible_false?(node)
53
55
  def_node_matcher :visible_false?, <<~PATTERN
54
56
  (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) false) ...>))
55
57
  PATTERN
@@ -28,6 +28,7 @@ module RuboCop
28
28
 
29
29
  MSG = 'Use `describe` for testing methods.'
30
30
 
31
+ # @!method context_method(node)
31
32
  def_node_matcher :context_method, <<-PATTERN
32
33
  (block (send #rspec? :context $(str #method_name?) ...) ...)
33
34
  PATTERN
@@ -8,6 +8,7 @@ module RuboCop
8
8
  # The default list of prefixes is minimal. Users are encouraged to tailor
9
9
  # the configuration to meet project needs. Other acceptable prefixes may
10
10
  # include `if`, `unless`, `for`, `before`, `after`, or `during`.
11
+ # They may consist of multiple words if desired.
11
12
  #
12
13
  # @see https://rspec.rubystyle.guide/#context-descriptions
13
14
  # @see http://www.betterspecs.org/#contexts
@@ -37,6 +38,7 @@ module RuboCop
37
38
  class ContextWording < Base
38
39
  MSG = 'Start context description with %<prefixes>s.'
39
40
 
41
+ # @!method context_wording(node)
40
42
  def_node_matcher :context_wording, <<-PATTERN
41
43
  (block (send #rspec? { :context :shared_context } $(str #bad_prefix?) ...) ...)
42
44
  PATTERN
@@ -51,7 +53,7 @@ module RuboCop
51
53
  private
52
54
 
53
55
  def bad_prefix?(description)
54
- !prefixes.include?(description.split(/\b/).first)
56
+ !prefix_regex.match?(description)
55
57
  end
56
58
 
57
59
  def joined_prefixes
@@ -65,6 +67,10 @@ module RuboCop
65
67
  def prefixes
66
68
  cop_config['Prefixes'] || []
67
69
  end
70
+
71
+ def prefix_regex
72
+ /^#{Regexp.union(prefixes)}\b/
73
+ end
68
74
  end
69
75
  end
70
76
  end
@@ -40,14 +40,17 @@ module RuboCop
40
40
  MSG = 'The first argument to describe should be ' \
41
41
  'the class or module being tested.'
42
42
 
43
+ # @!method example_group_with_ignored_metadata?(node)
43
44
  def_node_matcher :example_group_with_ignored_metadata?, <<~PATTERN
44
45
  (send #rspec? :describe ... (hash <#ignored_metadata? ...>))
45
46
  PATTERN
46
47
 
48
+ # @!method not_a_const_described(node)
47
49
  def_node_matcher :not_a_const_described, <<~PATTERN
48
50
  (send #rspec? :describe $[!const !#string_constant?] ...)
49
51
  PATTERN
50
52
 
53
+ # @!method sym_pair(node)
51
54
  def_node_matcher :sym_pair, <<~PATTERN
52
55
  (pair $sym $sym)
53
56
  PATTERN
@@ -22,6 +22,7 @@ module RuboCop
22
22
  MSG = 'The second argument to describe should be the method ' \
23
23
  "being tested. '#instance' or '.class'."
24
24
 
25
+ # @!method second_argument(node)
25
26
  def_node_matcher :second_argument, <<~PATTERN
26
27
  (block
27
28
  (send #rspec? :describe _first_argument $(str _) ...) ...
@@ -21,6 +21,7 @@ module RuboCop
21
21
  MSG = 'Avoid describing symbols.'
22
22
  RESTRICT_ON_SEND = %i[describe].freeze
23
23
 
24
+ # @!method describe_symbol?(node)
24
25
  def_node_matcher :describe_symbol?, <<-PATTERN
25
26
  (send #rspec? :describe $sym ...)
26
27
  PATTERN
@@ -61,18 +61,23 @@ module RuboCop
61
61
  DESCRIBED_CLASS = 'described_class'
62
62
  MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
63
63
 
64
+ # @!method common_instance_exec_closure?(node)
64
65
  def_node_matcher :common_instance_exec_closure?, <<-PATTERN
65
66
  (block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
66
67
  PATTERN
67
68
 
69
+ # @!method rspec_block?(node)
68
70
  def_node_matcher :rspec_block?, block_pattern('#ALL.all')
69
71
 
72
+ # @!method scope_changing_syntax?(node)
70
73
  def_node_matcher :scope_changing_syntax?, '{def class module}'
71
74
 
75
+ # @!method described_constant(node)
72
76
  def_node_matcher :described_constant, <<-PATTERN
73
77
  (block (send _ :describe $(const ...) ...) (args) $_)
74
78
  PATTERN
75
79
 
80
+ # @!method contains_described_class?(node)
76
81
  def_node_search :contains_described_class?, <<-PATTERN
77
82
  (send nil? :described_class)
78
83
  PATTERN
@@ -198,7 +203,7 @@ module RuboCop
198
203
  [name]
199
204
  elsif namespace.const_type?
200
205
  [*const_name(namespace), name]
201
- elsif namespace.lvar_type? || namespace.cbase_type?
206
+ elsif %i[lvar cbase send].include?(namespace.type)
202
207
  [nil, name]
203
208
  end
204
209
  end
@@ -18,10 +18,11 @@ module RuboCop
18
18
  # # ...
19
19
  # end
20
20
  #
21
- # @see https://github.com/rubocop-hq/rubocop-rspec/issues/735
21
+ # @see https://github.com/rubocop/rubocop-rspec/issues/735
22
22
  class DescribedClassModuleWrapping < Base
23
23
  MSG = 'Avoid opening modules and defining specs within them.'
24
24
 
25
+ # @!method find_rspec_blocks(node)
25
26
  def_node_search :find_rspec_blocks, block_pattern('#ExampleGroups.all')
26
27
 
27
28
  def on_module(node)
@@ -47,6 +47,7 @@ module RuboCop
47
47
 
48
48
  MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
49
49
 
50
+ # @!method rspec_method?(node)
50
51
  def_node_matcher :rspec_method?, send_pattern('#ALL.all')
51
52
 
52
53
  def on_send(node)
@@ -28,6 +28,7 @@ module RuboCop
28
28
 
29
29
  MSG = 'Empty hook detected.'
30
30
 
31
+ # @!method empty_hook?(node)
31
32
  def_node_matcher :empty_hook?, <<~PATTERN
32
33
  (block $#{send_pattern('#Hooks.all')} _ nil?)
33
34
  PATTERN
@@ -35,7 +36,10 @@ module RuboCop
35
36
  def on_block(node)
36
37
  empty_hook?(node) do |hook|
37
38
  add_offense(hook) do |corrector|
38
- range = range_with_surrounding_space(range: node.loc.expression)
39
+ range = range_with_surrounding_space(
40
+ range: node.loc.expression,
41
+ side: :left
42
+ )
39
43
  corrector.remove(range)
40
44
  end
41
45
  end
@@ -25,29 +25,43 @@ module RuboCop
25
25
  # result = service.call
26
26
  # expect(result).to be(true)
27
27
  # end
28
+ #
29
+ # You can set literals you want to fold with `CountAsOne`.
30
+ # Available are: 'array', 'hash', and 'heredoc'. Each literal
31
+ # will be counted as one line regardless of its actual size.
32
+ #
33
+ # @example CountAsOne: ['array', 'heredoc']
34
+ #
35
+ # it do
36
+ # array = [ # +1
37
+ # 1,
38
+ # 2
39
+ # ]
40
+ #
41
+ # hash = { # +3
42
+ # key: 'value'
43
+ # }
44
+ #
45
+ # msg = <<~HEREDOC # +1
46
+ # Heredoc
47
+ # content.
48
+ # HEREDOC
49
+ # end # 5 points
28
50
  class ExampleLength < Base
29
51
  include CodeLength
30
52
 
31
- MSG = 'Example has too many lines [%<total>d/%<max>d].'
53
+ LABEL = 'Example'
32
54
 
33
55
  def on_block(node)
34
56
  return unless example?(node)
35
57
 
36
- length = code_length(node)
37
-
38
- return unless length > max_length
39
-
40
- add_offense(node, message: message(length))
58
+ check_code_length(node)
41
59
  end
42
60
 
43
61
  private
44
62
 
45
- def code_length(node)
46
- node.source.lines[1..-2].count { |line| !irrelevant_line(line) }
47
- end
48
-
49
- def message(length)
50
- format(MSG, total: length, max: max_length)
63
+ def cop_label
64
+ LABEL
51
65
  end
52
66
  end
53
67
  end
@@ -54,6 +54,7 @@ module RuboCop
54
54
  'have auto-generated description.'
55
55
  MSG_ADD_DESCRIPTION = 'Add a description.'
56
56
 
57
+ # @!method example_description(node)
57
58
  def_node_matcher :example_description, '(send nil? _ $(str $_))'
58
59
 
59
60
  def on_block(node)
@@ -38,6 +38,7 @@ module RuboCop
38
38
  SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
39
39
  IT_PREFIX = /\Ait /i.freeze
40
40
 
41
+ # @!method it_description(node)
41
42
  def_node_matcher :it_description, <<-PATTERN
42
43
  (block (send _ :it ${
43
44
  (str $_)
@@ -59,7 +60,10 @@ module RuboCop
59
60
 
60
61
  def add_wording_offense(node, message)
61
62
  docstring = docstring(node)
63
+
62
64
  add_offense(docstring, message: message) do |corrector|
65
+ next if node.heredoc?
66
+
63
67
  corrector.replace(docstring, replacement_text(node))
64
68
  end
65
69
  end