rubocop-rspec 2.16.0 → 2.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +124 -9
  3. data/README.md +3 -3
  4. data/config/default.yml +145 -18
  5. data/config/obsoletion.yml +15 -0
  6. data/lib/rubocop/cop/rspec/be_empty.rb +44 -0
  7. data/lib/rubocop/cop/rspec/be_nil.rb +2 -2
  8. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +29 -115
  9. data/lib/rubocop/cop/rspec/capybara/match_style.rb +38 -0
  10. data/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +23 -96
  11. data/lib/rubocop/cop/rspec/capybara/specific_actions.rb +19 -75
  12. data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +14 -83
  13. data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +25 -69
  14. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +26 -63
  15. data/lib/rubocop/cop/rspec/change_by_zero.rb +33 -23
  16. data/lib/rubocop/cop/rspec/contain_exactly.rb +56 -0
  17. data/lib/rubocop/cop/rspec/context_method.rb +5 -1
  18. data/lib/rubocop/cop/rspec/context_wording.rb +13 -6
  19. data/lib/rubocop/cop/rspec/describe_method.rb +16 -8
  20. data/lib/rubocop/cop/rspec/described_class.rb +2 -1
  21. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +7 -5
  22. data/lib/rubocop/cop/rspec/dialect.rb +1 -1
  23. data/lib/rubocop/cop/rspec/duplicated_metadata.rb +2 -2
  24. data/lib/rubocop/cop/rspec/empty_example_group.rb +10 -7
  25. data/lib/rubocop/cop/rspec/empty_hook.rb +2 -2
  26. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  27. data/lib/rubocop/cop/rspec/empty_metadata.rb +46 -0
  28. data/lib/rubocop/cop/rspec/eq.rb +47 -0
  29. data/lib/rubocop/cop/rspec/example_wording.rb +1 -1
  30. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +14 -5
  31. data/lib/rubocop/cop/rspec/expect_actual.rb +4 -4
  32. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  33. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +25 -118
  34. data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +40 -107
  35. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +30 -250
  36. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +19 -46
  37. data/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +23 -64
  38. data/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +45 -79
  39. data/lib/rubocop/cop/rspec/file_path.rb +8 -2
  40. data/lib/rubocop/cop/rspec/focus.rb +19 -5
  41. data/lib/rubocop/cop/rspec/hook_argument.rb +12 -9
  42. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +5 -3
  43. data/lib/rubocop/cop/rspec/indexed_let.rb +112 -0
  44. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
  45. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
  46. data/lib/rubocop/cop/rspec/let_before_examples.rb +8 -4
  47. data/lib/rubocop/cop/rspec/let_setup.rb +6 -8
  48. data/lib/rubocop/cop/rspec/match_array.rb +59 -0
  49. data/lib/rubocop/cop/rspec/metadata_style.rb +197 -0
  50. data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +1 -2
  51. data/lib/rubocop/cop/rspec/mixin/file_help.rb +14 -0
  52. data/lib/rubocop/cop/rspec/mixin/location_help.rb +37 -0
  53. data/lib/rubocop/cop/rspec/mixin/metadata.rb +21 -7
  54. data/lib/rubocop/cop/rspec/mixin/skip_or_pending.rb +20 -4
  55. data/lib/rubocop/cop/rspec/multiple_expectations.rb +2 -1
  56. data/lib/rubocop/cop/rspec/named_subject.rb +7 -5
  57. data/lib/rubocop/cop/rspec/no_expectation_example.rb +2 -5
  58. data/lib/rubocop/cop/rspec/overwriting_setup.rb +3 -1
  59. data/lib/rubocop/cop/rspec/pending.rb +23 -13
  60. data/lib/rubocop/cop/rspec/pending_without_reason.rb +72 -36
  61. data/lib/rubocop/cop/rspec/predicate_matcher.rb +49 -40
  62. data/lib/rubocop/cop/rspec/rails/have_http_status.rb +11 -6
  63. data/lib/rubocop/cop/rspec/rails/http_status.rb +107 -34
  64. data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +4 -4
  65. data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +60 -0
  66. data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +102 -0
  67. data/lib/rubocop/cop/rspec/rails/travel_around.rb +92 -0
  68. data/lib/rubocop/cop/rspec/receive_counts.rb +1 -1
  69. data/lib/rubocop/cop/rspec/receive_messages.rb +161 -0
  70. data/lib/rubocop/cop/rspec/redundant_around.rb +65 -0
  71. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +3 -6
  72. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +3 -6
  73. data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -4
  74. data/lib/rubocop/cop/rspec/scattered_setup.rb +23 -6
  75. data/lib/rubocop/cop/rspec/shared_context.rb +12 -13
  76. data/lib/rubocop/cop/rspec/shared_examples.rb +6 -4
  77. data/lib/rubocop/cop/rspec/skip_block_inside_example.rb +46 -0
  78. data/lib/rubocop/cop/rspec/sort_metadata.rb +4 -3
  79. data/lib/rubocop/cop/rspec/spec_file_path_format.rb +133 -0
  80. data/lib/rubocop/cop/rspec/spec_file_path_suffix.rb +40 -0
  81. data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -1
  82. data/lib/rubocop/cop/rspec/subject_stub.rb +0 -1
  83. data/lib/rubocop/cop/rspec/variable_definition.rb +5 -2
  84. data/lib/rubocop/cop/rspec/variable_name.rb +4 -1
  85. data/lib/rubocop/cop/rspec/verified_double_reference.rb +7 -7
  86. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -1
  87. data/lib/rubocop/cop/rspec/void_expect.rb +2 -1
  88. data/lib/rubocop/cop/rspec_cops.rb +16 -0
  89. data/lib/rubocop/rspec/config_formatter.rb +16 -0
  90. data/lib/rubocop/rspec/example_group.rb +6 -8
  91. data/lib/rubocop/rspec/language/node_pattern.rb +26 -0
  92. data/lib/rubocop/rspec/language.rb +25 -16
  93. data/lib/rubocop/rspec/version.rb +1 -1
  94. data/lib/rubocop-rspec.rb +4 -5
  95. metadata +50 -8
  96. data/lib/rubocop/cop/rspec/mixin/capybara_help.rb +0 -80
  97. data/lib/rubocop/cop/rspec/mixin/css_selector.rb +0 -146
  98. data/lib/rubocop/rspec/factory_bot/language.rb +0 -37
  99. data/lib/rubocop/rspec/factory_bot.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c31ad963289938a78bf4a8439ad44c6f1a2eaf852a25d715be483ebe71e622fc
4
- data.tar.gz: 70b4e942004dd6654fa12c3ecaf7367c1f6bcf4bcd122573129984f5f0a66ff5
3
+ metadata.gz: c86b897dee5441bce313de34844ccae87313b9a5f8b4d84d3957b2a36d48aa5a
4
+ data.tar.gz: 517269204d37e39e80cb75b75d517e55817c8c13ec6a4574a8ed7d12d85145c6
5
5
  SHA512:
6
- metadata.gz: 250a68082a8e6406df3934035e5ccba4e1a7f9a13e021e196911c15981a2f4557e7b7a98efa93f995ad164d2a52e41bf948f4c1fa7c9637829c3c219c8116f74
7
- data.tar.gz: 7ce965fc56bf214eb65b63d2138cc710766ac16b476a63399271cc5562fb259cefc81cddcf3878f6324faf104d6552e48efcba2eff1fa0865bf463963e5a1a8e
6
+ metadata.gz: aed811c032c6094c898369be38925f59e7cd637de6268f0a5787d123b20505058b1659102bfc571a134983f51cf5984848caf7d7c539bf7816c94a6471f4ae19
7
+ data.tar.gz: cdd65ce7e146cc32035fef6d258fac99a6191b62e57e3e32b89176faa8d9ab6fc44400d37f903e4e71b64515292f8a2734aaa723099d0e5cf2064a29cbbb7032
data/CHANGELOG.md CHANGED
@@ -2,13 +2,120 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.24.1 (2023-09-23)
6
+
7
+ - 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])
8
+
9
+ ## 2.24.0 (2023-09-08)
10
+
11
+ - 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])
12
+ - Add new `RSpec/Eq` cop. ([@ydah])
13
+ - Add `RSpec/MetadataStyle` and `RSpec/EmptyMetadata` cops. ([@r7kamura])
14
+ - Add support `RSpec/Rails/HttpStatus` when `have_http_status` with string argument. ([@ydah])
15
+ - Fix an infinite loop error when `RSpec/ExcessiveDocstringSpacing` finds a description with non-ASCII leading/trailing whitespace. ([@bcgraham])
16
+ - Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when return values declared between stubs. ([@marocchino])
17
+ - Fix a false positive `RSpec/Focus` when chained method call and inside define method. ([@ydah])
18
+
19
+ ## 2.23.2 (2023-08-09)
20
+
21
+ - Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when method is only non-word character. ([@marocchino])
22
+ - Fix a false positive for `RSpec/ReceiveMessages` when return with splat. ([@marocchino])
23
+
24
+ ## 2.23.1 (2023-08-07)
25
+
26
+ - Mark to `Safe: false` for `RSpec/Rails/NegationBeValid` cop. ([@ydah])
27
+ - Declare autocorrect as unsafe for `RSpec/ReceiveMessages`. ([@bquorning])
28
+
29
+ ## 2.23.0 (2023-07-30)
30
+
31
+ - Add new `RSpec/Rails/NegationBeValid` cop. ([@ydah])
32
+ - Fix a false negative for `RSpec/ExcessiveDocstringSpacing` when finds description with em space. ([@ydah])
33
+ - Fix a false positive for `RSpec/EmptyExampleGroup` when example group with examples defined in `if` branch inside iterator. ([@ydah])
34
+ - Update the message output of `RSpec/ExpectActual` to include the word 'value'. ([@corydiamand])
35
+ - Fix a false negative for `RSpec/Pending` when `it` without body. ([@ydah])
36
+ - Add new `RSpec/ReceiveMessages` cop. ([@ydah])
37
+ - Change default.yml path to use `**/spec/*` instead of `spec/*`. ([@ydah])
38
+ - Add `AllowedIdentifiers` and `AllowedPatterns` configuration option to `RSpec/IndexedLet`. ([@ydah])
39
+ - Fix `RSpec/NamedSubject` when block has no body. ([@splattael])
40
+ - Fix `RSpec/LetBeforeExamples` autocorrect incompatible with `RSpec/ScatteredLet` autocorrect. ([@ydah])
41
+ - Update `RSpec/Focus` to support `shared_context` and `shared_examples`. ([@tmaier])
42
+
43
+ ## 2.22.0 (2023-05-06)
44
+
45
+ - 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])
46
+
47
+ ## 2.21.0 (2023-05-05)
48
+
49
+ - Fix a false positive in `RSpec/IndexedLet` with suffixes after index-like numbers. ([@pirj])
50
+ - Fix an error for `RSpec/Rails/HaveHttpStatus` with comparison with strings containing non-numeric characters. ([@ydah])
51
+ - Fix an error for `RSpec/MatchArray` when `match_array` with no argument. ([@ydah])
52
+ - Add support `a_block_changing` and `changing` for `RSpec/ChangeByZero`. ([@ydah])
53
+ - Drop Ruby 2.6 support. ([@ydah])
54
+
55
+ ## 2.20.0 (2023-04-18)
56
+
57
+ - Add new `RSpec/IndexedLet` cop. ([@dmitrytsepelev])
58
+ - Add new `RSpec/BeEmpty` cop. ([@ydah], [@bquorning])
59
+ - Add autocorrect support for `RSpec/ScatteredSetup`. ([@ydah])
60
+ - Add support `be_status` style for `RSpec/Rails/HttpStatus`. ([@ydah])
61
+ - Add support for shared example groups to `RSpec/EmptyLineAfterExampleGroup`. ([@pirj])
62
+ - Add support for `RSpec/HaveHttpStatus` when using `response.code`. ([@ydah])
63
+ - Fix order of expected and actual in correction for `RSpec/Rails/MinitestAssertions`. ([@mvz])
64
+ - Fix a false positive for `RSpec/DescribedClassModuleWrapping` when RSpec.describe numblock is nested within a module. ([@ydah])
65
+ - Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` inside `&&`, `||` and `:?` when `omit_parentheses` is on. ([@dmitrytsepelev])
66
+ - Fix a false positive for `RSpec/PendingWithoutReason` when pending/skip has a reason inside an example group. ([@ydah])
67
+ - Fix a false negative for `RSpec/RedundantAround` when redundant numblock `around`. ([@ydah])
68
+ - Change `RSpec/ContainExactly` to ignore calls with no arguments, and change `RSpec/MatchArray` to ignore calls with an empty array literal argument. ([@ydah], [@bquorning])
69
+ - Make `RSpec/MatchArray` and `RSpec/ContainExactly` pending. ([@ydah])
70
+
71
+ ## 2.19.0 (2023-03-06)
72
+
73
+ - Fix a false positive for `RSpec/ContextWording` when context is interpolated string literal or execute string. ([@ydah])
74
+ - Fix a false positive for `RSpec/DescribeMethod` when multi-line describe without `#` and `.` at the beginning. ([@ydah], [@pirj])
75
+ - Fix a false positive for `RSpec/VariableName` when inside non-spec code. ([@ydah])
76
+ - Fix a false positive for `RSpec/VariableDefinition` when inside non-spec code. ([@ydah])
77
+ - Add new `RSpec/PendingBlockInsideExample` cop. ([@ydah])
78
+ - Add `RSpec/RedundantAround` cop. ([@r7kamura])
79
+ - Add `RSpec/Rails/TravelAround` cop. ([@r7kamura])
80
+ - Add `RSpec/ContainExactly` and `RSpec/MatchArray` cops. ([@faucct])
81
+ - Fix a false positive for `RSpec/PendingWithoutReason` when not inside example and pending/skip with block. ([@ydah], [@pirj])
82
+ - Fix a false positive for `RSpec/PendingWithoutReason` when `skip` is passed a block inside example. ([@ydah], [@pirj])
83
+ - Rename `RSpec/PendingBlockInsideExample` cop to `RSpec/SkipBlockInsideExample`. ([@pirj])
84
+ - Deprecate `send_pattern`/`block_pattern`/`numblock_pattern` helpers in favour of using node pattern explicitly. ([@pirj], [@ydah])
85
+ - Fix an incorrect autocorrect for `RSpec/VerifiedDoubleReference` when namespaced class. ([@ydah])
86
+
87
+ ## 2.18.1 (2023-01-19)
88
+
89
+ - Add `rubocop-capybara` version constraint to prevent sudden cop enabling when it hits 3.0. ([@pirj])
90
+
91
+ ## 2.18.0 (2023-01-16)
92
+
93
+ - Extract Capybara cops to a separate repository, [`rubocop-capybara`](https://github.com/rubocop/rubocop-capybara). The `rubocop-capybara` repository is a dependency of `rubocop-rspec` and the Capybara cops are aliased (`RSpec/Capybara/Foo` == `Capybara/Foo`) until v3.0 is released, so the change will be invisible to users until then. ([@pirj])
94
+
95
+ ## 2.17.1 (2023-01-16)
96
+
97
+ - Fix a false negative for `RSpec/Pending` when using skipped in metadata is multiline string. ([@ydah])
98
+ - Fix a false positive for `RSpec/NoExpectationExample` when using skipped in metadata is multiline string. ([@ydah])
99
+ - Fix a false positive for `RSpec/ContextMethod` when multi-line context with `#` at the beginning. ([@ydah])
100
+ - Fix an incorrect autocorrect for `RSpec/PredicateMatcher` when multiline expect and predicate method with heredoc. ([@ydah])
101
+ - Fix a false positive for `RSpec/PredicateMatcher` when `include` with multiple argument. ([@ydah])
102
+
103
+ ## 2.17.0 (2023-01-13)
104
+
105
+ - Fix a false positive for `RSpec/PendingWithoutReason` when pending/skip is argument of methods. ([@ydah])
106
+ - Add new `RSpec/Capybara/MatchStyle` cop. ([@ydah])
107
+ - Add new `RSpec/Rails/MinitestAssertions` cop. ([@ydah])
108
+ - Fix a false positive for `RSpec/PendingWithoutReason` when not inside example. ([@ydah])
109
+ - Fix a false negative for `RSpec/PredicateMatcher` when using `include` and `respond_to`. ([@ydah])
110
+ - Fix a false positive for `RSpec/StubbedMock` when stubbed message expectation with a block and block parameter. ([@ydah])
111
+
5
112
  ## 2.16.0 (2022-12-13)
6
113
 
7
114
  - Add new `RSpec/FactoryBot/FactoryNameStyle` cop. ([@ydah])
8
115
  - Improved processing speed for `RSpec/Be`, `RSpec/ExpectActual`, `RSpec/ImplicitExpect`, `RSpec/MessageSpies`, `RSpec/PredicateMatcher` and `RSpec/Rails/HaveHttpStatus`. ([@ydah])
9
116
  - Fix wrong autocorrection in `n_times` style on `RSpec/FactoryBot/CreateList`. ([@r7kamura])
10
117
  - Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` when using `generate` with multiple arguments. ([@ydah])
11
- - Mark `RSpec/BeEq` as `Safe: false` ([@r7kamura])
118
+ - Mark `RSpec/BeEq` as `Safe: false`. ([@r7kamura])
12
119
  - Add `RSpec/DuplicatedMetadata` cop. ([@r7kamura])
13
120
  - Mark `RSpec/BeEql` as `Safe: false`. ([@r7kamura])
14
121
  - Add `RSpec/PendingWithoutReason` cop. ([@r7kamura])
@@ -41,8 +148,8 @@
41
148
  - Fix a false positive for `RSpec/Capybara/SpecificMatcher` when `have_css("a")` without attribute. ([@ydah])
42
149
  - Update `RSpec/ExampleWording` cop to raise error for insufficient descriptions. ([@akrox58])
43
150
  - Add new `RSpec/Capybara/NegationMatcher` cop. ([@ydah])
44
- - Add `AllowedPatterns` configuration option to `RSpec/NoExpectationExample`. ([@ydah])
45
- - Improve `RSpec/NoExpectationExample` cop to ignore examples skipped or pending via metadata. ([@pirj])
151
+ - Add `AllowedPatterns` configuration option to `RSpec/NoExpectationExample`. ([@ydah])
152
+ - Improve `RSpec/NoExpectationExample` cop to ignore examples skipped or pending via metadata. ([@pirj])
46
153
  - Add `RSpec/FactoryBot/ConsistentParenthesesStyle` cop. ([@Liberatys])
47
154
  - Add `RSpec/Rails/InferredSpecType` cop. ([@r7kamura])
48
155
  - Add new `RSpec/Capybara/SpecificActions` cop. ([@ydah])
@@ -288,7 +395,7 @@
288
395
  ## 1.37.0 (2019-11-25)
289
396
 
290
397
  - Implement `RSpec/DescribedClassModuleWrapping` to disallow RSpec statements within a module. ([@kellysutton])
291
- - Fix documentation rake task to support Rubocop 0.75. ([@nickcampbell18])
398
+ - Fix documentation rake task to support RuboCop 0.75. ([@nickcampbell18])
292
399
  - Fix `RSpec/SubjectStub` to detect implicit subjects stubbed. ([@QQism])
293
400
  - Fix `RSpec/Pending` not flagging `skip` with string values. ([@pirj])
294
401
  - Add `AllowedExplicitMatchers` config option for `RSpec/PredicateMatcher`. ([@mkrawc])
@@ -358,7 +465,7 @@
358
465
  - Add config to `RSpec/VerifiedDoubles` to enforcement of verification on unnamed doubles. ([@BrentWheeldon])
359
466
  - Fix `FactoryBot/AttributeDefinedStatically` not working when there is a non-symbol key. ([@vzvu3k6k])
360
467
  - Fix false positive in `RSpec/ImplicitSubject` when `is_expected` is used inside `its()` block. ([@Darhazer])
361
- - Add `single_statement_only` style to `RSpec/ImplicitSubject` as a more relaxed alternative to `single_line_only`. ([@Darhazer])
468
+ - Add `single_statement_only` style to `RSpec/ImplicitSubject` as a more relaxed alternative to `single_line_only`. ([@Darhazer])
362
469
  - Add `RSpec/UnspecifiedException` as a default cop to encourage more-specific `expect{}.to raise_error(ExceptionType)`, or `raise_exception` style handling of exceptions. ([@daveworth])
363
470
 
364
471
  ## 1.29.1 (2018-09-01)
@@ -393,14 +500,14 @@
393
500
 
394
501
  ## 1.26.0 (2018-06-06)
395
502
 
396
- - Fix false positive in `RSpec/EmptyExampleGroup` cop when methods named like a RSpec method are used. ([@Darhazer])
503
+ - Fix false positive in `RSpec/EmptyExampleGroup` cop when methods named like a RSpec method are used. ([@Darhazer])
397
504
  - Fix `Capybara/FeatureMethods` not working when there is require before the spec. ([@Darhazer])
398
505
  - Fix `RSpec/EmptyLineAfterFinalLet`: allow a comment to be placed after latest let, requiring empty line after the comment. ([@Darhazer])
399
506
  - Add `RSpec/ReceiveCounts` cop to enforce usage of :once and :twice matchers. ([@Darhazer])
400
507
 
401
508
  ## 1.25.1 (2018-04-10)
402
509
 
403
- - Fix false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer])
510
+ - Fix false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer])
404
511
  - Fix `FactoryBot/DynamicAttributeDefinedStatically` false positive when using symbol proc argument for a sequence. ([@tdeo])
405
512
 
406
513
  ## 1.25.0 (2018-04-07)
@@ -408,7 +515,7 @@
408
515
  - Add `RSpec/SharedExamples` cop to enforce consistent usage of string to titleize shared examples. ([@anthony-robin])
409
516
  - Add `RSpec/Be` cop to enforce passing argument to the generic `be` matcher. ([@Darhazer])
410
517
  - Fix false positives in `StaticAttributeDefinedDynamically` and `ReturnFromStub` when a const is used in an array or hash. ([@Darhazer])
411
- - Add `RSpec/Pending` cop to enforce no existing pending or skipped examples. This is disabled by default. ([@patrickomatic])
518
+ - Add `RSpec/Pending` cop to enforce no existing pending or skipped examples. This is disabled by default. ([@patrickomatic])
412
519
  - Fix `RSpec/NestedGroups` cop support --auto-gen-config. ([@walf443])
413
520
  - Fix false positives in `Capybara/FeatureMethods` when feature methods are used as property names in a factory. ([@Darhazer])
414
521
  - Allow configuring enabled methods in `Capybara/FeatureMethods`. ([@Darhazer])
@@ -619,7 +726,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
619
726
  - Skip `DescribeClass` cop for view specs. ([@andyw8])
620
727
  - Skip `FilePath` cop for Rails routing specs. ([@andyw8])
621
728
  - Add cop to check for focused specs. ([@renanborgescampos], [@jaredmoody])
622
- - Clean-up `RSpec::NotToNot` to use same configuration semantics as other Rubocop cops, add autocorrect support for `RSpec::NotToNot`. ([@baberthal])
729
+ - Clean-up `RSpec::NotToNot` to use same configuration semantics as other RuboCop cops, add autocorrect support for `RSpec::NotToNot`. ([@baberthal])
623
730
  - Update to rubocop 0.40.0. ([@nijikon])
624
731
 
625
732
  ## 1.4.1 (2016-04-03)
@@ -704,6 +811,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
704
811
  [@aried3r]: https://github.com/aried3r
705
812
  [@baberthal]: https://github.com/baberthal
706
813
  [@backus]: https://github.com/backus
814
+ [@bcgraham]: https://github.com/bcgraham
707
815
  [@biinari]: https://github.com/biinari
708
816
  [@bmorrall]: https://github.com/bmorrall
709
817
  [@bquorning]: https://github.com/bquorning
@@ -712,11 +820,13 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
712
820
  [@cfabianski]: https://github.com/cfabianski
713
821
  [@clupprich]: https://github.com/clupprich
714
822
  [@composerinteralia]: https://github.com/composerinteralia
823
+ [@corydiamand]: https://github.com/corydiamand
715
824
  [@darhazer]: https://github.com/Darhazer
716
825
  [@daveworth]: https://github.com/daveworth
717
826
  [@dduugg]: https://github.com/dduugg
718
827
  [@deivid-rodriguez]: https://github.com/deivid-rodriguez
719
828
  [@dgollahon]: https://github.com/dgollahon
829
+ [@dmitrytsepelev]: https://github.com/dmitrytsepelev
720
830
  [@drowze]: https://github.com/Drowze
721
831
  [@dswij]: https://github.com/dswij
722
832
  [@dvandersluis]: https://github.com/dvandersluis
@@ -726,6 +836,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
726
836
  [@elebow]: https://github.com/elebow
727
837
  [@elisefitz15]: https://github.com/EliseFitz15
728
838
  [@elliterate]: https://github.com/elliterate
839
+ [@faucct]: https://github.com/faucct
729
840
  [@foton]: https://github.com/foton
730
841
  [@francois-ferrandis]: https://github.com/francois-ferrandis
731
842
  [@g-rath]: https://github.com/G-Rath
@@ -752,12 +863,14 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
752
863
  [@lokhi]: https://github.com/lokhi
753
864
  [@luke-hill]: https://github.com/luke-hill
754
865
  [@m-yamashita01]: https://github.com/M-Yamashita01
866
+ [@marocchino]: https://github.com/marocchino
755
867
  [@miguelfteixeira]: https://github.com/miguelfteixeira
756
868
  [@mkenyon]: https://github.com/mkenyon
757
869
  [@mkrawc]: https://github.com/mkrawc
758
870
  [@mlarraz]: https://github.com/mlarraz
759
871
  [@mockdeep]: https://github.com/mockdeep
760
872
  [@mothonmars]: https://github.com/MothOnMars
873
+ [@mvz]: https://github.com/mvz
761
874
  [@nc-holodakg]: https://github.com/nc-holodakg
762
875
  [@nevir]: https://github.com/nevir
763
876
  [@ngouy]: https://github.com/ngouy
@@ -787,6 +900,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
787
900
  [@seanpdoyle]: https://github.com/seanpdoyle
788
901
  [@sl4vr]: https://github.com/sl4vr
789
902
  [@smcgivern]: https://github.com/smcgivern
903
+ [@splattael]: https://github.com/splattael
790
904
  [@stephannv]: https://github.com/stephannv
791
905
  [@t3h2mas]: https://github.com/t3h2mas
792
906
  [@tdeo]: https://github.com/tdeo
@@ -794,6 +908,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
794
908
  [@telmofcosta]: https://github.com/telmofcosta
795
909
  [@tietew]: https://github.com/Tietew
796
910
  [@timrogers]: https://github.com/timrogers
911
+ [@tmaier]: https://github.com/tmaier
797
912
  [@topalovic]: https://github.com/topalovic
798
913
  [@twalpole]: https://github.com/twalpole
799
914
  [@vzvu3k6k]: https://github.com/vzvu3k6k
data/README.md CHANGED
@@ -2,9 +2,9 @@
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
- ![CI](https://github.com/rubocop-hq/rubocop-rspec/workflows/CI/badge.svg)
5
+ ![CI](https://github.com/rubocop/rubocop-rspec/workflows/CI/badge.svg)
6
6
 
7
- RSpec-specific analysis for your projects, as an extension to
7
+ [RSpec](https://rspec.info/)-specific analysis for your projects, as an extension to
8
8
  [RuboCop](https://github.com/rubocop/rubocop).
9
9
 
10
10
  ## Installation
@@ -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
@@ -144,6 +144,12 @@ RSpec/Be:
144
144
  StyleGuide: https://rspec.rubystyle.guide/#be-matcher
145
145
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Be
146
146
 
147
+ RSpec/BeEmpty:
148
+ Description: Prefer using `be_empty` when checking for an empty array.
149
+ Enabled: pending
150
+ VersionAdded: '2.20'
151
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEmpty
152
+
147
153
  RSpec/BeEq:
148
154
  Description: Check for expectations where `be(...)` can replace `eq(...)`.
149
155
  Enabled: pending
@@ -175,10 +181,11 @@ RSpec/BeforeAfterAll:
175
181
  Description: Check that before/after(:all) isn't being used.
176
182
  Enabled: true
177
183
  Exclude:
178
- - spec/spec_helper.rb
179
- - spec/rails_helper.rb
180
- - spec/support/**/*.rb
184
+ - "**/spec/spec_helper.rb"
185
+ - "**/spec/rails_helper.rb"
186
+ - "**/spec/support/**/*.rb"
181
187
  VersionAdded: '1.12'
188
+ VersionChanged: '2.23'
182
189
  StyleGuide: https://rspec.rubystyle.guide/#avoid-hooks-with-context-scope
183
190
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
184
191
 
@@ -201,6 +208,12 @@ RSpec/ClassCheck:
201
208
  - be_kind_of
202
209
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ClassCheck
203
210
 
211
+ RSpec/ContainExactly:
212
+ Description: Checks where `contain_exactly` is used.
213
+ Enabled: pending
214
+ VersionAdded: '2.19'
215
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContainExactly
216
+
204
217
  RSpec/ContextMethod:
205
218
  Description: "`context` should not be used for specifying methods."
206
219
  Enabled: true
@@ -346,6 +359,18 @@ RSpec/EmptyLineAfterSubject:
346
359
  StyleGuide: https://rspec.rubystyle.guide/#empty-line-after-let
347
360
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterSubject
348
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
+
349
374
  RSpec/ExampleLength:
350
375
  Description: Checks for long examples.
351
376
  Enabled: true
@@ -392,8 +417,9 @@ RSpec/ExpectActual:
392
417
  Description: Checks for `expect(...)` calls containing literal values.
393
418
  Enabled: true
394
419
  Exclude:
395
- - spec/routing/**/*
420
+ - "**/spec/routing/**/*"
396
421
  VersionAdded: '1.7'
422
+ VersionChanged: '2.23'
397
423
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectActual
398
424
 
399
425
  RSpec/ExpectChange:
@@ -432,7 +458,7 @@ RSpec/FilePath:
432
458
  IgnoreMethods: false
433
459
  SpecSuffixOnly: false
434
460
  VersionAdded: '1.2'
435
- VersionChanged: '1.40'
461
+ VersionChanged: '2.24'
436
462
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FilePath
437
463
 
438
464
  RSpec/Focus:
@@ -497,6 +523,16 @@ RSpec/ImplicitSubject:
497
523
  VersionChanged: '2.13'
498
524
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitSubject
499
525
 
526
+ RSpec/IndexedLet:
527
+ Description: Do not set up test data using indexes (e.g., `item_1`, `item_2`).
528
+ Enabled: pending
529
+ VersionAdded: '2.20'
530
+ VersionChanged: '2.23'
531
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IndexedLet
532
+ Max: 1
533
+ AllowedIdentifiers: []
534
+ AllowedPatterns: []
535
+
500
536
  RSpec/InstanceSpy:
501
537
  Description: Checks for `instance_double` used with `have_received`.
502
538
  Enabled: true
@@ -556,6 +592,12 @@ RSpec/LetSetup:
556
592
  VersionAdded: '1.7'
557
593
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetSetup
558
594
 
595
+ RSpec/MatchArray:
596
+ Description: Checks where `match_array` is used.
597
+ Enabled: pending
598
+ VersionAdded: '2.19'
599
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MatchArray
600
+
559
601
  RSpec/MessageChain:
560
602
  Description: Check that chains of messages are not being stubbed.
561
603
  Enabled: true
@@ -583,6 +625,16 @@ RSpec/MessageSpies:
583
625
  VersionAdded: '1.9'
584
626
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageSpies
585
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
+
586
638
  RSpec/MissingExampleGroupArgument:
587
639
  Description: Checks that the first argument to an example group is not empty.
588
640
  Enabled: true
@@ -700,12 +752,25 @@ RSpec/ReceiveCounts:
700
752
  VersionAdded: '1.26'
701
753
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveCounts
702
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
+
703
762
  RSpec/ReceiveNever:
704
763
  Description: Prefer `not_to receive(...)` over `receive(...).never`.
705
764
  Enabled: true
706
765
  VersionAdded: '1.28'
707
766
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveNever
708
767
 
768
+ RSpec/RedundantAround:
769
+ Description: Remove redundant `around` hook.
770
+ Enabled: pending
771
+ VersionAdded: '2.19'
772
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RedundantAround
773
+
709
774
  RSpec/RepeatedDescription:
710
775
  Description: Check for repeated description strings in example groups.
711
776
  Enabled: true
@@ -779,12 +844,43 @@ RSpec/SingleArgumentMessageChain:
779
844
  VersionChanged: '1.10'
780
845
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SingleArgumentMessageChain
781
846
 
847
+ RSpec/SkipBlockInsideExample:
848
+ Description: Checks for passing a block to `skip` within examples.
849
+ Enabled: pending
850
+ VersionAdded: '2.19'
851
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SkipBlockInsideExample
852
+
782
853
  RSpec/SortMetadata:
783
854
  Description: Sort RSpec metadata alphabetically.
784
855
  Enabled: pending
785
856
  VersionAdded: '2.14'
786
857
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SortMetadata
787
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
+
788
884
  RSpec/StubbedMock:
789
885
  Description: Checks that message expectations do not have a configured response.
790
886
  Enabled: true
@@ -887,6 +983,12 @@ RSpec/Capybara/FeatureMethods:
887
983
  VersionChanged: '2.0'
888
984
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
889
985
 
986
+ RSpec/Capybara/MatchStyle:
987
+ Description: Checks for usage of deprecated style methods.
988
+ Enabled: pending
989
+ VersionAdded: '2.17'
990
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/MatchStyle
991
+
890
992
  RSpec/Capybara/NegationMatcher:
891
993
  Description: Enforces use of `have_no_*` or `not_to` for negated expectations.
892
994
  Enabled: pending
@@ -931,11 +1033,11 @@ RSpec/FactoryBot/AttributeDefinedStatically:
931
1033
  Description: Always declare attribute values as blocks.
932
1034
  Enabled: true
933
1035
  Include:
934
- - spec/factories.rb
935
- - spec/factories/**/*.rb
936
- - features/support/factories/**/*.rb
1036
+ - "**/spec/factories.rb"
1037
+ - "**/spec/factories/**/*.rb"
1038
+ - "**/features/support/factories/**/*.rb"
937
1039
  VersionAdded: '1.28'
938
- VersionChanged: '2.0'
1040
+ VersionChanged: '2.23'
939
1041
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/AttributeDefinedStatically
940
1042
 
941
1043
  RSpec/FactoryBot/ConsistentParenthesesStyle:
@@ -954,26 +1056,26 @@ RSpec/FactoryBot/CreateList:
954
1056
  Include:
955
1057
  - "**/*_spec.rb"
956
1058
  - "**/spec/**/*"
957
- - spec/factories.rb
958
- - spec/factories/**/*.rb
959
- - features/support/factories/**/*.rb
1059
+ - "**/spec/factories.rb"
1060
+ - "**/spec/factories/**/*.rb"
1061
+ - "**/features/support/factories/**/*.rb"
960
1062
  EnforcedStyle: create_list
961
1063
  SupportedStyles:
962
1064
  - create_list
963
1065
  - n_times
964
1066
  VersionAdded: '1.25'
965
- VersionChanged: '2.0'
1067
+ VersionChanged: '2.23'
966
1068
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/CreateList
967
1069
 
968
1070
  RSpec/FactoryBot/FactoryClassName:
969
1071
  Description: Use string value when setting the class attribute explicitly.
970
1072
  Enabled: true
971
1073
  Include:
972
- - spec/factories.rb
973
- - spec/factories/**/*.rb
974
- - features/support/factories/**/*.rb
1074
+ - "**/spec/factories.rb"
1075
+ - "**/spec/factories/**/*.rb"
1076
+ - "**/features/support/factories/**/*.rb"
975
1077
  VersionAdded: '1.37'
976
- VersionChanged: '2.0'
1078
+ VersionChanged: '2.23'
977
1079
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName
978
1080
 
979
1081
  RSpec/FactoryBot/FactoryNameStyle:
@@ -1018,8 +1120,9 @@ RSpec/Rails/HttpStatus:
1018
1120
  SupportedStyles:
1019
1121
  - numeric
1020
1122
  - symbolic
1123
+ - be_status
1021
1124
  VersionAdded: '1.23'
1022
- VersionChanged: '2.0'
1125
+ VersionChanged: '2.20'
1023
1126
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus
1024
1127
 
1025
1128
  RSpec/Rails/InferredSpecType:
@@ -1044,3 +1147,27 @@ RSpec/Rails/InferredSpecType:
1044
1147
  routing: routing
1045
1148
  system: system
1046
1149
  views: view
1150
+
1151
+ RSpec/Rails/MinitestAssertions:
1152
+ Description: Check if using Minitest matchers.
1153
+ Enabled: pending
1154
+ VersionAdded: '2.17'
1155
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/MinitestAssertions
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
+
1168
+ RSpec/Rails/TravelAround:
1169
+ Description: Prefer to travel in `before` rather than `around`.
1170
+ Enabled: pending
1171
+ Safe: false
1172
+ VersionAdded: '2.19'
1173
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/TravelAround
@@ -12,3 +12,18 @@ changed_parameters:
12
12
  parameters: IgnoredPatterns
13
13
  alternative: AllowedPatterns
14
14
  severity: warning
15
+
16
+ renamed:
17
+ RSpec/Capybara/CurrentPathExpectation: Capybara/CurrentPathExpectation
18
+ RSpec/Capybara/MatchStyle: Capybara/MatchStyle
19
+ RSpec/Capybara/NegationMatcher: Capybara/NegationMatcher
20
+ RSpec/Capybara/SpecificActions: Capybara/SpecificActions
21
+ RSpec/Capybara/SpecificFinders: Capybara/SpecificFinders
22
+ RSpec/Capybara/SpecificMatcher: Capybara/SpecificMatcher
23
+ RSpec/Capybara/VisibilityMatcher: Capybara/VisibilityMatcher
24
+ RSpec/FactoryBot/AttributeDefinedStatically: FactoryBot/AttributeDefinedStatically
25
+ RSpec/FactoryBot/ConsistentParenthesesStyle: FactoryBot/ConsistentParenthesesStyle
26
+ RSpec/FactoryBot/CreateList: FactoryBot/CreateList
27
+ RSpec/FactoryBot/FactoryClassName: FactoryBot/FactoryClassName
28
+ RSpec/FactoryBot/FactoryNameStyle: FactoryBot/FactoryNameStyle
29
+ RSpec/FactoryBot/SyntaxMethods: FactoryBot/SyntaxMethods
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Prefer using `be_empty` when checking for an empty array.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # expect(array).to contain_exactly
11
+ # expect(array).to match_array([])
12
+ #
13
+ # # good
14
+ # expect(array).to be_empty
15
+ #
16
+ class BeEmpty < Base
17
+ extend AutoCorrector
18
+
19
+ MSG = 'Use `be_empty` matchers for checking an empty array.'
20
+ RESTRICT_ON_SEND = %i[contain_exactly match_array].freeze
21
+
22
+ # @!method expect_array_matcher?(node)
23
+ def_node_matcher :expect_array_matcher?, <<~PATTERN
24
+ (send
25
+ (send nil? :expect _)
26
+ #Runners.all
27
+ ${
28
+ (send nil? :match_array (array))
29
+ (send nil? :contain_exactly)
30
+ }
31
+ )
32
+ PATTERN
33
+
34
+ def on_send(node)
35
+ expect_array_matcher?(node.parent) do |expect|
36
+ add_offense(expect) do |corrector|
37
+ corrector.replace(expect, 'be_empty')
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -57,7 +57,7 @@ module RuboCop
57
57
  return unless be_nil_matcher?(node)
58
58
 
59
59
  add_offense(node, message: BE_MSG) do |corrector|
60
- corrector.replace(node.loc.expression, 'be(nil)')
60
+ corrector.replace(node, 'be(nil)')
61
61
  end
62
62
  end
63
63
 
@@ -65,7 +65,7 @@ module RuboCop
65
65
  return unless nil_value_expectation?(node)
66
66
 
67
67
  add_offense(node, message: BE_NIL_MSG) do |corrector|
68
- corrector.replace(node.loc.expression, 'be_nil')
68
+ corrector.replace(node, 'be_nil')
69
69
  end
70
70
  end
71
71
  end