rubocop-rspec 2.12.1 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -86
  3. data/config/default.yml +44 -6
  4. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +8 -9
  5. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +8 -9
  6. data/lib/rubocop/cop/rspec/any_instance.rb +1 -0
  7. data/lib/rubocop/cop/rspec/around_block.rb +26 -3
  8. data/lib/rubocop/cop/rspec/be.rb +0 -1
  9. data/lib/rubocop/cop/rspec/be_eq.rb +0 -1
  10. data/lib/rubocop/cop/rspec/be_eql.rb +0 -1
  11. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -0
  12. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +9 -3
  13. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +2 -1
  14. data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +86 -0
  15. data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +91 -10
  16. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +0 -1
  17. data/lib/rubocop/cop/rspec/change_by_zero.rb +60 -5
  18. data/lib/rubocop/cop/rspec/class_check.rb +101 -0
  19. data/lib/rubocop/cop/rspec/context_method.rb +2 -1
  20. data/lib/rubocop/cop/rspec/context_wording.rb +49 -18
  21. data/lib/rubocop/cop/rspec/describe_class.rb +1 -1
  22. data/lib/rubocop/cop/rspec/describe_method.rb +1 -0
  23. data/lib/rubocop/cop/rspec/described_class.rb +4 -14
  24. data/lib/rubocop/cop/rspec/dialect.rb +1 -0
  25. data/lib/rubocop/cop/rspec/empty_example_group.rb +19 -4
  26. data/lib/rubocop/cop/rspec/empty_hook.rb +2 -1
  27. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +4 -9
  28. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  29. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +2 -1
  30. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +32 -2
  31. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +2 -1
  32. data/lib/rubocop/cop/rspec/example_length.rb +2 -1
  33. data/lib/rubocop/cop/rspec/example_without_description.rb +2 -1
  34. data/lib/rubocop/cop/rspec/example_wording.rb +2 -1
  35. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +1 -0
  36. data/lib/rubocop/cop/rspec/expect_actual.rb +3 -0
  37. data/lib/rubocop/cop/rspec/expect_change.rb +1 -1
  38. data/lib/rubocop/cop/rspec/expect_in_hook.rb +4 -1
  39. data/lib/rubocop/cop/rspec/expect_output.rb +1 -0
  40. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +2 -1
  41. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +26 -12
  42. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -0
  43. data/lib/rubocop/cop/rspec/file_path.rb +6 -3
  44. data/lib/rubocop/cop/rspec/focus.rb +18 -0
  45. data/lib/rubocop/cop/rspec/hook_argument.rb +7 -2
  46. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +10 -9
  47. data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +0 -1
  48. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +1 -0
  49. data/lib/rubocop/cop/rspec/implicit_expect.rb +0 -2
  50. data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
  51. data/lib/rubocop/cop/rspec/instance_variable.rb +0 -1
  52. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -0
  53. data/lib/rubocop/cop/rspec/iterated_expectation.rb +16 -0
  54. data/lib/rubocop/cop/rspec/leading_subject.rb +15 -15
  55. data/lib/rubocop/cop/rspec/let_before_examples.rb +7 -8
  56. data/lib/rubocop/cop/rspec/let_setup.rb +4 -4
  57. data/lib/rubocop/cop/rspec/message_chain.rb +1 -1
  58. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +2 -1
  59. data/lib/rubocop/cop/rspec/mixin/css_selector.rb +99 -0
  60. data/lib/rubocop/cop/rspec/mixin/namespace.rb +23 -0
  61. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -0
  62. data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -5
  63. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +1 -3
  64. data/lib/rubocop/cop/rspec/multiple_subjects.rb +17 -2
  65. data/lib/rubocop/cop/rspec/named_subject.rb +2 -1
  66. data/lib/rubocop/cop/rspec/nested_groups.rb +45 -25
  67. data/lib/rubocop/cop/rspec/no_expectation_example.rb +64 -0
  68. data/lib/rubocop/cop/rspec/not_to_not.rb +1 -2
  69. data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -1
  70. data/lib/rubocop/cop/rspec/pending.rb +1 -0
  71. data/lib/rubocop/cop/rspec/predicate_matcher.rb +2 -1
  72. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +1 -2
  73. data/lib/rubocop/cop/rspec/receive_counts.rb +14 -15
  74. data/lib/rubocop/cop/rspec/receive_never.rb +4 -5
  75. data/lib/rubocop/cop/rspec/repeated_description.rb +25 -26
  76. data/lib/rubocop/cop/rspec/repeated_example.rb +1 -1
  77. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +28 -29
  78. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +28 -29
  79. data/lib/rubocop/cop/rspec/repeated_include_example.rb +32 -33
  80. data/lib/rubocop/cop/rspec/return_from_stub.rb +1 -1
  81. data/lib/rubocop/cop/rspec/scattered_let.rb +1 -5
  82. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  83. data/lib/rubocop/cop/rspec/shared_context.rb +1 -1
  84. data/lib/rubocop/cop/rspec/stubbed_mock.rb +0 -1
  85. data/lib/rubocop/cop/rspec/subject_declaration.rb +0 -1
  86. data/lib/rubocop/cop/rspec/subject_stub.rb +2 -2
  87. data/lib/rubocop/cop/rspec/unspecified_exception.rb +15 -15
  88. data/lib/rubocop/cop/rspec/variable_definition.rb +1 -0
  89. data/lib/rubocop/cop/rspec/variable_name.rb +6 -7
  90. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -0
  91. data/lib/rubocop/cop/rspec/void_expect.rb +2 -1
  92. data/lib/rubocop/cop/rspec/yield.rb +2 -1
  93. data/lib/rubocop/cop/rspec_cops.rb +3 -0
  94. data/lib/rubocop/rspec/config_formatter.rb +14 -3
  95. data/lib/rubocop/rspec/inject.rb +1 -3
  96. data/lib/rubocop/rspec/language/node_pattern.rb +4 -0
  97. data/lib/rubocop/rspec/language.rb +6 -1
  98. data/lib/rubocop/rspec/version.rb +1 -1
  99. data/lib/rubocop/rspec/wording.rb +2 -2
  100. data/lib/rubocop/rspec.rb +14 -0
  101. data/lib/rubocop-rspec.rb +3 -0
  102. metadata +10 -88
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a543787a865d7e8062e0b746c1b5dd641214bd17b17d25182a58b4a646c4bfb6
4
- data.tar.gz: 57ddde6cfed19062929b00c729dd7403955bf3c92a8b5354cb3704bd7382c5ef
3
+ metadata.gz: 31d7e881e40be6a9b27f78f77789f1ecc5056bb073f5028a5c3dc0c6e1fe81ad
4
+ data.tar.gz: 7ad05e5a9ecfa1230aabfa54c7e6f9d7649f428017c405a9ed68d4da95218dd2
5
5
  SHA512:
6
- metadata.gz: d4a03f557f7f2e7a7a24f01e14db9e7599ce08c7921618d877b807fd37ef065d97556b428931c4129b19ef1d791e072828fd0f3705797d1ec98c69eb7f25cf45
7
- data.tar.gz: 0d7bacaeb99c2c60594d507158434e8740c5b2a96032f73db4247cd16ff0963b46de2313d3bf76cf6bb0ed3d33b1751f663062e00cef095ab4310642a4e5153c
6
+ metadata.gz: dfa4fca8f641da881b6014b91f5df8678af96c60e937339a81a64efd0bd87859ddc5876f977a995ae52a844e88bd53d46d50e0b37fd933b37e18da830991f245
7
+ data.tar.gz: f7779621a7c6fc6e33bf47b6823cfe7c4be08cc0f32ac02465cd4cbe35a1b8d4ed280a71c33f6fcfd7195a65191f68c9f9c13cdb0f8624a0a3e80be56af4dd50
data/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.13.0 (2022-09-12)
6
+
7
+ * Fix `RSpec/FilePath` cop missing mismatched expanded namespace. ([@sl4vr][])
8
+ * Add new `AllowConsecutiveOneLiners` (default true) option for `Rspec/EmptyLineAfterHook` cop. ([@ngouy][])
9
+ * Add autocorrect support for `RSpec/EmptyExampleGroup`. ([@r7kamura][])
10
+ * Fix `RSpec/ChangeByZero` with compound expressions using `&` or `|` operators. ([@BrianHawley][])
11
+ * Add `RSpec/NoExpectationExample`. ([@r7kamura][])
12
+ * Add some expectation methods to default configuration. ([@r7kamura][])
13
+ * Fix a false positive for `RSpec/Capybara/SpecificMatcher`. ([@ydah][])
14
+ * Fix a false negative for `RSpec/Capybara/SpecificMatcher` for `have_field`. ([@ydah][])
15
+ * Fix a false positive for `RSpec/Capybara/SpecificMatcher` when may not have a `href` by `have_link`. ([@ydah][])
16
+ * Add `NegatedMatcher` configuration option to `RSpec/ChangeByZero`. ([@ydah][])
17
+ * Add new `RSpec/Capybara/SpecificFinders` cop. ([@ydah][])
18
+ * Add support for numblocks to `RSpec/AroundBlock`, `RSpec/EmptyLineAfterHook`, `RSpec/ExpectInHook`, `RSpec/HookArgument`, `RSpec/HooksBeforeExamples`, `RSpec/IteratedExpectation`, and `RSpec/NoExpectationExample`. ([@ydah][])
19
+ * Fix incorrect documentation URLs when using `rubocop --show-docs-url`. ([@r7kamura][])
20
+ * Add `AllowedGroups` configuration option to `RSpec/NestedGroups`. ([@ydah][])
21
+ * Deprecate `IgnoredPatterns` option in favor of the `AllowedPatterns` options. ([@ydah][])
22
+ * Add `AllowedPatterns` configuration option to `RSpec/ContextWording`. ([@ydah][])
23
+ * Add `RSpec/ClassCheck` cop. ([@r7kamura][])
24
+ * Fix a false positive for `RSpec/Capybara/SpecificMatcher` when pseudo-classes. ([@ydah][])
25
+ * Fix a false negative for `RSpec/SubjectStub` when the subject is declared with the `subject!` method and called by name. ([@eikes][])
26
+ * Support `Array.new(n)` on `RSpec/FactoryBot/CreateList` cop. ([@r7kamura][])
27
+
5
28
  ## 2.12.1 (2022-07-03)
6
29
 
7
30
  * Fix a false positive for `RSpec/Capybara/SpecificMatcher`. ([@ydah][])
@@ -603,114 +626,115 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
603
626
  * Split `UnitSpecNaming` cop into `RSpecDescribeClass`, `RSpecDescribeMethod` and `RSpecFileName` and enabled them all by default. ([@geniou][])
604
627
  * Add `RSpecExampleWording` cop to prevent to use of should at the beginning of the spec description. ([@geniou][])
605
628
  * Fix `RSpecFileName` cop for non-class specs. ([@geniou][])
606
- * Adapt `RSpecFileName` cop to commen naming convention and skip spec with multiple top level describes. ([@geniou][])
629
+ * Adapt `RSpecFileName` cop to common naming convention and skip spec with multiple top level describes. ([@geniou][])
607
630
  * Add `RSpecMultipleDescribes` cop to check for multiple top level describes. ([@geniou][])
608
631
  * Add `RSpecDescribedClass` to promote the use of `described_class`. ([@geniou][])
609
632
  * Add `RSpecInstanceVariable` cop to check for the usage of instance variables. ([@geniou][])
610
633
 
611
- <!-- Contributors -->
634
+ <!-- Contributors (alphabetically) -->
612
635
 
636
+ [@abrom]: https://github.com/abrom
637
+ [@ahukkanen]: https://github.com/ahukkanen
638
+ [@akiomik]: https://github.com/akiomik
639
+ [@AlexWayfer]: https://github.com/AlexWayfer
640
+ [@andrykonchin]: https://github.com/andrykonchin
613
641
  [@andyw8]: https://github.com/andyw8
642
+ [@anthony-robin]: https://github.com/anthony-robin
643
+ [@aried3r]: https://github.com/aried3r
644
+ [@baberthal]: https://github.com/baberthal
614
645
  [@backus]: https://github.com/backus
646
+ [@biinari]: https://github.com/biinari
647
+ [@bmorrall]: https://github.com/bmorrall
615
648
  [@bquorning]: https://github.com/bquorning
649
+ [@BrentWheeldon]: https://github.com/BrentWheeldon
650
+ [@BrianHawley]: https://github.com/BrianHawley
651
+ [@cfabianski]: https://github.com/cfabianski
652
+ [@clupprich]: https://github.com/clupprich
653
+ [@composerinteralia]: https://github.com/composerinteralia
654
+ [@Darhazer]: https://github.com/Darhazer
655
+ [@daveworth]: https://github.com/daveworth
656
+ [@dduugg]: https://github.com/dduugg
616
657
  [@deivid-rodriguez]: https://github.com/deivid-rodriguez
658
+ [@dgollahon]: https://github.com/dgollahon
659
+ [@Drowze]: https://github.com/Drowze
660
+ [@dswij]: https://github.com/dswij
661
+ [@dvandersluis]: https://github.com/dvandersluis
662
+ [@edgibbs]: https://github.com/edgibbs
663
+ [@eikes]: https://github.com/eikes
664
+ [@eitoball]: https://github.com/eitoball
665
+ [@elebow]: https://github.com/elebow
666
+ [@EliseFitz15]: https://github.com/EliseFitz15
667
+ [@elliterate]: https://github.com/elliterate
668
+ [@foton]: https://github.com/foton
669
+ [@francois-ferrandis]: https://github.com/francois-ferrandis
670
+ [@G-Rath]: https://github.com/G-Rath
617
671
  [@geniou]: https://github.com/geniou
672
+ [@gsamokovarov]: https://github.com/gsamokovarov
673
+ [@harry-graham]: https://github.com/harry-graham
674
+ [@harrylewis]: https://github.com/harrylewis
675
+ [@hosamaly]: https://github.com/hosamaly
618
676
  [@jaredbeck]: https://github.com/jaredbeck
619
- [@jawshooah]: https://github.com/jawshooah
620
- [@nevir]: https://github.com/nevir
621
- [@nijikon]: https://github.com/nijikon
622
- [@pstengel]: https://github.com/pstengel
623
- [@miguelfteixeira]: https://github.com/miguelfteixeira
624
- [@mlarraz]: https://github.com/mlarraz
625
- [@renanborgescampos]: https://github.com/renanborgescampos
626
677
  [@jaredmoody]: https://github.com/jaredmoody
627
- [@baberthal]: https://github.com/baberthal
628
678
  [@jeffreyc]: https://github.com/jeffreyc
629
- [@clupprich]: https://github.com/clupprich
630
- [@onk]: https://github.com/onk
631
- [@Darhazer]: https://github.com/Darhazer
632
- [@redross]: https://github.com/redross
633
- [@cfabianski]: https://github.com/cfabianski
634
- [@dgollahon]: https://github.com/dgollahon
635
- [@rspeicher]: https://github.com/rspeicher
636
- [@jonatas]: https://github.com/jonatas
637
- [@pocke]: https://github.com/pocke
638
- [@bmorrall]: https://github.com/bmorrall
639
- [@zverok]: https://github.com/zverok
640
- [@timrogers]: https://github.com/timrogers
641
- [@yevhene]: https://github.com/yevhene
642
- [@walf443]: https://github.com/walf443
643
- [@pirj]: https://github.com/pirj
644
- [@telmofcosta]: https://github.com/telmofcosta
645
- [@EliseFitz15]: https://github.com/EliseFitz15
646
- [@anthony-robin]: https://github.com/anthony-robin
679
+ [@jfragoulis]: https://github.com/jfragoulis
680
+ [@johnny-miyake]: https://github.com/johnny-miyake
647
681
  [@jojos003]: https://github.com/jojos003
648
- [@abrom]: https://github.com/abrom
649
- [@patrickomatic]: https://github.com/patrickomatic
650
- [@tdeo]: https://github.com/tdeo
651
- [@composerinteralia]: https://github.com/composerinteralia
652
- [@seanpdoyle]: https://github.com/seanpdoyle
653
- [@vzvu3k6k]: https://github.com/vzvu3k6k
654
- [@BrentWheeldon]: https://github.com/BrentWheeldon
655
- [@daveworth]: https://github.com/daveworth
656
- [@RST-J]: https://github.com/RST-J
657
- [@ypresto]: https://github.com/ypresto
682
+ [@jonatas]: https://github.com/jonatas
683
+ [@jtannas]: https://github.com/jtannas
684
+ [@kellysutton]: https://github.com/kellysutton
685
+ [@koic]: https://github.com/koic
686
+ [@lazycoder9]: https://github.com/lazycoder9
687
+ [@leoarnold]: https://github.com/leoarnold
688
+ [@lokhi]: https://github.com/lokhi
689
+ [@luke-hill]: https://github.com/luke-hill
690
+ [@M-Yamashita01]: https://github.com/M-Yamashita01
691
+ [@miguelfteixeira]: https://github.com/miguelfteixeira
658
692
  [@mkenyon]: https://github.com/mkenyon
659
- [@gsamokovarov]: https://github.com/gsamokovarov
660
- [@schmijos]: https://github.com/schmijos
661
- [@foton]: https://github.com/foton
693
+ [@mkrawc]: https://github.com/mkrawc
694
+ [@mlarraz]: https://github.com/mlarraz
695
+ [@mockdeep]: https://github.com/mockdeep
696
+ [@MothOnMars]: https://github.com/MothOnMars
662
697
  [@nc-holodakg]: https://github.com/nc-holodakg
663
- [@onumis]: https://github.com/onumis
698
+ [@nevir]: https://github.com/nevir
699
+ [@ngouy]: https://github.com/ngouy
664
700
  [@nickcampbell18]: https://github.com/nickcampbell18
701
+ [@nijikon]: https://github.com/nijikon
702
+ [@onk]: https://github.com/onk
703
+ [@onumis]: https://github.com/onumis
704
+ [@oshiro3]: https://github.com/oshiro3
705
+ [@patrickomatic]: https://github.com/patrickomatic
706
+ [@paydaylight]: https://github.com/paydaylight
707
+ [@PhilCoggins]: https://github.com/PhilCoggins
708
+ [@pirj]: https://github.com/pirj
709
+ [@pocke]: https://github.com/pocke
710
+ [@pstengel]: https://github.com/pstengel
665
711
  [@QQism]: https://github.com/QQism
666
- [@kellysutton]: https://github.com/kellysutton
667
- [@mkrawc]: https://github.com/mkrawc
668
- [@jfragoulis]: https://github.com/jfragoulis
669
- [@ybiquitous]: https://github.com/ybiquitous
670
- [@dduugg]: https://github.com/dduugg
671
- [@lazycoder9]: https://github.com/lazycoder9
672
- [@elebow]: https://github.com/elebow
673
- [@eitoball]: https://github.com/eitoball
674
- [@aried3r]: https://github.com/aried3r
675
- [@AlexWayfer]: https://github.com/AlexWayfer
676
- [@tejasbubane]: https://github.com/tejasbubane
677
- [@twalpole]: https://github.com/twalpole
678
- [@zdennis]: https://github.com/zdennis
712
+ [@r7kamura]: https://github.com/r7kamura
713
+ [@Rafix02]: https://github.com/Rafix02
714
+ [@redross]: https://github.com/redross
715
+ [@renanborgescampos]: https://github.com/renanborgescampos
679
716
  [@robotdana]: https://github.com/robotdana
680
717
  [@rolfschmidt]: https://github.com/rolfschmidt
681
- [@andrykonchin]: https://github.com/andrykonchin
682
- [@harrylewis]: https://github.com/harrylewis
683
- [@elliterate]: https://github.com/elliterate
684
- [@jtannas]: https://github.com/jtannas
685
- [@mockdeep]: https://github.com/mockdeep
686
- [@biinari]: https://github.com/biinari
687
- [@koic]: https://github.com/koic
688
- [@Rafix02]: https://github.com/Rafix02
689
- [@PhilCoggins]: https://github.com/PhilCoggins
718
+ [@rrosenblum]: https://github.com/rrosenblum
719
+ [@rspeicher]: https://github.com/rspeicher
720
+ [@RST-J]: https://github.com/RST-J
721
+ [@schmijos]: https://github.com/schmijos
722
+ [@seanpdoyle]: https://github.com/seanpdoyle
690
723
  [@sl4vr]: https://github.com/sl4vr
691
- [@ahukkanen]: https://github.com/ahukkanen
692
- [@dvandersluis]: https://github.com/dvandersluis
693
- [@hosamaly]: https://github.com/hosamaly
694
724
  [@stephannv]: https://github.com/stephannv
725
+ [@t3h2mas]: https://github.com/t3h2mas
726
+ [@tdeo]: https://github.com/tdeo
727
+ [@tejasbubane]: https://github.com/tejasbubane
728
+ [@telmofcosta]: https://github.com/telmofcosta
695
729
  [@Tietew]: https://github.com/Tietew
696
- [@rrosenblum]: https://github.com/rrosenblum
697
- [@paydaylight]: https://github.com/paydaylight
730
+ [@timrogers]: https://github.com/timrogers
698
731
  [@topalovic]: https://github.com/topalovic
699
- [@lokhi]: https://github.com/lokhi
700
- [@MothOnMars]: https://github.com/MothOnMars
701
- [@G-Rath]: https://github.com/G-Rath
702
- [@dswij]: https://github.com/dswij
703
- [@francois-ferrandis]: https://github.com/francois-ferrandis
704
- [@r7kamura]: https://github.com/r7kamura
705
- [@leoarnold]: https://github.com/leoarnold
706
- [@harry-graham]: https://github.com/harry-graham
707
- [@oshiro3]: https://github.com/oshiro3
732
+ [@twalpole]: https://github.com/twalpole
733
+ [@vzvu3k6k]: https://github.com/vzvu3k6k
734
+ [@walf443]: https://github.com/walf443
735
+ [@ybiquitous]: https://github.com/ybiquitous
708
736
  [@ydah]: https://github.com/ydah
709
- [@t3h2mas]: https://github.com/t3h2mas
710
- [@M-Yamashita01]: https://github.com/M-Yamashita01
711
- [@luke-hill]: https://github.com/luke-hill
712
- [@johnny-miyake]: https://github.com/johnny-miyake
713
- [@ngouy]: https://github.com/ngouy
714
- [@edgibbs]: https://github.com/edgibbs
715
- [@Drowze]: https://github.com/Drowze
716
- [@akiomik]: https://github.com/akiomik
737
+ [@yevhene]: https://github.com/yevhene
738
+ [@ypresto]: https://github.com/ypresto
739
+ [@zdennis]: https://github.com/zdennis
740
+ [@zverok]: https://github.com/zverok
data/config/default.yml CHANGED
@@ -2,6 +2,7 @@
2
2
  RSpec:
3
3
  Enabled: true
4
4
  StyleGuideBaseURL: https://rspec.rubystyle.guide
5
+ DocumentationBaseURL: https://docs.rubocop.org/rubocop-rspec
5
6
  Include: &1
6
7
  - "**/*_spec.rb"
7
8
  - "**/spec/**/*"
@@ -61,9 +62,14 @@ RSpec:
61
62
  Pending:
62
63
  - pending
63
64
  Expectations:
65
+ - are_expected
64
66
  - expect
65
- - is_expected
66
67
  - expect_any_instance_of
68
+ - is_expected
69
+ - should
70
+ - should_not
71
+ - should_not_receive
72
+ - should_receive
67
73
  Helpers:
68
74
  - let
69
75
  - let!
@@ -187,8 +193,21 @@ RSpec/BeforeAfterAll:
187
193
  RSpec/ChangeByZero:
188
194
  Description: Prefer negated matchers over `to change.by(0)`.
189
195
  Enabled: pending
190
- VersionAdded: 2.11.0
196
+ VersionAdded: '2.11'
197
+ VersionChanged: '2.13'
191
198
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ChangeByZero
199
+ NegatedMatcher: ~
200
+
201
+ RSpec/ClassCheck:
202
+ Description: Enforces consistent use of `be_a` or `be_kind_of`.
203
+ StyleGuide: "#is-a-vs-kind-of"
204
+ Enabled: pending
205
+ VersionAdded: '2.13'
206
+ EnforcedStyle: be_a
207
+ SupportedStyles:
208
+ - be_a
209
+ - be_kind_of
210
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ClassCheck
192
211
 
193
212
  RSpec/ContextMethod:
194
213
  Description: "`context` should not be used for specifying methods."
@@ -204,8 +223,9 @@ RSpec/ContextWording:
204
223
  - when
205
224
  - with
206
225
  - without
226
+ AllowedPatterns: []
207
227
  VersionAdded: '1.20'
208
- VersionChanged: 1.20.1
228
+ VersionChanged: '2.13'
209
229
  StyleGuide: https://rspec.rubystyle.guide/#context-descriptions
210
230
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextWording
211
231
 
@@ -279,8 +299,9 @@ RSpec/Dialect:
279
299
  RSpec/EmptyExampleGroup:
280
300
  Description: Checks if an example group does not include any tests.
281
301
  Enabled: true
302
+ SafeAutoCorrect: false
282
303
  VersionAdded: '1.7'
283
- VersionChanged: '2.0'
304
+ VersionChanged: '2.13'
284
305
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup
285
306
 
286
307
  RSpec/EmptyHook:
@@ -315,8 +336,10 @@ RSpec/EmptyLineAfterHook:
315
336
  Description: Checks if there is an empty line after hook blocks.
316
337
  Enabled: true
317
338
  VersionAdded: '1.27'
339
+ VersionChanged: '2.13'
318
340
  StyleGuide: https://rspec.rubystyle.guide/#empty-line-after-let
319
341
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterHook
342
+ AllowConsecutiveOneLiners: true
320
343
 
321
344
  RSpec/EmptyLineAfterSubject:
322
345
  Description: Checks if there is an empty line after subject block.
@@ -607,10 +630,18 @@ RSpec/NestedGroups:
607
630
  Description: Checks for nested example groups.
608
631
  Enabled: true
609
632
  Max: 3
633
+ AllowedGroups: []
610
634
  VersionAdded: '1.7'
611
- VersionChanged: '1.10'
635
+ VersionChanged: '2.13'
612
636
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NestedGroups
613
637
 
638
+ RSpec/NoExpectationExample:
639
+ Description: Checks if an example contains any expectation.
640
+ Enabled: pending
641
+ Safe: false
642
+ VersionAdded: '2.13'
643
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NoExpectationExample
644
+
614
645
  RSpec/NotToNot:
615
646
  Description: Checks for consistent method usage for negating expectations.
616
647
  Enabled: true
@@ -775,9 +806,10 @@ RSpec/VariableName:
775
806
  SupportedStyles:
776
807
  - snake_case
777
808
  - camelCase
809
+ AllowedPatterns: []
778
810
  IgnoredPatterns: []
779
811
  VersionAdded: '1.40'
780
- VersionChanged: '1.43'
812
+ VersionChanged: '2.13'
781
813
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableName
782
814
 
783
815
  RSpec/VerifiedDoubleReference:
@@ -834,6 +866,12 @@ RSpec/Capybara/FeatureMethods:
834
866
  VersionChanged: '2.0'
835
867
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
836
868
 
869
+ RSpec/Capybara/SpecificFinders:
870
+ Description: Checks if there is a more specific finder offered by Capybara.
871
+ Enabled: pending
872
+ VersionAdded: '2.13'
873
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificFinders
874
+
837
875
  RSpec/Capybara/SpecificMatcher:
838
876
  Description: Checks for there is a more specific matcher offered by Capybara.
839
877
  Enabled: pending
@@ -6,16 +6,15 @@ module RuboCop
6
6
  # Checks that left braces for adjacent single line lets are aligned.
7
7
  #
8
8
  # @example
9
+ # # bad
10
+ # let(:foobar) { blahblah }
11
+ # let(:baz) { bar }
12
+ # let(:a) { b }
9
13
  #
10
- # # bad
11
- # let(:foobar) { blahblah }
12
- # let(:baz) { bar }
13
- # let(:a) { b }
14
- #
15
- # # good
16
- # let(:foobar) { blahblah }
17
- # let(:baz) { bar }
18
- # let(:a) { b }
14
+ # # good
15
+ # let(:foobar) { blahblah }
16
+ # let(:baz) { bar }
17
+ # let(:a) { b }
19
18
  #
20
19
  class AlignLeftLetBrace < Base
21
20
  extend AutoCorrector
@@ -6,16 +6,15 @@ module RuboCop
6
6
  # Checks that right braces for adjacent single line lets are aligned.
7
7
  #
8
8
  # @example
9
+ # # bad
10
+ # let(:foobar) { blahblah }
11
+ # let(:baz) { bar }
12
+ # let(:a) { b }
9
13
  #
10
- # # bad
11
- # let(:foobar) { blahblah }
12
- # let(:baz) { bar }
13
- # let(:a) { b }
14
- #
15
- # # good
16
- # let(:foobar) { blahblah }
17
- # let(:baz) { bar }
18
- # let(:a) { b }
14
+ # # good
15
+ # let(:foobar) { blahblah }
16
+ # let(:baz) { bar }
17
+ # let(:a) { b }
19
18
  #
20
19
  class AlignRightLetBrace < Base
21
20
  extend AutoCorrector
@@ -22,6 +22,7 @@ module RuboCop
22
22
  # allow(my_instance).to receive(:foo)
23
23
  # end
24
24
  # end
25
+ #
25
26
  class AnyInstance < Base
26
27
  MSG = 'Avoid stubbing using `%<method>s`.'
27
28
  RESTRICT_ON_SEND = %i[
@@ -25,23 +25,29 @@ module RuboCop
25
25
  # some_method
26
26
  # test.run
27
27
  # end
28
+ #
28
29
  class AroundBlock < Base
29
30
  MSG_NO_ARG = 'Test object should be passed to around block.'
30
31
  MSG_UNUSED_ARG = 'You should call `%<arg>s.call` ' \
31
32
  'or `%<arg>s.run`.'
32
33
 
33
- # @!method hook(node)
34
- def_node_matcher :hook, <<-PATTERN
34
+ # @!method hook_block(node)
35
+ def_node_matcher :hook_block, <<-PATTERN
35
36
  (block (send nil? :around sym ?) (args $...) ...)
36
37
  PATTERN
37
38
 
39
+ # @!method hook_numblock(node)
40
+ def_node_matcher :hook_numblock, <<-PATTERN
41
+ (numblock (send nil? :around sym ?) ...)
42
+ PATTERN
43
+
38
44
  # @!method find_arg_usage(node)
39
45
  def_node_search :find_arg_usage, <<-PATTERN
40
46
  {(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
41
47
  PATTERN
42
48
 
43
49
  def on_block(node)
44
- hook(node) do |(example_proxy)|
50
+ hook_block(node) do |(example_proxy)|
45
51
  if example_proxy.nil?
46
52
  add_no_arg_offense(node)
47
53
  else
@@ -50,6 +56,12 @@ module RuboCop
50
56
  end
51
57
  end
52
58
 
59
+ def on_numblock(node)
60
+ hook_numblock(node) do
61
+ check_for_numblock(node)
62
+ end
63
+ end
64
+
53
65
  private
54
66
 
55
67
  def add_no_arg_offense(node)
@@ -68,6 +80,17 @@ module RuboCop
68
80
  message: format(MSG_UNUSED_ARG, arg: name)
69
81
  )
70
82
  end
83
+
84
+ def check_for_numblock(block)
85
+ find_arg_usage(block) do |usage|
86
+ return if usage.include?(s(:lvar, :_1))
87
+ end
88
+
89
+ add_offense(
90
+ block.children.last,
91
+ message: format(MSG_UNUSED_ARG, arg: :_1)
92
+ )
93
+ end
71
94
  end
72
95
  end
73
96
  end
@@ -10,7 +10,6 @@ module RuboCop
10
10
  # cases it's better to specify what exactly is the expected value.
11
11
  #
12
12
  # @example
13
- #
14
13
  # # bad
15
14
  # expect(foo).to be
16
15
  #
@@ -10,7 +10,6 @@ module RuboCop
10
10
  # the `be` matcher is preferable as it is a more strict test.
11
11
  #
12
12
  # @example
13
- #
14
13
  # # bad
15
14
  # expect(foo).to eq(true)
16
15
  # expect(foo).to eq(false)
@@ -11,7 +11,6 @@ module RuboCop
11
11
  # preferable as it is a more strict test.
12
12
  #
13
13
  # @example
14
- #
15
14
  # # bad
16
15
  # expect(foo).to eql(1)
17
16
  # expect(foo).to eql(1.0)
@@ -23,6 +23,7 @@ module RuboCop
23
23
  # before(:each) { Widget.create }
24
24
  # after(:each) { Widget.delete_all }
25
25
  # end
26
+ #
26
27
  class BeforeAfterAll < Base
27
28
  MSG = 'Beware of using `%<hook>s` as it may cause state to leak ' \
28
29
  'between tests. If you are using `rspec-rails`, and ' \
@@ -14,14 +14,20 @@ module RuboCop
14
14
  # which ensures that preceding actions (like `click_link`) have
15
15
  # completed.
16
16
  #
17
+ # This cop does not support autocorrection in some cases.
18
+ #
17
19
  # @example
18
20
  # # bad
19
21
  # expect(current_path).to eq('/callback')
20
- # expect(page.current_path).to match(/widgets/)
21
22
  #
22
23
  # # good
23
- # expect(page).to have_current_path("/callback")
24
- # expect(page).to have_current_path(/widgets/)
24
+ # expect(page).to have_current_path('/callback')
25
+ #
26
+ # # bad (does not support autocorrection)
27
+ # expect(page.current_path).to match(variable)
28
+ #
29
+ # # good
30
+ # expect(page).to have_current_path('/callback')
25
31
  #
26
32
  class CurrentPathExpectation < Base
27
33
  extend AutoCorrector
@@ -40,6 +40,7 @@ module RuboCop
40
40
  # # ...
41
41
  # end
42
42
  # end
43
+ #
43
44
  class FeatureMethods < Base
44
45
  extend AutoCorrector
45
46
  include InsideExampleGroup
@@ -68,7 +69,7 @@ module RuboCop
68
69
  ...)
69
70
  PATTERN
70
71
 
71
- def on_block(node)
72
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
72
73
  return unless inside_example_group?(node)
73
74
 
74
75
  feature_method(node) do |send_node, match|
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ module Capybara
7
+ # Checks if there is a more specific finder offered by Capybara.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # find('#some-id')
12
+ # find('[visible][id=some-id]')
13
+ #
14
+ # # good
15
+ # find_by_id('some-id')
16
+ # find_by_id('some-id', visible: true)
17
+ #
18
+ class SpecificFinders < Base
19
+ extend AutoCorrector
20
+
21
+ include RangeHelp
22
+
23
+ MSG = 'Prefer `find_by` over `find`.'
24
+ RESTRICT_ON_SEND = %i[find].freeze
25
+
26
+ # @!method find_argument(node)
27
+ def_node_matcher :find_argument, <<~PATTERN
28
+ (send _ :find (str $_) ...)
29
+ PATTERN
30
+
31
+ def on_send(node)
32
+ find_argument(node) do |arg|
33
+ next if CssSelector.multiple_selectors?(arg)
34
+
35
+ on_attr(node, arg) if attribute?(arg)
36
+ on_id(node, arg) if CssSelector.id?(arg)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def on_attr(node, arg)
43
+ return unless (id = CssSelector.attributes(arg)['id'])
44
+
45
+ register_offense(node, replaced_arguments(arg, id))
46
+ end
47
+
48
+ def on_id(node, arg)
49
+ register_offense(node, "'#{arg.to_s.delete('#')}'")
50
+ end
51
+
52
+ def attribute?(arg)
53
+ CssSelector.attribute?(arg) &&
54
+ CssSelector.common_attributes?(arg)
55
+ end
56
+
57
+ def register_offense(node, arg_replacement)
58
+ add_offense(offense_range(node)) do |corrector|
59
+ corrector.replace(node.loc.selector, 'find_by_id')
60
+ corrector.replace(node.first_argument.loc.expression,
61
+ arg_replacement)
62
+ end
63
+ end
64
+
65
+ def replaced_arguments(arg, id)
66
+ options = to_options(CssSelector.attributes(arg))
67
+ options.empty? ? id : "#{id}, #{options}"
68
+ end
69
+
70
+ def to_options(attrs)
71
+ attrs.each.map do |key, value|
72
+ next if key == 'id'
73
+
74
+ "#{key}: #{value}"
75
+ end.compact.join(', ')
76
+ end
77
+
78
+ def offense_range(node)
79
+ range_between(node.loc.selector.begin_pos,
80
+ node.loc.end.end_pos)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end