rubocop-rspec 2.22.0 → 2.25.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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +59 -9
  3. data/README.md +1 -1
  4. data/config/default.yml +87 -17
  5. data/lib/rubocop/cop/rspec/duplicated_metadata.rb +1 -1
  6. data/lib/rubocop/cop/rspec/empty_example_group.rb +3 -0
  7. data/lib/rubocop/cop/rspec/empty_metadata.rb +46 -0
  8. data/lib/rubocop/cop/rspec/eq.rb +47 -0
  9. data/lib/rubocop/cop/rspec/example_length.rb +11 -5
  10. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +13 -4
  11. data/lib/rubocop/cop/rspec/expect_actual.rb +2 -2
  12. data/lib/rubocop/cop/rspec/file_path.rb +6 -0
  13. data/lib/rubocop/cop/rspec/focus.rb +15 -0
  14. data/lib/rubocop/cop/rspec/indexed_let.rb +32 -1
  15. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
  16. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
  17. data/lib/rubocop/cop/rspec/let_before_examples.rb +4 -0
  18. data/lib/rubocop/cop/rspec/metadata_style.rb +202 -0
  19. data/lib/rubocop/cop/rspec/mixin/file_help.rb +14 -0
  20. data/lib/rubocop/cop/rspec/mixin/metadata.rb +21 -7
  21. data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
  22. data/lib/rubocop/cop/rspec/pending.rb +12 -2
  23. data/lib/rubocop/cop/rspec/predicate_matcher.rb +3 -3
  24. data/lib/rubocop/cop/rspec/rails/http_status.rb +28 -17
  25. data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +102 -0
  26. data/lib/rubocop/cop/rspec/receive_messages.rb +161 -0
  27. data/lib/rubocop/cop/rspec/sort_metadata.rb +2 -1
  28. data/lib/rubocop/cop/rspec/spec_file_path_format.rb +133 -0
  29. data/lib/rubocop/cop/rspec/spec_file_path_suffix.rb +40 -0
  30. data/lib/rubocop/cop/rspec/variable_definition.rb +2 -2
  31. data/lib/rubocop/cop/rspec/verified_double_reference.rb +6 -6
  32. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -1
  33. data/lib/rubocop/cop/rspec/void_expect.rb +2 -1
  34. data/lib/rubocop/cop/rspec_cops.rb +7 -0
  35. data/lib/rubocop/rspec/version.rb +1 -1
  36. data/lib/rubocop-rspec.rb +1 -0
  37. metadata +13 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e786386e218833ac7f78af9ffcadadb6bf6c822a31b455cac1567152fd3bc9c0
4
- data.tar.gz: 384170b4ae3a06c05b30855ae9361057c53226b40b924d4ec1d49c0d15195658
3
+ metadata.gz: afb5cf0c88af50530fc023549eb7e9083db3ca2314553f1fca912ea2a3c47bdb
4
+ data.tar.gz: ba30f926d9cd3056e786f724140ac4358af527496b2e783fcc5c8e541adc9d13
5
5
  SHA512:
6
- metadata.gz: 554345811f404b27a39fd522e0085022c39147e0487f04ea77ed7887002451af112e2ddc45ad94841c0a4201a76f37fbfb7a2e64aed3c7efa91cddf1a30843bc
7
- data.tar.gz: 22882a56ddf03c55d6eaf299fb05197c835049054231e6d7798e2ca3eac5cbd9840eeada823a12431b00efd37289a8353792dfe3c8f653b2606f9ccda480615a
6
+ metadata.gz: cd7955549b3b95b481eb5dea24b98f72e1b802546f8e090695a782a20b0ee8d1d0bcca9a6089f3a46718c5a14967de6c8473709ecea72d8aa5eae85e2cb5bd6f
7
+ data.tar.gz: 2beb193cf65884c363c2ece1a3a7ba5db39eecc3a579724bd39f29696ab29276def06261363b6a6290d378743e0b79d414e056b65f0a8a9e2e4215a417d9b978
data/CHANGELOG.md CHANGED
@@ -2,6 +2,50 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.25.0 (2023-10-27)
6
+
7
+ - Add support single quoted string and percent string and heredoc for `RSpec/Rails/HttpStatus`. ([@ydah])
8
+ - Change to be inline disable for `RSpec/SpecFilePathFormat` like `RSpec/FilePath`. ([@ydah])
9
+ - Fix a false positive for `RSpec/MetadataStyle` with example groups having multiple string arguments. ([@franzliedke])
10
+
11
+ ## 2.24.1 (2023-09-23)
12
+
13
+ - Fix an error when using `RSpec/FilePath` and revert to enabled by default. If you have already moved to `RSpec/SpecFilePathSuffix` and `RSpec/SpecFilePathFormat`, disable `RSpec/FilePath` explicitly as `Enabled: false`. The `RSpec/FilePath` before migration and the `RSpec/SpecFilePathSuffix` and `RSpec/SpecFilePathFormat` as the target are available respectively. ([@ydah])
14
+
15
+ ## 2.24.0 (2023-09-08)
16
+
17
+ - Split `RSpec/FilePath` into `RSpec/SpecFilePathSuffix` and `RSpec/SpecFilePathFormat`. `RSpec/FilePath` cop is disabled by default and the two new cops are pending and need to be enabled explicitly. ([@ydah])
18
+ - Add new `RSpec/Eq` cop. ([@ydah])
19
+ - Add `RSpec/MetadataStyle` and `RSpec/EmptyMetadata` cops. ([@r7kamura])
20
+ - Add support `RSpec/Rails/HttpStatus` when `have_http_status` with string argument. ([@ydah])
21
+ - Fix an infinite loop error when `RSpec/ExcessiveDocstringSpacing` finds a description with non-ASCII leading/trailing whitespace. ([@bcgraham])
22
+ - Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when return values declared between stubs. ([@marocchino])
23
+ - Fix a false positive `RSpec/Focus` when chained method call and inside define method. ([@ydah])
24
+
25
+ ## 2.23.2 (2023-08-09)
26
+
27
+ - Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when method is only non-word character. ([@marocchino])
28
+ - Fix a false positive for `RSpec/ReceiveMessages` when return with splat. ([@marocchino])
29
+
30
+ ## 2.23.1 (2023-08-07)
31
+
32
+ - Mark to `Safe: false` for `RSpec/Rails/NegationBeValid` cop. ([@ydah])
33
+ - Declare autocorrect as unsafe for `RSpec/ReceiveMessages`. ([@bquorning])
34
+
35
+ ## 2.23.0 (2023-07-30)
36
+
37
+ - Add new `RSpec/Rails/NegationBeValid` cop. ([@ydah])
38
+ - Fix a false negative for `RSpec/ExcessiveDocstringSpacing` when finds description with em space. ([@ydah])
39
+ - Fix a false positive for `RSpec/EmptyExampleGroup` when example group with examples defined in `if` branch inside iterator. ([@ydah])
40
+ - Update the message output of `RSpec/ExpectActual` to include the word 'value'. ([@corydiamand])
41
+ - Fix a false negative for `RSpec/Pending` when `it` without body. ([@ydah])
42
+ - Add new `RSpec/ReceiveMessages` cop. ([@ydah])
43
+ - Change default.yml path to use `**/spec/*` instead of `spec/*`. ([@ydah])
44
+ - Add `AllowedIdentifiers` and `AllowedPatterns` configuration option to `RSpec/IndexedLet`. ([@ydah])
45
+ - Fix `RSpec/NamedSubject` when block has no body. ([@splattael])
46
+ - Fix `RSpec/LetBeforeExamples` autocorrect incompatible with `RSpec/ScatteredLet` autocorrect. ([@ydah])
47
+ - Update `RSpec/Focus` to support `shared_context` and `shared_examples`. ([@tmaier])
48
+
5
49
  ## 2.22.0 (2023-05-06)
6
50
 
7
51
  - Extract factory_bot cops to a separate repository, [`rubocop-factory_bot`](https://github.com/rubocop/rubocop-factory_bot). The `rubocop-factory_bot` repository is a dependency of `rubocop-rspec` and the factory_bot cops are aliased (`RSpec/FactoryBot/Foo` == `FactoryBot/Foo`) until v3.0 is released, so the change will be invisible to users until then. ([@ydah])
@@ -22,9 +66,9 @@
22
66
  - Add support `be_status` style for `RSpec/Rails/HttpStatus`. ([@ydah])
23
67
  - Add support for shared example groups to `RSpec/EmptyLineAfterExampleGroup`. ([@pirj])
24
68
  - Add support for `RSpec/HaveHttpStatus` when using `response.code`. ([@ydah])
25
- - Fix order of expected and actual in correction for `RSpec/Rails/MinitestAssertions` ([@mvz])
69
+ - Fix order of expected and actual in correction for `RSpec/Rails/MinitestAssertions`. ([@mvz])
26
70
  - Fix a false positive for `RSpec/DescribedClassModuleWrapping` when RSpec.describe numblock is nested within a module. ([@ydah])
27
- - Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` inside `&&`, `||` and `:?` when `omit_parentheses` is on ([@dmitrytsepelev])
71
+ - Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` inside `&&`, `||` and `:?` when `omit_parentheses` is on. ([@dmitrytsepelev])
28
72
  - Fix a false positive for `RSpec/PendingWithoutReason` when pending/skip has a reason inside an example group. ([@ydah])
29
73
  - Fix a false negative for `RSpec/RedundantAround` when redundant numblock `around`. ([@ydah])
30
74
  - Change `RSpec/ContainExactly` to ignore calls with no arguments, and change `RSpec/MatchArray` to ignore calls with an empty array literal argument. ([@ydah], [@bquorning])
@@ -77,7 +121,7 @@
77
121
  - Improved processing speed for `RSpec/Be`, `RSpec/ExpectActual`, `RSpec/ImplicitExpect`, `RSpec/MessageSpies`, `RSpec/PredicateMatcher` and `RSpec/Rails/HaveHttpStatus`. ([@ydah])
78
122
  - Fix wrong autocorrection in `n_times` style on `RSpec/FactoryBot/CreateList`. ([@r7kamura])
79
123
  - Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` when using `generate` with multiple arguments. ([@ydah])
80
- - Mark `RSpec/BeEq` as `Safe: false` ([@r7kamura])
124
+ - Mark `RSpec/BeEq` as `Safe: false`. ([@r7kamura])
81
125
  - Add `RSpec/DuplicatedMetadata` cop. ([@r7kamura])
82
126
  - Mark `RSpec/BeEql` as `Safe: false`. ([@r7kamura])
83
127
  - Add `RSpec/PendingWithoutReason` cop. ([@r7kamura])
@@ -110,8 +154,8 @@
110
154
  - Fix a false positive for `RSpec/Capybara/SpecificMatcher` when `have_css("a")` without attribute. ([@ydah])
111
155
  - Update `RSpec/ExampleWording` cop to raise error for insufficient descriptions. ([@akrox58])
112
156
  - Add new `RSpec/Capybara/NegationMatcher` cop. ([@ydah])
113
- - Add `AllowedPatterns` configuration option to `RSpec/NoExpectationExample`. ([@ydah])
114
- - Improve `RSpec/NoExpectationExample` cop to ignore examples skipped or pending via metadata. ([@pirj])
157
+ - Add `AllowedPatterns` configuration option to `RSpec/NoExpectationExample`. ([@ydah])
158
+ - Improve `RSpec/NoExpectationExample` cop to ignore examples skipped or pending via metadata. ([@pirj])
115
159
  - Add `RSpec/FactoryBot/ConsistentParenthesesStyle` cop. ([@Liberatys])
116
160
  - Add `RSpec/Rails/InferredSpecType` cop. ([@r7kamura])
117
161
  - Add new `RSpec/Capybara/SpecificActions` cop. ([@ydah])
@@ -427,7 +471,7 @@
427
471
  - Add config to `RSpec/VerifiedDoubles` to enforcement of verification on unnamed doubles. ([@BrentWheeldon])
428
472
  - Fix `FactoryBot/AttributeDefinedStatically` not working when there is a non-symbol key. ([@vzvu3k6k])
429
473
  - Fix false positive in `RSpec/ImplicitSubject` when `is_expected` is used inside `its()` block. ([@Darhazer])
430
- - Add `single_statement_only` style to `RSpec/ImplicitSubject` as a more relaxed alternative to `single_line_only`. ([@Darhazer])
474
+ - Add `single_statement_only` style to `RSpec/ImplicitSubject` as a more relaxed alternative to `single_line_only`. ([@Darhazer])
431
475
  - Add `RSpec/UnspecifiedException` as a default cop to encourage more-specific `expect{}.to raise_error(ExceptionType)`, or `raise_exception` style handling of exceptions. ([@daveworth])
432
476
 
433
477
  ## 1.29.1 (2018-09-01)
@@ -462,14 +506,14 @@
462
506
 
463
507
  ## 1.26.0 (2018-06-06)
464
508
 
465
- - Fix false positive in `RSpec/EmptyExampleGroup` cop when methods named like a RSpec method are used. ([@Darhazer])
509
+ - Fix false positive in `RSpec/EmptyExampleGroup` cop when methods named like a RSpec method are used. ([@Darhazer])
466
510
  - Fix `Capybara/FeatureMethods` not working when there is require before the spec. ([@Darhazer])
467
511
  - Fix `RSpec/EmptyLineAfterFinalLet`: allow a comment to be placed after latest let, requiring empty line after the comment. ([@Darhazer])
468
512
  - Add `RSpec/ReceiveCounts` cop to enforce usage of :once and :twice matchers. ([@Darhazer])
469
513
 
470
514
  ## 1.25.1 (2018-04-10)
471
515
 
472
- - Fix false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer])
516
+ - Fix false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer])
473
517
  - Fix `FactoryBot/DynamicAttributeDefinedStatically` false positive when using symbol proc argument for a sequence. ([@tdeo])
474
518
 
475
519
  ## 1.25.0 (2018-04-07)
@@ -477,7 +521,7 @@
477
521
  - Add `RSpec/SharedExamples` cop to enforce consistent usage of string to titleize shared examples. ([@anthony-robin])
478
522
  - Add `RSpec/Be` cop to enforce passing argument to the generic `be` matcher. ([@Darhazer])
479
523
  - Fix false positives in `StaticAttributeDefinedDynamically` and `ReturnFromStub` when a const is used in an array or hash. ([@Darhazer])
480
- - Add `RSpec/Pending` cop to enforce no existing pending or skipped examples. This is disabled by default. ([@patrickomatic])
524
+ - Add `RSpec/Pending` cop to enforce no existing pending or skipped examples. This is disabled by default. ([@patrickomatic])
481
525
  - Fix `RSpec/NestedGroups` cop support --auto-gen-config. ([@walf443])
482
526
  - Fix false positives in `Capybara/FeatureMethods` when feature methods are used as property names in a factory. ([@Darhazer])
483
527
  - Allow configuring enabled methods in `Capybara/FeatureMethods`. ([@Darhazer])
@@ -773,6 +817,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
773
817
  [@aried3r]: https://github.com/aried3r
774
818
  [@baberthal]: https://github.com/baberthal
775
819
  [@backus]: https://github.com/backus
820
+ [@bcgraham]: https://github.com/bcgraham
776
821
  [@biinari]: https://github.com/biinari
777
822
  [@bmorrall]: https://github.com/bmorrall
778
823
  [@bquorning]: https://github.com/bquorning
@@ -781,6 +826,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
781
826
  [@cfabianski]: https://github.com/cfabianski
782
827
  [@clupprich]: https://github.com/clupprich
783
828
  [@composerinteralia]: https://github.com/composerinteralia
829
+ [@corydiamand]: https://github.com/corydiamand
784
830
  [@darhazer]: https://github.com/Darhazer
785
831
  [@daveworth]: https://github.com/daveworth
786
832
  [@dduugg]: https://github.com/dduugg
@@ -799,6 +845,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
799
845
  [@faucct]: https://github.com/faucct
800
846
  [@foton]: https://github.com/foton
801
847
  [@francois-ferrandis]: https://github.com/francois-ferrandis
848
+ [@franzliedke]: https://github.com/franzliedke
802
849
  [@g-rath]: https://github.com/G-Rath
803
850
  [@geniou]: https://github.com/geniou
804
851
  [@gsamokovarov]: https://github.com/gsamokovarov
@@ -823,6 +870,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
823
870
  [@lokhi]: https://github.com/lokhi
824
871
  [@luke-hill]: https://github.com/luke-hill
825
872
  [@m-yamashita01]: https://github.com/M-Yamashita01
873
+ [@marocchino]: https://github.com/marocchino
826
874
  [@miguelfteixeira]: https://github.com/miguelfteixeira
827
875
  [@mkenyon]: https://github.com/mkenyon
828
876
  [@mkrawc]: https://github.com/mkrawc
@@ -859,6 +907,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
859
907
  [@seanpdoyle]: https://github.com/seanpdoyle
860
908
  [@sl4vr]: https://github.com/sl4vr
861
909
  [@smcgivern]: https://github.com/smcgivern
910
+ [@splattael]: https://github.com/splattael
862
911
  [@stephannv]: https://github.com/stephannv
863
912
  [@t3h2mas]: https://github.com/t3h2mas
864
913
  [@tdeo]: https://github.com/tdeo
@@ -866,6 +915,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
866
915
  [@telmofcosta]: https://github.com/telmofcosta
867
916
  [@tietew]: https://github.com/Tietew
868
917
  [@timrogers]: https://github.com/timrogers
918
+ [@tmaier]: https://github.com/tmaier
869
919
  [@topalovic]: https://github.com/topalovic
870
920
  [@twalpole]: https://github.com/twalpole
871
921
  [@vzvu3k6k]: https://github.com/vzvu3k6k
data/README.md CHANGED
@@ -17,7 +17,7 @@ gem install rubocop-rspec
17
17
 
18
18
  or if you use bundler put this in your `Gemfile`
19
19
 
20
- ```
20
+ ```ruby
21
21
  gem 'rubocop-rspec', require: false
22
22
  ```
23
23
 
data/config/default.yml CHANGED
@@ -181,10 +181,11 @@ RSpec/BeforeAfterAll:
181
181
  Description: Check that before/after(:all) isn't being used.
182
182
  Enabled: true
183
183
  Exclude:
184
- - spec/spec_helper.rb
185
- - spec/rails_helper.rb
186
- - spec/support/**/*.rb
184
+ - "**/spec/spec_helper.rb"
185
+ - "**/spec/rails_helper.rb"
186
+ - "**/spec/support/**/*.rb"
187
187
  VersionAdded: '1.12'
188
+ VersionChanged: '2.23'
188
189
  StyleGuide: https://rspec.rubystyle.guide/#avoid-hooks-with-context-scope
189
190
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
190
191
 
@@ -358,6 +359,18 @@ RSpec/EmptyLineAfterSubject:
358
359
  StyleGuide: https://rspec.rubystyle.guide/#empty-line-after-let
359
360
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterSubject
360
361
 
362
+ RSpec/EmptyMetadata:
363
+ Description: Avoid empty metadata hash.
364
+ Enabled: pending
365
+ VersionAdded: '2.24'
366
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyMetadata
367
+
368
+ RSpec/Eq:
369
+ Description: Use `eq` instead of `be ==` to compare objects.
370
+ Enabled: pending
371
+ VersionAdded: '2.24'
372
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Eq
373
+
361
374
  RSpec/ExampleLength:
362
375
  Description: Checks for long examples.
363
376
  Enabled: true
@@ -404,8 +417,9 @@ RSpec/ExpectActual:
404
417
  Description: Checks for `expect(...)` calls containing literal values.
405
418
  Enabled: true
406
419
  Exclude:
407
- - spec/routing/**/*
420
+ - "**/spec/routing/**/*"
408
421
  VersionAdded: '1.7'
422
+ VersionChanged: '2.23'
409
423
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectActual
410
424
 
411
425
  RSpec/ExpectChange:
@@ -444,7 +458,7 @@ RSpec/FilePath:
444
458
  IgnoreMethods: false
445
459
  SpecSuffixOnly: false
446
460
  VersionAdded: '1.2'
447
- VersionChanged: '1.40'
461
+ VersionChanged: '2.24'
448
462
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FilePath
449
463
 
450
464
  RSpec/Focus:
@@ -513,8 +527,11 @@ RSpec/IndexedLet:
513
527
  Description: Do not set up test data using indexes (e.g., `item_1`, `item_2`).
514
528
  Enabled: pending
515
529
  VersionAdded: '2.20'
530
+ VersionChanged: '2.23'
516
531
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IndexedLet
517
532
  Max: 1
533
+ AllowedIdentifiers: []
534
+ AllowedPatterns: []
518
535
 
519
536
  RSpec/InstanceSpy:
520
537
  Description: Checks for `instance_double` used with `have_received`.
@@ -608,6 +625,16 @@ RSpec/MessageSpies:
608
625
  VersionAdded: '1.9'
609
626
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageSpies
610
627
 
628
+ RSpec/MetadataStyle:
629
+ Description: Use consistent metadata style.
630
+ Enabled: pending
631
+ EnforcedStyle: symbol
632
+ SupportedStyles:
633
+ - hash
634
+ - symbol
635
+ VersionAdded: '2.24'
636
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MetadataStyle
637
+
611
638
  RSpec/MissingExampleGroupArgument:
612
639
  Description: Checks that the first argument to an example group is not empty.
613
640
  Enabled: true
@@ -725,6 +752,13 @@ RSpec/ReceiveCounts:
725
752
  VersionAdded: '1.26'
726
753
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveCounts
727
754
 
755
+ RSpec/ReceiveMessages:
756
+ Description: Checks for multiple messages stubbed on the same object.
757
+ Enabled: pending
758
+ SafeAutoCorrect: false
759
+ VersionAdded: '2.23'
760
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveMessages
761
+
728
762
  RSpec/ReceiveNever:
729
763
  Description: Prefer `not_to receive(...)` over `receive(...).never`.
730
764
  Enabled: true
@@ -822,6 +856,31 @@ RSpec/SortMetadata:
822
856
  VersionAdded: '2.14'
823
857
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SortMetadata
824
858
 
859
+ RSpec/SpecFilePathFormat:
860
+ Description: Checks that spec file paths are consistent and well-formed.
861
+ Enabled: pending
862
+ Include:
863
+ - "**/*_spec.rb"
864
+ Exclude:
865
+ - "**/spec/routing/**/*"
866
+ CustomTransform:
867
+ RuboCop: rubocop
868
+ RSpec: rspec
869
+ IgnoreMethods: false
870
+ IgnoreMetadata:
871
+ type: routing
872
+ VersionAdded: '2.24'
873
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathFormat
874
+
875
+ RSpec/SpecFilePathSuffix:
876
+ Description: Checks that spec file paths suffix are consistent and well-formed.
877
+ Enabled: pending
878
+ VersionAdded: '2.24'
879
+ Include:
880
+ - "**/*_spec*rb*"
881
+ - "**/spec/**/*"
882
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathSuffix
883
+
825
884
  RSpec/StubbedMock:
826
885
  Description: Checks that message expectations do not have a configured response.
827
886
  Enabled: true
@@ -974,11 +1033,11 @@ RSpec/FactoryBot/AttributeDefinedStatically:
974
1033
  Description: Always declare attribute values as blocks.
975
1034
  Enabled: true
976
1035
  Include:
977
- - spec/factories.rb
978
- - spec/factories/**/*.rb
979
- - features/support/factories/**/*.rb
1036
+ - "**/spec/factories.rb"
1037
+ - "**/spec/factories/**/*.rb"
1038
+ - "**/features/support/factories/**/*.rb"
980
1039
  VersionAdded: '1.28'
981
- VersionChanged: '2.0'
1040
+ VersionChanged: '2.23'
982
1041
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/AttributeDefinedStatically
983
1042
 
984
1043
  RSpec/FactoryBot/ConsistentParenthesesStyle:
@@ -997,26 +1056,26 @@ RSpec/FactoryBot/CreateList:
997
1056
  Include:
998
1057
  - "**/*_spec.rb"
999
1058
  - "**/spec/**/*"
1000
- - spec/factories.rb
1001
- - spec/factories/**/*.rb
1002
- - features/support/factories/**/*.rb
1059
+ - "**/spec/factories.rb"
1060
+ - "**/spec/factories/**/*.rb"
1061
+ - "**/features/support/factories/**/*.rb"
1003
1062
  EnforcedStyle: create_list
1004
1063
  SupportedStyles:
1005
1064
  - create_list
1006
1065
  - n_times
1007
1066
  VersionAdded: '1.25'
1008
- VersionChanged: '2.0'
1067
+ VersionChanged: '2.23'
1009
1068
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/CreateList
1010
1069
 
1011
1070
  RSpec/FactoryBot/FactoryClassName:
1012
1071
  Description: Use string value when setting the class attribute explicitly.
1013
1072
  Enabled: true
1014
1073
  Include:
1015
- - spec/factories.rb
1016
- - spec/factories/**/*.rb
1017
- - features/support/factories/**/*.rb
1074
+ - "**/spec/factories.rb"
1075
+ - "**/spec/factories/**/*.rb"
1076
+ - "**/features/support/factories/**/*.rb"
1018
1077
  VersionAdded: '1.37'
1019
- VersionChanged: '2.0'
1078
+ VersionChanged: '2.23'
1020
1079
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName
1021
1080
 
1022
1081
  RSpec/FactoryBot/FactoryNameStyle:
@@ -1095,6 +1154,17 @@ RSpec/Rails/MinitestAssertions:
1095
1154
  VersionAdded: '2.17'
1096
1155
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/MinitestAssertions
1097
1156
 
1157
+ RSpec/Rails/NegationBeValid:
1158
+ Description: Enforces use of `be_invalid` or `not_to` for negated be_valid.
1159
+ Safe: false
1160
+ EnforcedStyle: not_to
1161
+ SupportedStyles:
1162
+ - not_to
1163
+ - be_invalid
1164
+ Enabled: pending
1165
+ VersionAdded: '2.23'
1166
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/NegationBeValid
1167
+
1098
1168
  RSpec/Rails/TravelAround:
1099
1169
  Description: Prefer to travel in `before` rather than `around`.
1100
1170
  Enabled: pending
@@ -19,7 +19,7 @@ module RuboCop
19
19
 
20
20
  MSG = 'Avoid duplicated metadata.'
21
21
 
22
- def on_metadata(symbols, _pairs)
22
+ def on_metadata(symbols, _hash)
23
23
  symbols.each do |symbol|
24
24
  on_metadata_symbol(symbol)
25
25
  end
@@ -131,6 +131,7 @@ module RuboCop
131
131
  {
132
132
  #examples_directly_or_in_block?
133
133
  (begin <#examples_directly_or_in_block? ...>)
134
+ (begin <#examples_in_branches? ...>)
134
135
  }
135
136
  PATTERN
136
137
 
@@ -169,6 +170,8 @@ module RuboCop
169
170
  end
170
171
 
171
172
  def examples_in_branches?(condition_node)
173
+ return if !condition_node.if_type? && !condition_node.case_type?
174
+
172
175
  condition_node.branches.any? { |branch| examples?(branch) }
173
176
  end
174
177
 
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Avoid empty metadata hash.
7
+ #
8
+ # @example EnforcedStyle: symbol (default)
9
+ # # bad
10
+ # describe 'Something', {}
11
+ #
12
+ # # good
13
+ # describe 'Something'
14
+ class EmptyMetadata < Base
15
+ extend AutoCorrector
16
+
17
+ include Metadata
18
+ include RangeHelp
19
+
20
+ MSG = 'Avoid empty metadata hash.'
21
+
22
+ def on_metadata(_symbols, hash)
23
+ return unless hash&.pairs&.empty?
24
+
25
+ add_offense(hash) do |corrector|
26
+ remove_empty_metadata(corrector, hash)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def remove_empty_metadata(corrector, node)
33
+ corrector.remove(
34
+ range_with_surrounding_comma(
35
+ range_with_surrounding_space(
36
+ node.source_range,
37
+ side: :left
38
+ ),
39
+ :left
40
+ )
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Use `eq` instead of `be ==` to compare objects.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # expect(foo).to be == 42
11
+ #
12
+ # # good
13
+ # expect(foo).to eq 42
14
+ #
15
+ class Eq < Base
16
+ extend AutoCorrector
17
+ include RangeHelp
18
+
19
+ MSG = 'Use `eq` instead of `be ==` to compare objects.'
20
+ RESTRICT_ON_SEND = Runners.all
21
+
22
+ # @!method be_equals(node)
23
+ def_node_matcher :be_equals, <<~PATTERN
24
+ (send _ #Runners.all $(send (send nil? :be) :== _))
25
+ PATTERN
26
+
27
+ def on_send(node)
28
+ be_equals(node) do |matcher|
29
+ range = offense_range(matcher)
30
+ add_offense(range) do |corrector|
31
+ corrector.replace(range, 'eq')
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def offense_range(matcher)
39
+ range_between(
40
+ matcher.source_range.begin_pos,
41
+ matcher.loc.selector.end_pos
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -26,11 +26,12 @@ module RuboCop
26
26
  # expect(result).to be(true)
27
27
  # end
28
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.
29
+ # You can set constructs you want to fold with `CountAsOne`.
30
+ # Available are: 'array', 'hash', 'heredoc', and 'method_call'.
31
+ # Each construct will be counted as one line regardless of
32
+ # its actual size.
32
33
  #
33
- # @example CountAsOne: ['array', 'heredoc']
34
+ # @example CountAsOne: ['array', 'heredoc', 'method_call']
34
35
  #
35
36
  # it do
36
37
  # array = [ # +1
@@ -46,7 +47,12 @@ module RuboCop
46
47
  # Heredoc
47
48
  # content.
48
49
  # HEREDOC
49
- # end # 5 points
50
+ #
51
+ # foo( # +1
52
+ # 1,
53
+ # 2
54
+ # )
55
+ # end # 6 points
50
56
  #
51
57
  class ExampleLength < Base
52
58
  include CodeLength
@@ -52,14 +52,23 @@ module RuboCop
52
52
 
53
53
  # @param text [String]
54
54
  def excessive_whitespace?(text)
55
- return true if text.start_with?(' ') || text.end_with?(' ')
56
-
57
- text.match?(/[^\n ] +[^ ]/)
55
+ text.match?(/
56
+ # Leading space
57
+ \A[[:blank:]]
58
+ |
59
+ # Trailing space
60
+ [[:blank:]]\z
61
+ |
62
+ # Two or more consecutive spaces, except if they are leading spaces
63
+ [^[[:space:]]][[:blank:]]{2,}[^[[:blank:]]]
64
+ /x)
58
65
  end
59
66
 
60
67
  # @param text [String]
61
68
  def strip_excessive_whitespace(text)
62
- text.strip.gsub(/ +/, ' ')
69
+ text
70
+ .gsub(/[[:blank:]]{2,}/, ' ')
71
+ .gsub(/\A[[:blank:]]|[[:blank:]]\z/, '')
63
72
  end
64
73
 
65
74
  # @param node [RuboCop::AST::Node]
@@ -24,7 +24,7 @@ module RuboCop
24
24
  class ExpectActual < Base
25
25
  extend AutoCorrector
26
26
 
27
- MSG = 'Provide the actual you are testing to `expect(...)`.'
27
+ MSG = 'Provide the actual value you are testing to `expect(...)`.'
28
28
 
29
29
  RESTRICT_ON_SEND = Runners.all
30
30
 
@@ -77,7 +77,7 @@ module RuboCop
77
77
 
78
78
  private
79
79
 
80
- # This is not implement using a NodePattern because it seems
80
+ # This is not implemented using a NodePattern because it seems
81
81
  # to not be able to match against an explicit (nil) sexp
82
82
  def literal?(node)
83
83
  node && (simple_literal?(node) || complex_literal?(node))
@@ -5,6 +5,12 @@ module RuboCop
5
5
  module RSpec
6
6
  # Checks that spec file paths are consistent and well-formed.
7
7
  #
8
+ # This cop is deprecated.
9
+ # We plan to remove it in the next major version update to 3.0.
10
+ # The migration targets are `RSpec/SpecFilePathSuffix`
11
+ # and `RSpec/SpecFilePathFormat`.
12
+ # If you are using this cop, please plan for migration.
13
+ #
8
14
  # By default, this checks that spec file paths are consistent with the
9
15
  # test subject and enforces that it reflects the described
10
16
  # class/module and its optionally called out method.
@@ -34,6 +34,18 @@ module RuboCop
34
34
  # # good
35
35
  # describe 'test' do; end
36
36
  #
37
+ # # bad
38
+ # shared_examples 'test', focus: true do; end
39
+ #
40
+ # # good
41
+ # shared_examples 'test' do; end
42
+ #
43
+ # # bad
44
+ # shared_context 'test', focus: true do; end
45
+ #
46
+ # # good
47
+ # shared_context 'test' do; end
48
+ #
37
49
  # # bad (does not support autocorrection)
38
50
  # focus 'test' do; end
39
51
  #
@@ -51,6 +63,7 @@ module RuboCop
51
63
  #Examples.regular
52
64
  #Examples.skipped
53
65
  #Examples.pending
66
+ #SharedGroups.all
54
67
  }
55
68
  PATTERN
56
69
 
@@ -66,6 +79,8 @@ module RuboCop
66
79
  PATTERN
67
80
 
68
81
  def on_send(node)
82
+ return if node.chained? || node.each_ancestor(:def, :defs).any?
83
+
69
84
  focus_metadata(node) do |focus|
70
85
  add_offense(focus) do |corrector|
71
86
  if focus.pair_type? || focus.str_type? || focus.sym_type?