diff --git a/.rubocop.yml b/.rubocop.yml index 6fb427aef..6f7695352 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -250,8 +250,3 @@ Style/StringChars: {Enabled: true} Style/SuperWithArgsParentheses: {Enabled: true} Style/SwapValues: {Enabled: true} Style/YAMLFileRead: {Enabled: true} - -# Enable our own pending cops. -# -RSpec/StringAsInstanceDoubleConstant: - Enabled: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 41551a09d..4073488f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fix `RSpec/VoidExpect` to only operate inside an example block. ([@corsonknowles]) - Change `RSpec/ContextWording` cop to always report an offense when both `Prefixes` and `AllowedPatterns` are empty. ([@ydah]) - Add support for `and` and `or` compound matchers to `RSpec/ChangeByZero` cop. ([@ydah]) +- Replace `RSpec/StringAsInstanceDoubleConstant` with `RSpecVerifiedDoubleReference` configured to only support constant class references. ([@corsonknowles]) ## 3.1.0 (2024-10-01) diff --git a/config/default.yml b/config/default.yml index 6c09b7d72..a3bb9f216 100644 --- a/config/default.yml +++ b/config/default.yml @@ -930,13 +930,6 @@ RSpec/SpecFilePathSuffix: - "**/spec/**/*" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathSuffix -RSpec/StringAsInstanceDoubleConstant: - Description: Do not use a string as `instance_double` constant. - Enabled: pending - Safe: false - VersionAdded: '3.1' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StringAsInstanceDoubleConstant - RSpec/StubbedMock: Description: Checks that message expectations do not have a configured response. Enabled: true @@ -995,12 +988,8 @@ RSpec/VerifiedDoubleReference: Description: Checks for consistent verified double reference style. Enabled: true SafeAutoCorrect: false - EnforcedStyle: constant - SupportedStyles: - - constant - - string VersionAdded: 2.10.0 - VersionChanged: '2.12' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubleReference RSpec/VerifiedDoubles: diff --git a/config/obsoletion.yml b/config/obsoletion.yml index 530bd0ed4..40c6628d4 100644 --- a/config/obsoletion.yml +++ b/config/obsoletion.yml @@ -28,3 +28,6 @@ extracted: RSpec/Rails/*: rubocop-rspec_rails RSpec/FactoryBot/*: rubocop-factory_bot RSpec/Capybara/*: rubocop-capybara + +renamed: + RSpec/StringAsInstanceDoubleConstant: RSpec/VerifiedDoubleReference diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 116d2a714..16ddf0fd6 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -101,7 +101,6 @@ * xref:cops_rspec.adoc#rspecsortmetadata[RSpec/SortMetadata] * xref:cops_rspec.adoc#rspecspecfilepathformat[RSpec/SpecFilePathFormat] * xref:cops_rspec.adoc#rspecspecfilepathsuffix[RSpec/SpecFilePathSuffix] -* xref:cops_rspec.adoc#rspecstringasinstancedoubleconstant[RSpec/StringAsInstanceDoubleConstant] * xref:cops_rspec.adoc#rspecstubbedmock[RSpec/StubbedMock] * xref:cops_rspec.adoc#rspecsubjectdeclaration[RSpec/SubjectDeclaration] * xref:cops_rspec.adoc#rspecsubjectstub[RSpec/SubjectStub] diff --git a/docs/modules/ROOT/pages/cops_rspec.adoc b/docs/modules/ROOT/pages/cops_rspec.adoc index 20015bc0a..d06a33fbf 100644 --- a/docs/modules/ROOT/pages/cops_rspec.adoc +++ b/docs/modules/ROOT/pages/cops_rspec.adoc @@ -6,7 +6,6 @@ = RSpec -[#rspecalignleftletbrace] == RSpec/AlignLeftLetBrace |=== @@ -21,7 +20,6 @@ Checks that left braces for adjacent single line lets are aligned. -[#examples-rspecalignleftletbrace] === Examples [source,ruby] @@ -37,12 +35,10 @@ let(:baz) { bar } let(:a) { b } ---- -[#references-rspecalignleftletbrace] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignLeftLetBrace -[#rspecalignrightletbrace] == RSpec/AlignRightLetBrace |=== @@ -57,7 +53,6 @@ let(:a) { b } Checks that right braces for adjacent single line lets are aligned. -[#examples-rspecalignrightletbrace] === Examples [source,ruby] @@ -73,12 +68,10 @@ let(:baz) { bar } let(:a) { b } ---- -[#references-rspecalignrightletbrace] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignRightLetBrace -[#rspecanyinstance] == RSpec/AnyInstance |=== @@ -95,7 +88,6 @@ Check that instances are not being stubbed globally. Prefer instance doubles over stubbing any instance of a class -[#examples-rspecanyinstance] === Examples [source,ruby] @@ -116,13 +108,11 @@ describe MyClass do end ---- -[#references-rspecanyinstance] === References * https://rspec.rubystyle.guide/#any_instance_of * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AnyInstance -[#rspecaroundblock] == RSpec/AroundBlock |=== @@ -137,7 +127,6 @@ end Checks that around blocks actually run the test. -[#examples-rspecaroundblock] === Examples [source,ruby] @@ -163,12 +152,10 @@ around do |test| end ---- -[#references-rspecaroundblock] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AroundBlock -[#rspecbe] == RSpec/Be |=== @@ -187,7 +174,6 @@ The `be` matcher is too generic, as it pass on everything that is not nil or false. If that is the exact intend, use `be_truthy`. In all other cases it's better to specify what exactly is the expected value. -[#examples-rspecbe] === Examples [source,ruby] @@ -201,13 +187,11 @@ expect(foo).to be 1.0 expect(foo).to be(true) ---- -[#references-rspecbe] === References * https://rspec.rubystyle.guide/#be-matcher * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Be -[#rspecbeempty] == RSpec/BeEmpty |=== @@ -222,7 +206,6 @@ expect(foo).to be(true) Prefer using `be_empty` when checking for an empty array. -[#examples-rspecbeempty] === Examples [source,ruby] @@ -235,12 +218,10 @@ expect(array).to match_array([]) expect(array).to be_empty ---- -[#references-rspecbeempty] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEmpty -[#rspecbeeq] == RSpec/BeEq |=== @@ -259,12 +240,10 @@ The `be` matcher compares by identity while the `eq` matcher compares using `==`. Booleans and nil can be compared by identity and therefore the `be` matcher is preferable as it is a more strict test. -[#safety-rspecbeeq] === Safety This cop is unsafe because it changes how values are compared. -[#examples-rspecbeeq] === Examples [source,ruby] @@ -280,12 +259,10 @@ expect(foo).to be(false) expect(foo).to be(nil) ---- -[#references-rspecbeeq] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEq -[#rspecbeeql] == RSpec/BeEql |=== @@ -312,12 +289,10 @@ than `!equal?`. We also do not try to flag `eq` because if necessarily the same type as `b` since the `#==` operator can coerce objects for comparison. -[#safety-rspecbeeql] === Safety This cop is unsafe because it changes how values are compared. -[#examples-rspecbeeql] === Examples [source,ruby] @@ -339,12 +314,10 @@ expect(foo).to be(:bar) expect(foo).to be(nil) ---- -[#references-rspecbeeql] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEql -[#rspecbenil] == RSpec/BeNil |=== @@ -364,10 +337,8 @@ generic `be` matcher with a `nil` argument. This cop can be configured using the `EnforcedStyle` option -[#examples-rspecbenil] === Examples -[#_enforcedstyle_-be_nil_-_default_-rspecbenil] ==== `EnforcedStyle: be_nil` (default) [source,ruby] @@ -379,7 +350,6 @@ expect(foo).to be(nil) expect(foo).to be_nil ---- -[#_enforcedstyle_-be_-rspecbenil] ==== `EnforcedStyle: be` [source,ruby] @@ -391,7 +361,6 @@ expect(foo).to be_nil expect(foo).to be(nil) ---- -[#configurable-attributes-rspecbenil] === Configurable attributes |=== @@ -402,12 +371,10 @@ expect(foo).to be(nil) | `be`, `be_nil` |=== -[#references-rspecbenil] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeNil -[#rspecbeforeafterall] == RSpec/BeforeAfterAll |=== @@ -422,7 +389,6 @@ expect(foo).to be(nil) Check that before/after(:all/:context) isn't being used. -[#examples-rspecbeforeafterall] === Examples [source,ruby] @@ -440,7 +406,6 @@ describe MyClass do end ---- -[#configurable-attributes-rspecbeforeafterall] === Configurable attributes |=== @@ -451,13 +416,11 @@ end | Array |=== -[#references-rspecbeforeafterall] === References * https://rspec.rubystyle.guide/#avoid-hooks-with-context-scope * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll -[#rspecchangebyzero] == RSpec/ChangeByZero |=== @@ -480,10 +443,8 @@ compound expectations, but if you set the negated matcher for `change`, e.g. `not_change` with the `NegatedMatcher` option, the cop will perform the autocorrection. -[#examples-rspecchangebyzero] === Examples -[#negatedmatcher_-_-_default_-rspecchangebyzero] ==== NegatedMatcher: ~ (default) [source,ruby] @@ -514,7 +475,6 @@ expect { run } .and not_change { Foo.baz } ---- -[#negatedmatcher_-not_change-rspecchangebyzero] ==== NegatedMatcher: not_change [source,ruby] @@ -537,7 +497,6 @@ expect { run } .and not_change { Foo.baz } ---- -[#configurable-attributes-rspecchangebyzero] === Configurable attributes |=== @@ -548,12 +507,10 @@ expect { run } | |=== -[#references-rspecchangebyzero] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ChangeByZero -[#rspecclasscheck] == RSpec/ClassCheck |=== @@ -568,10 +525,8 @@ expect { run } Enforces consistent use of `be_a` or `be_kind_of`. -[#examples-rspecclasscheck] === Examples -[#enforcedstyle_-be_a-_default_-rspecclasscheck] ==== EnforcedStyle: be_a (default) [source,ruby] @@ -585,7 +540,6 @@ expect(object).to be_a(String) expect(object).to be_an(String) ---- -[#enforcedstyle_-be_kind_of-rspecclasscheck] ==== EnforcedStyle: be_kind_of [source,ruby] @@ -599,7 +553,6 @@ expect(object).to be_kind_of(String) expect(object).to be_a_kind_of(String) ---- -[#configurable-attributes-rspecclasscheck] === Configurable attributes |=== @@ -610,13 +563,11 @@ expect(object).to be_a_kind_of(String) | `be_a`, `be_kind_of` |=== -[#references-rspecclasscheck] === References * https://rubystyle.guide#is-a-vs-kind-of * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ClassCheck -[#rspeccontainexactly] == RSpec/ContainExactly |=== @@ -635,7 +586,6 @@ This cop checks for the following: - Prefer `match_array` when matching array values. - Prefer `be_empty` when using `contain_exactly` with no arguments. -[#examples-rspeccontainexactly] === Examples [source,ruby] @@ -650,12 +600,10 @@ it { is_expected.to match_array(array1 + array2) } it { is_expected.to contain_exactly(content, *array) } ---- -[#references-rspeccontainexactly] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContainExactly -[#rspeccontextmethod] == RSpec/ContextMethod |=== @@ -670,7 +618,6 @@ it { is_expected.to contain_exactly(content, *array) } `context` should not be used for specifying methods. -[#examples-rspeccontextmethod] === Examples [source,ruby] @@ -694,13 +641,11 @@ describe '.foo_bar' do end ---- -[#references-rspeccontextmethod] === References * https://rspec.rubystyle.guide/#example-group-naming * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextMethod -[#rspeccontextwording] == RSpec/ContextWording |=== @@ -726,10 +671,8 @@ report an offense. So you need to set at least one of them. This cop can be customized allowed context description pattern with `AllowedPatterns`. By default, there are no checking by pattern. -[#examples-rspeccontextwording] === Examples -[#_prefixes_-configuration-rspeccontextwording] ==== `Prefixes` configuration [source,ruby] @@ -758,7 +701,6 @@ context 'when the display name is not present' do end ---- -[#_allowedpatterns_-configuration-rspeccontextwording] ==== `AllowedPatterns` configuration [source,ruby] @@ -782,7 +724,6 @@ context '条件を満たすとき' do end ---- -[#configurable-attributes-rspeccontextwording] === Configurable attributes |=== @@ -797,14 +738,12 @@ end | Array |=== -[#references-rspeccontextwording] === References * https://rspec.rubystyle.guide/#context-descriptions * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextWording * http://www.betterspecs.org/#contexts -[#rspecdescribeclass] == RSpec/DescribeClass |=== @@ -823,10 +762,8 @@ It can be configured to ignore strings when certain metadata is passed. Ignores Rails and Aruba `type` metadata by default. -[#examples-rspecdescribeclass] === Examples -[#_ignoredmetadata_-configuration-rspecdescribeclass] ==== `IgnoredMetadata` configuration [source,ruby] @@ -858,7 +795,6 @@ describe "A feature example", type: :feature do end ---- -[#configurable-attributes-rspecdescribeclass] === Configurable attributes |=== @@ -873,12 +809,10 @@ end | |=== -[#references-rspecdescribeclass] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass -[#rspecdescribemethod] == RSpec/DescribeMethod |=== @@ -893,7 +827,6 @@ end Checks that the second argument to `describe` specifies a method. -[#examples-rspecdescribemethod] === Examples [source,ruby] @@ -910,12 +843,10 @@ describe MyClass, '.my_class_method' do end ---- -[#references-rspecdescribemethod] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeMethod -[#rspecdescribesymbol] == RSpec/DescribeSymbol |=== @@ -930,7 +861,6 @@ end Avoid describing symbols. -[#examples-rspecdescribesymbol] === Examples [source,ruby] @@ -946,13 +876,11 @@ describe '#my_method' do end ---- -[#references-rspecdescribesymbol] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeSymbol * https://github.com/rspec/rspec-core/issues/1610 -[#rspecdescribedclass] == RSpec/DescribedClass |=== @@ -984,10 +912,8 @@ To narrow down this setting to only a specific directory, it is possible to use an overriding configuration file local to that directory. -[#examples-rspecdescribedclass] === Examples -[#_enforcedstyle_-described_class_-_default_-rspecdescribedclass] ==== `EnforcedStyle: described_class` (default) [source,ruby] @@ -1003,7 +929,6 @@ describe MyClass do end ---- -[#_onlystaticconstants_-true_-_default_-rspecdescribedclass] ==== `OnlyStaticConstants: true` (default) [source,ruby] @@ -1014,7 +939,6 @@ describe MyClass do end ---- -[#_onlystaticconstants_-false_-rspecdescribedclass] ==== `OnlyStaticConstants: false` [source,ruby] @@ -1025,7 +949,6 @@ describe MyClass do end ---- -[#_enforcedstyle_-explicit_-rspecdescribedclass] ==== `EnforcedStyle: explicit` [source,ruby] @@ -1041,7 +964,6 @@ describe MyClass do end ---- -[#_skipblocks_-true_-rspecdescribedclass] ==== `SkipBlocks: true` [source,ruby] @@ -1058,7 +980,6 @@ describe MyConcern do end ---- -[#configurable-attributes-rspecdescribedclass] === Configurable attributes |=== @@ -1077,12 +998,10 @@ end | Boolean |=== -[#references-rspecdescribedclass] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass -[#rspecdescribedclassmodulewrapping] == RSpec/DescribedClassModuleWrapping |=== @@ -1097,7 +1016,6 @@ end Avoid opening modules and defining specs within them. -[#examples-rspecdescribedclassmodulewrapping] === Examples [source,ruby] @@ -1115,13 +1033,11 @@ RSpec.describe MyModule::MyClass do end ---- -[#references-rspecdescribedclassmodulewrapping] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClassModuleWrapping * https://github.com/rubocop/rubocop-rspec/issues/735 -[#rspecdialect] == RSpec/Dialect |=== @@ -1175,7 +1091,6 @@ native RSpec method (e.g. are just aliases), use the following config: You can expect the following behavior: -[#examples-rspecdialect] === Examples [source,ruby] @@ -1191,7 +1106,6 @@ describe 'display name presence' do end ---- -[#configurable-attributes-rspecdialect] === Configurable attributes |=== @@ -1202,12 +1116,10 @@ end | |=== -[#references-rspecdialect] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect -[#rspecduplicatedmetadata] == RSpec/DuplicatedMetadata |=== @@ -1222,7 +1134,6 @@ end Avoid duplicated metadata. -[#examples-rspecduplicatedmetadata] === Examples [source,ruby] @@ -1234,12 +1145,10 @@ describe 'Something', :a, :a describe 'Something', :a ---- -[#references-rspecduplicatedmetadata] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DuplicatedMetadata -[#rspecemptyexamplegroup] == RSpec/EmptyExampleGroup |=== @@ -1254,10 +1163,8 @@ describe 'Something', :a Checks if an example group does not include any tests. -[#examples-rspecemptyexamplegroup] === Examples -[#usage-rspecemptyexamplegroup] ==== usage [source,ruby] @@ -1292,12 +1199,10 @@ describe Bacon do end ---- -[#references-rspecemptyexamplegroup] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup -[#rspecemptyhook] == RSpec/EmptyHook |=== @@ -1312,7 +1217,6 @@ end Checks for empty before and after hooks. -[#examples-rspecemptyhook] === Examples [source,ruby] @@ -1335,12 +1239,10 @@ end after(:all) { cleanup_feed } ---- -[#references-rspecemptyhook] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyHook -[#rspecemptylineafterexample] == RSpec/EmptyLineAfterExample |=== @@ -1355,7 +1257,6 @@ after(:all) { cleanup_feed } Checks if there is an empty line after example blocks. -[#examples-rspecemptylineafterexample] === Examples [source,ruby] @@ -1384,7 +1285,6 @@ RSpec.describe Foo do end ---- -[#with-allowconsecutiveoneliners-configuration-rspecemptylineafterexample] ==== with AllowConsecutiveOneLiners configuration [source,ruby] @@ -1400,7 +1300,6 @@ RSpec.describe Foo do end ---- -[#configurable-attributes-rspecemptylineafterexample] === Configurable attributes |=== @@ -1411,13 +1310,11 @@ end | Boolean |=== -[#references-rspecemptylineafterexample] === References * https://rspec.rubystyle.guide/#empty-lines-around-examples * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExample -[#rspecemptylineafterexamplegroup] == RSpec/EmptyLineAfterExampleGroup |=== @@ -1432,7 +1329,6 @@ end Checks if there is an empty line after example group blocks. -[#examples-rspecemptylineafterexamplegroup] === Examples [source,ruby] @@ -1455,13 +1351,11 @@ RSpec.describe Foo do end ---- -[#references-rspecemptylineafterexamplegroup] === References * https://rspec.rubystyle.guide/#empty-lines-between-describes * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExampleGroup -[#rspecemptylineafterfinallet] == RSpec/EmptyLineAfterFinalLet |=== @@ -1476,7 +1370,6 @@ end Checks if there is an empty line after the last let block. -[#examples-rspecemptylineafterfinallet] === Examples [source,ruby] @@ -1493,13 +1386,11 @@ let(:something) { other } it { does_something } ---- -[#references-rspecemptylineafterfinallet] === References * https://rspec.rubystyle.guide/#empty-line-after-let * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet -[#rspecemptylineafterhook] == RSpec/EmptyLineAfterHook |=== @@ -1517,7 +1408,6 @@ Checks if there is an empty line after hook blocks. `AllowConsecutiveOneLiners` configures whether adjacent one-line definitions are considered an offense. -[#examples-rspecemptylineafterhook] === Examples [source,ruby] @@ -1546,7 +1436,6 @@ after { do_something } it { does_something } ---- -[#with-allowconsecutiveoneliners-configuration-rspecemptylineafterhook] ==== with AllowConsecutiveOneLiners configuration [source,ruby] @@ -1569,7 +1458,6 @@ after { do_something } it { does_something } ---- -[#configurable-attributes-rspecemptylineafterhook] === Configurable attributes |=== @@ -1580,13 +1468,11 @@ it { does_something } | Boolean |=== -[#references-rspecemptylineafterhook] === References * https://rspec.rubystyle.guide/#empty-line-after-let * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterHook -[#rspecemptylineaftersubject] == RSpec/EmptyLineAfterSubject |=== @@ -1601,7 +1487,6 @@ it { does_something } Checks if there is an empty line after subject block. -[#examples-rspecemptylineaftersubject] === Examples [source,ruby] @@ -1616,13 +1501,11 @@ subject(:obj) { described_class } let(:foo) { bar } ---- -[#references-rspecemptylineaftersubject] === References * https://rspec.rubystyle.guide/#empty-line-after-let * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterSubject -[#rspecemptymetadata] == RSpec/EmptyMetadata |=== @@ -1637,10 +1520,8 @@ let(:foo) { bar } Avoid empty metadata hash. -[#examples-rspecemptymetadata] === Examples -[#enforcedstyle_-symbol-_default_-rspecemptymetadata] ==== EnforcedStyle: symbol (default) [source,ruby] @@ -1652,12 +1533,10 @@ describe 'Something', {} describe 'Something' ---- -[#references-rspecemptymetadata] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyMetadata -[#rspecemptyoutput] == RSpec/EmptyOutput |=== @@ -1672,7 +1551,6 @@ describe 'Something' Check that the `output` matcher is not called with an empty string. -[#examples-rspecemptyoutput] === Examples [source,ruby] @@ -1686,12 +1564,10 @@ expect { foo }.not_to output.to_stdout expect { bar }.to output.to_stderr ---- -[#references-rspecemptyoutput] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyOutput -[#rspeceq] == RSpec/Eq |=== @@ -1706,7 +1582,6 @@ expect { bar }.to output.to_stderr Use `eq` instead of `be ==` to compare objects. -[#examples-rspeceq] === Examples [source,ruby] @@ -1718,12 +1593,10 @@ expect(foo).to be == 42 expect(foo).to eq 42 ---- -[#references-rspeceq] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Eq -[#rspecexamplelength] == RSpec/ExampleLength |=== @@ -1747,7 +1620,6 @@ Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct will be counted as one line regardless of its actual size. -[#examples-rspecexamplelength] === Examples [source,ruby] @@ -1769,7 +1641,6 @@ it do end ---- -[#countasone_-__array__-_heredoc__-_method_call__-rspecexamplelength] ==== CountAsOne: ['array', 'heredoc', 'method_call'] [source,ruby] @@ -1796,7 +1667,6 @@ it do end # 6 points ---- -[#configurable-attributes-rspecexamplelength] === Configurable attributes |=== @@ -1811,12 +1681,10 @@ end # 6 points | Array |=== -[#references-rspecexamplelength] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleLength -[#rspecexamplewithoutdescription] == RSpec/ExampleWithoutDescription |=== @@ -1841,7 +1709,6 @@ on the configured style. This cop can be configured using the `EnforcedStyle` option -[#examples-rspecexamplewithoutdescription] === Examples [source,ruby] @@ -1853,7 +1720,6 @@ specify do end ---- -[#_enforcedstyle_-always_allow_-_default_-rspecexamplewithoutdescription] ==== `EnforcedStyle: always_allow` (default) [source,ruby] @@ -1873,7 +1739,6 @@ specify do end ---- -[#_enforcedstyle_-single_line_only_-rspecexamplewithoutdescription] ==== `EnforcedStyle: single_line_only` [source,ruby] @@ -1889,7 +1754,6 @@ end it { is_expected.to be_good } ---- -[#_enforcedstyle_-disallow_-rspecexamplewithoutdescription] ==== `EnforcedStyle: disallow` [source,ruby] @@ -1902,7 +1766,6 @@ it do end ---- -[#configurable-attributes-rspecexamplewithoutdescription] === Configurable attributes |=== @@ -1913,13 +1776,11 @@ end | `always_allow`, `single_line_only`, `disallow` |=== -[#references-rspecexamplewithoutdescription] === References * https://rspec.rubystyle.guide/#it-and-specify * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWithoutDescription -[#rspecexamplewording] == RSpec/ExampleWording |=== @@ -1944,7 +1805,6 @@ Use the DisallowedExamples setting to prevent unclear or insufficient descriptions. Please note that this config will not be treated as case sensitive. -[#examples-rspecexamplewording] === Examples [source,ruby] @@ -1972,7 +1832,6 @@ it 'does things' do end ---- -[#_disallowedexamples_-__works___-_default_-rspecexamplewording] ==== `DisallowedExamples: ['works']` (default) [source,ruby] @@ -1986,7 +1845,6 @@ it 'marks the task as done' do end ---- -[#configurable-attributes-rspecexamplewording] === Configurable attributes |=== @@ -2005,14 +1863,12 @@ end | Array |=== -[#references-rspecexamplewording] === References * https://rspec.rubystyle.guide/#should-in-example-docstrings * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWording * http://betterspecs.org/#should -[#rspecexcessivedocstringspacing] == RSpec/ExcessiveDocstringSpacing |=== @@ -2027,7 +1883,6 @@ end Checks for excessive whitespace in example descriptions. -[#examples-rspecexcessivedocstringspacing] === Examples [source,ruby] @@ -2052,12 +1907,10 @@ context 'when a condition is met' do end ---- -[#references-rspecexcessivedocstringspacing] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExcessiveDocstringSpacing -[#rspecexpectactual] == RSpec/ExpectActual |=== @@ -2074,7 +1927,6 @@ Checks for `expect(...)` calls containing literal values. Autocorrection is performed when the expected is not a literal. -[#examples-rspecexpectactual] === Examples [source,ruby] @@ -2093,7 +1945,6 @@ expect(name).to eq("John") expect(false).to eq(true) ---- -[#configurable-attributes-rspecexpectactual] === Configurable attributes |=== @@ -2104,12 +1955,10 @@ expect(false).to eq(true) | Array |=== -[#references-rspecexpectactual] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectActual -[#rspecexpectchange] == RSpec/ExpectChange |=== @@ -2129,10 +1978,8 @@ or passing a block that reads the attribute value. This cop can be configured using the `EnforcedStyle` option. -[#examples-rspecexpectchange] === Examples -[#_enforcedstyle_-method_call_-_default_-rspecexpectchange] ==== `EnforcedStyle: method_call` (default) [source,ruby] @@ -2149,7 +1996,6 @@ expect { run }.to change { Foo.bar(:count) } expect { run }.to change { user.reload.name } ---- -[#_enforcedstyle_-block_-rspecexpectchange] ==== `EnforcedStyle: block` [source,ruby] @@ -2161,7 +2007,6 @@ expect { run }.to change(Foo, :bar) expect { run }.to change { Foo.bar } ---- -[#configurable-attributes-rspecexpectchange] === Configurable attributes |=== @@ -2172,12 +2017,10 @@ expect { run }.to change { Foo.bar } | `method_call`, `block` |=== -[#references-rspecexpectchange] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectChange -[#rspecexpectinhook] == RSpec/ExpectInHook |=== @@ -2192,7 +2035,6 @@ expect { run }.to change { Foo.bar } Do not use `expect` in hooks such as `before`. -[#examples-rspecexpectinhook] === Examples [source,ruby] @@ -2213,12 +2055,10 @@ it do end ---- -[#references-rspecexpectinhook] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectInHook -[#rspecexpectinlet] == RSpec/ExpectInLet |=== @@ -2233,7 +2073,6 @@ end Do not use `expect` in let. -[#examples-rspecexpectinlet] === Examples [source,ruby] @@ -2249,12 +2088,10 @@ it do end ---- -[#references-rspecexpectinlet] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectInLet -[#rspecexpectoutput] == RSpec/ExpectOutput |=== @@ -2269,7 +2106,6 @@ end Checks for opportunities to use `expect { ... }.to output`. -[#examples-rspecexpectoutput] === Examples [source,ruby] @@ -2284,12 +2120,10 @@ expect($stdout.string).to eq('Hello World') expect { my_app.print_report }.to output('Hello World').to_stdout ---- -[#references-rspecexpectoutput] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectOutput -[#rspecfocus] == RSpec/Focus |=== @@ -2306,7 +2140,6 @@ Checks if examples are focused. This cop does not support autocorrection in some cases. -[#examples-rspecfocus] === Examples [source,ruby] @@ -2353,12 +2186,10 @@ shared_context 'test' do; end focus 'test' do; end ---- -[#references-rspecfocus] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus -[#rspechookargument] == RSpec/HookArgument |=== @@ -2378,10 +2209,8 @@ hooks which run for each example. There are three supported styles: "implicit", "each", and "example." All styles have the same behavior. -[#examples-rspechookargument] === Examples -[#_enforcedstyle_-implicit_-_default_-rspechookargument] ==== `EnforcedStyle: implicit` (default) [source,ruby] @@ -2402,7 +2231,6 @@ before do end ---- -[#_enforcedstyle_-each_-rspechookargument] ==== `EnforcedStyle: each` [source,ruby] @@ -2423,7 +2251,6 @@ before(:each) do end ---- -[#_enforcedstyle_-example_-rspechookargument] ==== `EnforcedStyle: example` [source,ruby] @@ -2444,7 +2271,6 @@ before(:example) do end ---- -[#configurable-attributes-rspechookargument] === Configurable attributes |=== @@ -2455,13 +2281,11 @@ end | `implicit`, `each`, `example` |=== -[#references-rspechookargument] === References * https://rspec.rubystyle.guide/#redundant-beforeeach * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument -[#rspechooksbeforeexamples] == RSpec/HooksBeforeExamples |=== @@ -2476,7 +2300,6 @@ end Checks for before/around/after hooks that come after an example. -[#examples-rspechooksbeforeexamples] === Examples [source,ruby] @@ -2498,12 +2321,10 @@ it 'checks what foo does' do end ---- -[#references-rspechooksbeforeexamples] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HooksBeforeExamples -[#rspecidenticalequalityassertion] == RSpec/IdenticalEqualityAssertion |=== @@ -2518,7 +2339,6 @@ end Checks for equality assertions with identical expressions on both sides. -[#examples-rspecidenticalequalityassertion] === Examples [source,ruby] @@ -2532,12 +2352,10 @@ expect(foo.bar).to eq(2) expect(foo.bar).to eql(2) ---- -[#references-rspecidenticalequalityassertion] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IdenticalEqualityAssertion -[#rspecimplicitblockexpectation] == RSpec/ImplicitBlockExpectation |=== @@ -2554,7 +2372,6 @@ Check that implicit block expectation syntax is not used. Prefer using explicit block expectations. -[#examples-rspecimplicitblockexpectation] === Examples [source,ruby] @@ -2569,13 +2386,11 @@ it 'changes something to a new value' do end ---- -[#references-rspecimplicitblockexpectation] === References * https://rspec.rubystyle.guide/#implicit-block-expectations * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitBlockExpectation -[#rspecimplicitexpect] == RSpec/ImplicitExpect |=== @@ -2593,10 +2408,8 @@ Check that a consistent implicit expectation style is used. This cop can be configured using the `EnforcedStyle` option and supports the `--auto-gen-config` flag. -[#examples-rspecimplicitexpect] === Examples -[#_enforcedstyle_-is_expected_-_default_-rspecimplicitexpect] ==== `EnforcedStyle: is_expected` (default) [source,ruby] @@ -2608,7 +2421,6 @@ it { should be_truthy } it { is_expected.to be_truthy } ---- -[#_enforcedstyle_-should_-rspecimplicitexpect] ==== `EnforcedStyle: should` [source,ruby] @@ -2620,7 +2432,6 @@ it { is_expected.to be_truthy } it { should be_truthy } ---- -[#configurable-attributes-rspecimplicitexpect] === Configurable attributes |=== @@ -2631,13 +2442,11 @@ it { should be_truthy } | `is_expected`, `should` |=== -[#references-rspecimplicitexpect] === References * https://rspec.rubystyle.guide/#use-expect * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitExpect -[#rspecimplicitsubject] == RSpec/ImplicitSubject |=== @@ -2654,10 +2463,8 @@ Checks for usage of implicit subject (`is_expected` / `should`). This cop can be configured using the `EnforcedStyle` option -[#examples-rspecimplicitsubject] === Examples -[#_enforcedstyle_-single_line_only_-_default_-rspecimplicitsubject] ==== `EnforcedStyle: single_line_only` (default) [source,ruby] @@ -2674,7 +2481,6 @@ it do end ---- -[#_enforcedstyle_-single_statement_only_-rspecimplicitsubject] ==== `EnforcedStyle: single_statement_only` [source,ruby] @@ -2695,7 +2501,6 @@ it do end ---- -[#_enforcedstyle_-disallow_-rspecimplicitsubject] ==== `EnforcedStyle: disallow` [source,ruby] @@ -2707,7 +2512,6 @@ it { is_expected.to be_truthy } it { expect(subject).to be_truthy } ---- -[#_enforcedstyle_-require_implicit_-rspecimplicitsubject] ==== `EnforcedStyle: require_implicit` [source,ruby] @@ -2732,7 +2536,6 @@ end it { expect(named_subject).to be_truthy } ---- -[#configurable-attributes-rspecimplicitsubject] === Configurable attributes |=== @@ -2743,12 +2546,10 @@ it { expect(named_subject).to be_truthy } | `single_line_only`, `single_statement_only`, `disallow`, `require_implicit` |=== -[#references-rspecimplicitsubject] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitSubject -[#rspecindexedlet] == RSpec/IndexedLet |=== @@ -2769,10 +2570,8 @@ is tested by this particular example. The configurable options `AllowedIdentifiers` and `AllowedPatterns` will also read those set in `Naming/VariableNumber`. -[#examples-rspecindexedlet] === Examples -[#_max_-1-_default__-rspecindexedlet] ==== `Max: 1 (default)` [source,ruby] @@ -2790,7 +2589,6 @@ let(:visible_item) { create(:item, visible: true) } let(:invisible_item) { create(:item, visible: false) } ---- -[#_max_-2_-rspecindexedlet] ==== `Max: 2` [source,ruby] @@ -2805,7 +2603,6 @@ let(:item_1) { create(:item) } let(:item_2) { create(:item) } ---- -[#_allowedidentifiers_-__item_1__-_item_2___-rspecindexedlet] ==== `AllowedIdentifiers: ['item_1', 'item_2']` [source,ruby] @@ -2815,7 +2612,6 @@ let(:item_1) { create(:item) } let(:item_2) { create(:item) } ---- -[#_allowedpatterns_-__item___-rspecindexedlet] ==== `AllowedPatterns: ['item']` [source,ruby] @@ -2825,7 +2621,6 @@ let(:item_1) { create(:item) } let(:item_2) { create(:item) } ---- -[#configurable-attributes-rspecindexedlet] === Configurable attributes |=== @@ -2844,12 +2639,10 @@ let(:item_2) { create(:item) } | Array |=== -[#references-rspecindexedlet] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IndexedLet -[#rspecinstancespy] == RSpec/InstanceSpy |=== @@ -2864,7 +2657,6 @@ let(:item_2) { create(:item) } Checks for `instance_double` used with `have_received`. -[#examples-rspecinstancespy] === Examples [source,ruby] @@ -2882,12 +2674,10 @@ it do end ---- -[#references-rspecinstancespy] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceSpy -[#rspecinstancevariable] == RSpec/InstanceVariable |=== @@ -2907,7 +2697,6 @@ will configure the cop to only register offenses on instance variable usage if the instance variable is also assigned within the spec -[#examples-rspecinstancevariable] === Examples [source,ruby] @@ -2925,7 +2714,6 @@ describe MyClass do end ---- -[#with-assignmentonly-configuration-rspecinstancevariable] ==== with AssignmentOnly configuration [source,ruby] @@ -2952,7 +2740,6 @@ describe MyClass do end ---- -[#configurable-attributes-rspecinstancevariable] === Configurable attributes |=== @@ -2963,13 +2750,11 @@ end | Boolean |=== -[#references-rspecinstancevariable] === References * https://rspec.rubystyle.guide/#instance-variables * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable -[#rspecisexpectedspecify] == RSpec/IsExpectedSpecify |=== @@ -2984,7 +2769,6 @@ end Check for `specify` with `is_expected` and one-liner expectations. -[#examples-rspecisexpectedspecify] === Examples [source,ruby] @@ -3002,13 +2786,11 @@ end specify { expect(sqrt(4)).to eq(2) } ---- -[#references-rspecisexpectedspecify] === References * https://rspec.rubystyle.guide/#it-and-specify * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IsExpectedSpecify -[#rspecitbehaveslike] == RSpec/ItBehavesLike |=== @@ -3023,10 +2805,8 @@ specify { expect(sqrt(4)).to eq(2) } Checks that only one `it_behaves_like` style is used. -[#examples-rspecitbehaveslike] === Examples -[#_enforcedstyle_-it_behaves_like_-_default_-rspecitbehaveslike] ==== `EnforcedStyle: it_behaves_like` (default) [source,ruby] @@ -3038,7 +2818,6 @@ it_should_behave_like 'a foo' it_behaves_like 'a foo' ---- -[#_enforcedstyle_-it_should_behave_like_-rspecitbehaveslike] ==== `EnforcedStyle: it_should_behave_like` [source,ruby] @@ -3050,7 +2829,6 @@ it_behaves_like 'a foo' it_should_behave_like 'a foo' ---- -[#configurable-attributes-rspecitbehaveslike] === Configurable attributes |=== @@ -3061,12 +2839,10 @@ it_should_behave_like 'a foo' | `it_behaves_like`, `it_should_behave_like` |=== -[#references-rspecitbehaveslike] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ItBehavesLike -[#rspeciteratedexpectation] == RSpec/IteratedExpectation |=== @@ -3081,7 +2857,6 @@ it_should_behave_like 'a foo' Check that `all` matcher is used instead of iterating over an array. -[#examples-rspeciteratedexpectation] === Examples [source,ruby] @@ -3097,12 +2872,10 @@ it 'validates users' do end ---- -[#references-rspeciteratedexpectation] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IteratedExpectation -[#rspecleadingsubject] == RSpec/LeadingSubject |=== @@ -3117,7 +2890,6 @@ end Enforce that subject is the first definition in the test. -[#examples-rspecleadingsubject] === Examples [source,ruby] @@ -3147,13 +2919,11 @@ it { expect_something } it { expect_something_else } ---- -[#references-rspecleadingsubject] === References * https://rspec.rubystyle.guide/#leading-subject * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeadingSubject -[#rspecleakyconstantdeclaration] == RSpec/LeakyConstantDeclaration |=== @@ -3180,10 +2950,8 @@ Even worse when a class that exists in the codebase is reopened. Anonymous classes are fine, since they don't result in global namespace name clashes. -[#examples-rspecleakyconstantdeclaration] === Examples -[#constants-leak-between-examples-rspecleakyconstantdeclaration] ==== Constants leak between examples [source,ruby] @@ -3267,14 +3035,12 @@ describe SomeClass do end ---- -[#references-rspecleakyconstantdeclaration] === References * https://rspec.rubystyle.guide/#declare-constants * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeakyConstantDeclaration * https://rspec.info/features/3-12/rspec-mocks/mutating-constants -[#rspecletbeforeexamples] == RSpec/LetBeforeExamples |=== @@ -3289,7 +3055,6 @@ end Checks for `let` definitions that come after an example. -[#examples-rspecletbeforeexamples] === Examples [source,ruby] @@ -3320,12 +3085,10 @@ it 'checks what some does' do end ---- -[#references-rspecletbeforeexamples] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetBeforeExamples -[#rspecletsetup] == RSpec/LetSetup |=== @@ -3340,7 +3103,6 @@ end Checks unreferenced `let!` calls being used for test setup. -[#examples-rspecletsetup] === Examples [source,ruby] @@ -3366,12 +3128,10 @@ it 'counts widgets' do end ---- -[#references-rspecletsetup] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetSetup -[#rspecmatcharray] == RSpec/MatchArray |=== @@ -3390,7 +3150,6 @@ This cop checks for the following: - Prefer `contain_exactly` when matching an array with values. - Prefer `eq` when using `match_array` with an empty array literal. -[#examples-rspecmatcharray] === Examples [source,ruby] @@ -3408,12 +3167,10 @@ it { is_expected.to match_array([content] + array) } it { is_expected.to match_array(%w(tremble in fear foolish mortals)) } ---- -[#references-rspecmatcharray] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MatchArray -[#rspecmessagechain] == RSpec/MessageChain |=== @@ -3428,7 +3185,6 @@ it { is_expected.to match_array(%w(tremble in fear foolish mortals)) } Check that chains of messages are not being stubbed. -[#examples-rspecmessagechain] === Examples [source,ruby] @@ -3441,12 +3197,10 @@ thing = Thing.new(baz: 42) allow(foo).to receive(:bar).and_return(thing) ---- -[#references-rspecmessagechain] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageChain -[#rspecmessageexpectation] == RSpec/MessageExpectation |=== @@ -3464,10 +3218,8 @@ Checks for consistent message expectation style. This cop can be configured in your configuration using the `EnforcedStyle` option and supports `--auto-gen-config`. -[#examples-rspecmessageexpectation] === Examples -[#_enforcedstyle_-allow_-_default_-rspecmessageexpectation] ==== `EnforcedStyle: allow` (default) [source,ruby] @@ -3479,7 +3231,6 @@ expect(foo).to receive(:bar) allow(foo).to receive(:bar) ---- -[#_enforcedstyle_-expect_-rspecmessageexpectation] ==== `EnforcedStyle: expect` [source,ruby] @@ -3491,7 +3242,6 @@ allow(foo).to receive(:bar) expect(foo).to receive(:bar) ---- -[#configurable-attributes-rspecmessageexpectation] === Configurable attributes |=== @@ -3502,12 +3252,10 @@ expect(foo).to receive(:bar) | `allow`, `expect` |=== -[#references-rspecmessageexpectation] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageExpectation -[#rspecmessagespies] == RSpec/MessageSpies |=== @@ -3525,10 +3273,8 @@ Checks that message expectations are set using spies. This cop can be configured in your configuration using the `EnforcedStyle` option and supports `--auto-gen-config`. -[#examples-rspecmessagespies] === Examples -[#_enforcedstyle_-have_received_-_default_-rspecmessagespies] ==== `EnforcedStyle: have_received` (default) [source,ruby] @@ -3543,7 +3289,6 @@ do_something expect(foo).to have_received(:bar) ---- -[#_enforcedstyle_-receive_-rspecmessagespies] ==== `EnforcedStyle: receive` [source,ruby] @@ -3558,7 +3303,6 @@ expect(foo).to receive(:bar) do_something ---- -[#configurable-attributes-rspecmessagespies] === Configurable attributes |=== @@ -3569,12 +3313,10 @@ do_something | `have_received`, `receive` |=== -[#references-rspecmessagespies] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageSpies -[#rspecmetadatastyle] == RSpec/MetadataStyle |=== @@ -3593,10 +3335,8 @@ This cop does not support autocorrection in the case of `EnforcedStyle: hash` where the trailing metadata type is ambiguous. (e.g. `describe 'Something', :a, b`) -[#examples-rspecmetadatastyle] === Examples -[#enforcedstyle_-symbol-_default_-rspecmetadatastyle] ==== EnforcedStyle: symbol (default) [source,ruby] @@ -3608,7 +3348,6 @@ describe 'Something', a: true describe 'Something', :a ---- -[#enforcedstyle_-hash-rspecmetadatastyle] ==== EnforcedStyle: hash [source,ruby] @@ -3620,7 +3359,6 @@ describe 'Something', :a describe 'Something', a: true ---- -[#configurable-attributes-rspecmetadatastyle] === Configurable attributes |=== @@ -3631,12 +3369,10 @@ describe 'Something', a: true | `hash`, `symbol` |=== -[#references-rspecmetadatastyle] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MetadataStyle -[#rspecmissingexamplegroupargument] == RSpec/MissingExampleGroupArgument |=== @@ -3651,7 +3387,6 @@ describe 'Something', a: true Checks that the first argument to an example group is not empty. -[#examples-rspecmissingexamplegroupargument] === Examples [source,ruby] @@ -3671,12 +3406,10 @@ describe "A feature example" do end ---- -[#references-rspecmissingexamplegroupargument] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MissingExampleGroupArgument -[#rspecmissingexpectationtargetmethod] == RSpec/MissingExpectationTargetMethod |=== @@ -3694,7 +3427,6 @@ Checks if `.to`, `not_to` or `to_not` are used. The RSpec::Expectations::ExpectationTarget must use `to`, `not_to` or `to_not` to run. Therefore, this cop checks if other methods are used. -[#examples-rspecmissingexpectationtargetmethod] === Examples [source,ruby] @@ -3710,12 +3442,10 @@ is_expected.to eq 42 expect{something}.to raise_error BarError ---- -[#references-rspecmissingexpectationtargetmethod] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MissingExpectationTargetMethod -[#rspecmultipledescribes] == RSpec/MultipleDescribes |=== @@ -3733,7 +3463,6 @@ Checks for multiple top-level example groups. Multiple descriptions for the same class or module should either be nested or separated into different test files. -[#examples-rspecmultipledescribes] === Examples [source,ruby] @@ -3753,12 +3482,10 @@ describe MyClass do end ---- -[#references-rspecmultipledescribes] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleDescribes -[#rspecmultipleexpectations] == RSpec/MultipleExpectations |=== @@ -3776,7 +3503,6 @@ Checks if examples contain too many `expect` calls. This cop is configurable using the `Max` option and works with `--auto-gen-config`. -[#examples-rspecmultipleexpectations] === Examples [source,ruby] @@ -3801,7 +3527,6 @@ describe UserCreator do end ---- -[#_aggregate_failures_-true_-_default_-rspecmultipleexpectations] ==== `aggregate_failures: true` (default) [source,ruby] @@ -3815,7 +3540,6 @@ describe UserCreator do end ---- -[#_aggregate_failures_-false_-rspecmultipleexpectations] ==== `aggregate_failures: false` [source,ruby] @@ -3829,7 +3553,6 @@ describe UserCreator do end ---- -[#_max_-1_-_default_-rspecmultipleexpectations] ==== `Max: 1` (default) [source,ruby] @@ -3843,7 +3566,6 @@ describe UserCreator do end ---- -[#_max_-2_-rspecmultipleexpectations] ==== `Max: 2` [source,ruby] @@ -3857,7 +3579,6 @@ describe UserCreator do end ---- -[#configurable-attributes-rspecmultipleexpectations] === Configurable attributes |=== @@ -3868,14 +3589,12 @@ end | Integer |=== -[#references-rspecmultipleexpectations] === References * https://rspec.rubystyle.guide/#expectation-per-example * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations * http://betterspecs.org/#single -[#rspecmultiplememoizedhelpers] == RSpec/MultipleMemoizedHelpers |=== @@ -3894,7 +3613,6 @@ This cop is configurable using the `Max` option and the `AllowSubject` which will configure the cop to only register offenses on calls to `let` and not calls to `subject`. -[#examples-rspecmultiplememoizedhelpers] === Examples [source,ruby] @@ -3945,7 +3663,6 @@ describe MyClass do end ---- -[#when-disabling-allowsubject-configuration-rspecmultiplememoizedhelpers] ==== when disabling AllowSubject configuration [source,ruby] @@ -3965,7 +3682,6 @@ describe MyClass do end ---- -[#with-max-configuration-rspecmultiplememoizedhelpers] ==== with Max configuration [source,ruby] @@ -3981,7 +3697,6 @@ describe MyClass do end ---- -[#configurable-attributes-rspecmultiplememoizedhelpers] === Configurable attributes |=== @@ -3996,13 +3711,11 @@ end | Integer |=== -[#references-rspecmultiplememoizedhelpers] === References * https://rspec.rubystyle.guide/#let-blocks * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers -[#rspecmultiplesubjects] == RSpec/MultipleSubjects |=== @@ -4033,7 +3746,6 @@ duplication: This is enough of an edge case that people can just move this to a `before` hook on their own -[#examples-rspecmultiplesubjects] === Examples [source,ruby] @@ -4065,12 +3777,10 @@ describe Foo do end ---- -[#references-rspecmultiplesubjects] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleSubjects -[#rspecnamedsubject] == RSpec/NamedSubject |=== @@ -4096,10 +3806,8 @@ This cop can be configured in your configuration using `EnforcedStyle`, and `IgnoreSharedExamples` which will not report offenses for implicit subjects in shared example groups. -[#examples-rspecnamedsubject] === Examples -[#_enforcedstyle_-always_-_default_-rspecnamedsubject] ==== `EnforcedStyle: always` (default) [source,ruby] @@ -4130,7 +3838,6 @@ RSpec.describe User do end ---- -[#_enforcedstyle_-named_only_-rspecnamedsubject] ==== `EnforcedStyle: named_only` [source,ruby] @@ -4170,7 +3877,6 @@ RSpec.describe User do end ---- -[#configurable-attributes-rspecnamedsubject] === Configurable attributes |=== @@ -4185,13 +3891,11 @@ end | Boolean |=== -[#references-rspecnamedsubject] === References * https://rspec.rubystyle.guide/#use-subject * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NamedSubject -[#rspecnestedgroups] == RSpec/NestedGroups |=== @@ -4209,7 +3913,6 @@ Checks for nested example groups. This cop is configurable using the `Max` option and supports `--auto-gen-config`. -[#examples-rspecnestedgroups] === Examples [source,ruby] @@ -4259,7 +3962,6 @@ context 'using some feature as an admin' do end ---- -[#_max_-3_-_default_-rspecnestedgroups] ==== `Max: 3` (default) [source,ruby] @@ -4275,7 +3977,6 @@ describe Foo do end ---- -[#_max_-2_-rspecnestedgroups] ==== `Max: 2` [source,ruby] @@ -4291,7 +3992,6 @@ describe Foo do end ---- -[#_allowedgroups_-__-_default__-rspecnestedgroups] ==== `AllowedGroups: [] (default)` [source,ruby] @@ -4304,7 +4004,6 @@ describe Foo do # <-- nested groups 1 end ---- -[#_allowedgroups_-_path__-rspecnestedgroups] ==== `AllowedGroups: [path]` [source,ruby] @@ -4317,7 +4016,6 @@ describe Foo do # <-- nested groups 1 end ---- -[#configurable-attributes-rspecnestedgroups] === Configurable attributes |=== @@ -4332,12 +4030,10 @@ end | Array |=== -[#references-rspecnestedgroups] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NestedGroups -[#rspecnoexpectationexample] == RSpec/NoExpectationExample |=== @@ -4368,7 +4064,6 @@ This cop can be customized with an allowed expectation methods pattern with an `AllowedPatterns` option. ^expect_ and ^assert_ are allowed by default. -[#examples-rspecnoexpectationexample] === Examples [source,ruby] @@ -4384,7 +4079,6 @@ it do end ---- -[#_allowedpatterns_-configuration-rspecnoexpectationexample] ==== `AllowedPatterns` configuration [source,ruby] @@ -4413,7 +4107,6 @@ it do end ---- -[#configurable-attributes-rspecnoexpectationexample] === Configurable attributes |=== @@ -4424,12 +4117,10 @@ end | Array |=== -[#references-rspecnoexpectationexample] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NoExpectationExample -[#rspecnottonot] == RSpec/NotToNot |=== @@ -4444,10 +4135,8 @@ end Checks for consistent method usage for negating expectations. -[#examples-rspecnottonot] === Examples -[#_enforcedstyle_-not_to_-_default_-rspecnottonot] ==== `EnforcedStyle: not_to` (default) [source,ruby] @@ -4463,7 +4152,6 @@ it '...' do end ---- -[#_enforcedstyle_-to_not_-rspecnottonot] ==== `EnforcedStyle: to_not` [source,ruby] @@ -4479,7 +4167,6 @@ it '...' do end ---- -[#configurable-attributes-rspecnottonot] === Configurable attributes |=== @@ -4490,12 +4177,10 @@ end | `not_to`, `to_not` |=== -[#references-rspecnottonot] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NotToNot -[#rspecoverwritingsetup] == RSpec/OverwritingSetup |=== @@ -4510,7 +4195,6 @@ end Checks if there is a let/subject that overwrites an existing one. -[#examples-rspecoverwritingsetup] === Examples [source,ruby] @@ -4532,12 +4216,10 @@ let(:baz) { baz } let!(:other) { other } ---- -[#references-rspecoverwritingsetup] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/OverwritingSetup -[#rspecpending] == RSpec/Pending |=== @@ -4552,7 +4234,6 @@ let!(:other) { other } Checks for any pending or skipped examples. -[#examples-rspecpending] === Examples [source,ruby] @@ -4584,12 +4265,10 @@ describe MyClass do end ---- -[#references-rspecpending] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Pending -[#rspecpendingwithoutreason] == RSpec/PendingWithoutReason |=== @@ -4604,7 +4283,6 @@ end Checks for pending or skipped examples without reason. -[#examples-rspecpendingwithoutreason] === Examples [source,ruby] @@ -4661,12 +4339,10 @@ it 'does something', skip: 'reason' do end ---- -[#references-rspecpendingwithoutreason] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/PendingWithoutReason -[#rspecpredicatematcher] == RSpec/PredicateMatcher |=== @@ -4685,10 +4361,8 @@ RSpec defines magic matchers for predicate methods. This cop recommends to use the predicate matcher instead of using predicate method directly. -[#examples-rspecpredicatematcher] === Examples -[#strict_-true_-enforcedstyle_-inflected-_default_-rspecpredicatematcher] ==== Strict: true, EnforcedStyle: inflected (default) [source,ruby] @@ -4703,7 +4377,6 @@ expect(foo).to be_something expect(foo.something?).to be(true) ---- -[#strict_-false_-enforcedstyle_-inflected-rspecpredicatematcher] ==== Strict: false, EnforcedStyle: inflected [source,ruby] @@ -4716,7 +4389,6 @@ expect(foo.something?).to be(true) expect(foo).to be_something ---- -[#strict_-true_-enforcedstyle_-explicit-rspecpredicatematcher] ==== Strict: true, EnforcedStyle: explicit [source,ruby] @@ -4739,7 +4411,6 @@ expect(foo.something?(<<~TEXT)).to be(true) TEXT ---- -[#strict_-false_-enforcedstyle_-explicit-rspecpredicatematcher] ==== Strict: false, EnforcedStyle: explicit [source,ruby] @@ -4751,7 +4422,6 @@ expect(foo).to be_something expect(foo.something?).to be_truthy ---- -[#configurable-attributes-rspecpredicatematcher] === Configurable attributes |=== @@ -4770,13 +4440,11 @@ expect(foo.something?).to be_truthy | Array |=== -[#references-rspecpredicatematcher] === References * https://rspec.rubystyle.guide/#predicate-matchers * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/PredicateMatcher -[#rspecreceivecounts] == RSpec/ReceiveCounts |=== @@ -4791,7 +4459,6 @@ expect(foo.something?).to be_truthy Check for `once` and `twice` receive counts matchers usage. -[#examples-rspecreceivecounts] === Examples [source,ruby] @@ -4813,12 +4480,10 @@ expect(foo).to receive(:bar).at_most(:once) expect(foo).to receive(:bar).at_most(:twice).times ---- -[#references-rspecreceivecounts] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveCounts -[#rspecreceivemessages] == RSpec/ReceiveMessages |=== @@ -4833,14 +4498,12 @@ expect(foo).to receive(:bar).at_most(:twice).times Checks for multiple messages stubbed on the same object. -[#safety-rspecreceivemessages] === Safety The autocorrection is marked as unsafe, because it may change the order of stubs. This in turn may cause e.g. variables to be called before they are defined. -[#examples-rspecreceivemessages] === Examples [source,ruby] @@ -4863,12 +4526,10 @@ before do end ---- -[#references-rspecreceivemessages] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveMessages -[#rspecreceivenever] == RSpec/ReceiveNever |=== @@ -4883,7 +4544,6 @@ end Prefer `not_to receive(...)` over `receive(...).never`. -[#examples-rspecreceivenever] === Examples [source,ruby] @@ -4895,12 +4555,10 @@ expect(foo).to receive(:bar).never expect(foo).not_to receive(:bar) ---- -[#references-rspecreceivenever] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveNever -[#rspecredundantaround] == RSpec/RedundantAround |=== @@ -4915,7 +4573,6 @@ expect(foo).not_to receive(:bar) Remove redundant `around` hook. -[#examples-rspecredundantaround] === Examples [source,ruby] @@ -4928,12 +4585,10 @@ end # good ---- -[#references-rspecredundantaround] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RedundantAround -[#rspecredundantpredicatematcher] == RSpec/RedundantPredicateMatcher |=== @@ -4948,7 +4603,6 @@ end Checks for redundant predicate matcher. -[#examples-rspecredundantpredicatematcher] === Examples [source,ruby] @@ -4964,12 +4618,10 @@ expect(foo).not_to include(bar) expect(foo).to all be(bar) ---- -[#references-rspecredundantpredicatematcher] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RedundantPredicateMatcher -[#rspecremoveconst] == RSpec/RemoveConst |=== @@ -4984,7 +4636,6 @@ expect(foo).to all be(bar) Checks that `remove_const` is not used in specs. -[#examples-rspecremoveconst] === Examples [source,ruby] @@ -4999,12 +4650,10 @@ before do end ---- -[#references-rspecremoveconst] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RemoveConst -[#rspecrepeateddescription] == RSpec/RepeatedDescription |=== @@ -5019,7 +4668,6 @@ end Check for repeated description strings in example groups. -[#examples-rspecrepeateddescription] === Examples [source,ruby] @@ -5058,12 +4706,10 @@ RSpec.describe User do end ---- -[#references-rspecrepeateddescription] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedDescription -[#rspecrepeatedexample] == RSpec/RepeatedExample |=== @@ -5078,7 +4724,6 @@ end Check for repeated examples within example groups. -[#examples-rspecrepeatedexample] === Examples [source,ruby] @@ -5092,12 +4737,10 @@ it 'validates the user' do end ---- -[#references-rspecrepeatedexample] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExample -[#rspecrepeatedexamplegroupbody] == RSpec/RepeatedExampleGroupBody |=== @@ -5112,7 +4755,6 @@ end Check for repeated describe and context block body. -[#examples-rspecrepeatedexamplegroupbody] === Examples [source,ruby] @@ -5154,12 +4796,10 @@ context Hash do end ---- -[#references-rspecrepeatedexamplegroupbody] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExampleGroupBody -[#rspecrepeatedexamplegroupdescription] == RSpec/RepeatedExampleGroupDescription |=== @@ -5174,7 +4814,6 @@ end Check for repeated example group descriptions. -[#examples-rspecrepeatedexamplegroupdescription] === Examples [source,ruby] @@ -5216,12 +4855,10 @@ context 'when another case' do end ---- -[#references-rspecrepeatedexamplegroupdescription] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExampleGroupDescription -[#rspecrepeatedincludeexample] == RSpec/RepeatedIncludeExample |=== @@ -5236,7 +4873,6 @@ end Check for repeated include of shared examples. -[#examples-rspecrepeatedincludeexample] === Examples [source,ruby] @@ -5281,12 +4917,10 @@ context 'foo' do end ---- -[#references-rspecrepeatedincludeexample] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedIncludeExample -[#rspecrepeatedsubjectcall] == RSpec/RepeatedSubjectCall |=== @@ -5301,7 +4935,6 @@ end Checks for repeated calls to subject missing that it is memoized. -[#examples-rspecrepeatedsubjectcall] === Examples [source,ruby] @@ -5330,12 +4963,10 @@ it do end ---- -[#references-rspecrepeatedsubjectcall] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedSubjectCall -[#rspecreturnfromstub] == RSpec/ReturnFromStub |=== @@ -5356,10 +4987,8 @@ are the result would be different This cop can be configured using the `EnforcedStyle` option -[#examples-rspecreturnfromstub] === Examples -[#_enforcedstyle_-and_return_-_default_-rspecreturnfromstub] ==== `EnforcedStyle: and_return` (default) [source,ruby] @@ -5375,7 +5004,6 @@ expect(Foo).to receive(:bar).and_return("baz") allow(Foo).to receive(:bar) { bar.baz } ---- -[#_enforcedstyle_-block_-rspecreturnfromstub] ==== `EnforcedStyle: block` [source,ruby] @@ -5391,7 +5019,6 @@ expect(Foo).to receive(:bar) { "baz" } allow(Foo).to receive(:bar).and_return(bar.baz) ---- -[#configurable-attributes-rspecreturnfromstub] === Configurable attributes |=== @@ -5402,12 +5029,10 @@ allow(Foo).to receive(:bar).and_return(bar.baz) | `and_return`, `block` |=== -[#references-rspecreturnfromstub] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReturnFromStub -[#rspecscatteredlet] == RSpec/ScatteredLet |=== @@ -5424,7 +5049,6 @@ Checks for let scattered across the example group. Group lets together -[#examples-rspecscatteredlet] === Examples [source,ruby] @@ -5448,12 +5072,10 @@ describe Foo do end ---- -[#references-rspecscatteredlet] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredLet -[#rspecscatteredsetup] == RSpec/ScatteredSetup |=== @@ -5470,7 +5092,6 @@ Checks for setup scattered across multiple hooks in an example group. Unify `before`, `after`, and `around` hooks when possible. -[#examples-rspecscatteredsetup] === Examples [source,ruby] @@ -5490,12 +5111,10 @@ describe Foo do end ---- -[#references-rspecscatteredsetup] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredSetup -[#rspecsharedcontext] == RSpec/SharedContext |=== @@ -5513,7 +5132,6 @@ Checks for proper shared_context and shared_examples usage. If there are no examples defined, use shared_context. If there is no setup defined, use shared_examples. -[#examples-rspecsharedcontext] === Examples [source,ruby] @@ -5562,12 +5180,10 @@ RSpec.shared_context 'only setup here' do end ---- -[#references-rspecsharedcontext] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedContext -[#rspecsharedexamples] == RSpec/SharedExamples |=== @@ -5586,10 +5202,8 @@ Enforces either `string` or `symbol` for shared example names. This cop can be configured using the `EnforcedStyle` option -[#examples-rspecsharedexamples] === Examples -[#_enforcedstyle_-string_-_default_-rspecsharedexamples] ==== `EnforcedStyle: string` (default) [source,ruby] @@ -5609,7 +5223,6 @@ shared_examples_for 'foo bar baz' include_examples 'foo bar baz' ---- -[#_enforcedstyle_-symbol_-rspecsharedexamples] ==== `EnforcedStyle: symbol` [source,ruby] @@ -5629,7 +5242,6 @@ shared_examples_for :foo_bar_baz include_examples :foo_bar_baz ---- -[#configurable-attributes-rspecsharedexamples] === Configurable attributes |=== @@ -5640,12 +5252,10 @@ include_examples :foo_bar_baz | `string`, `symbol` |=== -[#references-rspecsharedexamples] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedExamples -[#rspecsingleargumentmessagechain] == RSpec/SingleArgumentMessageChain |=== @@ -5660,7 +5270,6 @@ include_examples :foo_bar_baz Checks that chains of messages contain more than one element. -[#examples-rspecsingleargumentmessagechain] === Examples [source,ruby] @@ -5676,12 +5285,10 @@ allow(foo).to receive(:bar, :baz) allow(foo).to receive("bar.baz") ---- -[#references-rspecsingleargumentmessagechain] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SingleArgumentMessageChain -[#rspecskipblockinsideexample] == RSpec/SkipBlockInsideExample |=== @@ -5696,7 +5303,6 @@ allow(foo).to receive("bar.baz") Checks for passing a block to `skip` within examples. -[#examples-rspecskipblockinsideexample] === Examples [source,ruby] @@ -5719,12 +5325,10 @@ skip 'not yet implemented' do end ---- -[#references-rspecskipblockinsideexample] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SkipBlockInsideExample -[#rspecsortmetadata] == RSpec/SortMetadata |=== @@ -5739,7 +5343,6 @@ end Sort RSpec metadata alphabetically. -[#examples-rspecsortmetadata] === Examples [source,ruby] @@ -5755,12 +5358,10 @@ context 'Something', baz: true, foo: 'bar' it 'works', :a, :b, baz: true, foo: 'bar' ---- -[#references-rspecsortmetadata] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SortMetadata -[#rspecspecfilepathformat] == RSpec/SpecFilePathFormat |=== @@ -5775,7 +5376,6 @@ it 'works', :a, :b, baz: true, foo: 'bar' Checks that spec file paths are consistent and well-formed. -[#examples-rspecspecfilepathformat] === Examples [source,ruby] @@ -5790,7 +5390,6 @@ my_class_method_spec.rb # describe MyClass, '#method' my_class/method_spec.rb # describe MyClass, '#method' ---- -[#_customtransform_-_rubocop__rubocop_-rspec__rspec__-_default_-rspecspecfilepathformat] ==== `CustomTransform: {RuboCop=>rubocop, RSpec=>rspec}` (default) [source,ruby] @@ -5800,7 +5399,6 @@ rubocop_spec.rb # describe RuboCop rspec_spec.rb # describe RSpec ---- -[#_ignoremethods_-false_-_default_-rspecspecfilepathformat] ==== `IgnoreMethods: false` (default) [source,ruby] @@ -5809,7 +5407,6 @@ rspec_spec.rb # describe RSpec my_class_spec.rb # describe MyClass, '#method' ---- -[#_ignoremethods_-true_-rspecspecfilepathformat] ==== `IgnoreMethods: true` [source,ruby] @@ -5818,7 +5415,6 @@ my_class_spec.rb # describe MyClass, '#method' my_class_spec.rb # describe MyClass, '#method' ---- -[#_ignoremetadata_-_type__routing__-_default_-rspecspecfilepathformat] ==== `IgnoreMetadata: {type=>routing}` (default) [source,ruby] @@ -5827,7 +5423,6 @@ my_class_spec.rb # describe MyClass, '#method' whatever_spec.rb # describe MyClass, type: :routing do; end ---- -[#configurable-attributes-rspecspecfilepathformat] === Configurable attributes |=== @@ -5854,12 +5449,10 @@ whatever_spec.rb # describe MyClass, type: :routing do; end | |=== -[#references-rspecspecfilepathformat] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathFormat -[#rspecspecfilepathsuffix] == RSpec/SpecFilePathSuffix |=== @@ -5874,7 +5467,6 @@ whatever_spec.rb # describe MyClass, type: :routing do; end Checks that spec file paths suffix are consistent and well-formed. -[#examples-rspecspecfilepathsuffix] === Examples [source,ruby] @@ -5891,7 +5483,6 @@ my_class_spec.rb # describe MyClass spec/models/user.rb # shared_examples_for 'foo' ---- -[#configurable-attributes-rspecspecfilepathsuffix] === Configurable attributes |=== @@ -5902,51 +5493,10 @@ spec/models/user.rb # shared_examples_for 'foo' | Array |=== -[#references-rspecspecfilepathsuffix] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathSuffix -[#rspecstringasinstancedoubleconstant] -== RSpec/StringAsInstanceDoubleConstant - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| No -| Always (Unsafe) -| 3.1 -| - -|=== - -Do not use a string as `instance_double` constant. - -[#safety-rspecstringasinstancedoubleconstant] -=== Safety - -This cop is unsafe because the correction requires loading the class. -Loading before stubbing causes RSpec to only allow instance methods -to be stubbed. - -[#examples-rspecstringasinstancedoubleconstant] -=== Examples - -[source,ruby] ----- -# bad -instance_double('User', name: 'John') - -# good -instance_double(User, name: 'John') ----- - -[#references-rspecstringasinstancedoubleconstant] -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StringAsInstanceDoubleConstant - -[#rspecstubbedmock] == RSpec/StubbedMock |=== @@ -5961,7 +5511,6 @@ instance_double(User, name: 'John') Checks that message expectations do not have a configured response. -[#examples-rspecstubbedmock] === Examples [source,ruby] @@ -5974,12 +5523,10 @@ allow(foo).to receive(:bar).with(42).and_return("hello world") expect(foo).to receive(:bar).with(42) ---- -[#references-rspecstubbedmock] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StubbedMock -[#rspecsubjectdeclaration] == RSpec/SubjectDeclaration |=== @@ -5994,7 +5541,6 @@ expect(foo).to receive(:bar).with(42) Ensure that subject is defined using subject helper. -[#examples-rspecsubjectdeclaration] === Examples [source,ruby] @@ -6013,12 +5559,10 @@ let(:subject, &block) subject(:test_subject) { foo } ---- -[#references-rspecsubjectdeclaration] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectDeclaration -[#rspecsubjectstub] == RSpec/SubjectStub |=== @@ -6036,7 +5580,6 @@ Checks for stubbed test subjects. Checks nested subject stubs for innermost subject definition when subject is also defined in parent example groups. -[#examples-rspecsubjectstub] === Examples [source,ruby] @@ -6075,7 +5618,6 @@ describe Article do end ---- -[#references-rspecsubjectstub] === References * https://rspec.rubystyle.guide/#dont-stub-subject @@ -6083,7 +5625,6 @@ end * https://robots.thoughtbot.com/don-t-stub-the-system-under-test * https://penelope.zone/2015/12/27/introducing-rspec-smells-and-where-to-find-them.html#smell-1-stubjec -[#rspecundescriptiveliteralsdescription] == RSpec/UndescriptiveLiteralsDescription |=== @@ -6101,7 +5642,6 @@ Description should be descriptive. If example group or example contains only `execute string`, numbers and regular expressions, the description is not clear. -[#examples-rspecundescriptiveliteralsdescription] === Examples [source,ruby] @@ -6142,12 +5682,10 @@ it 'does something' do end ---- -[#references-rspecundescriptiveliteralsdescription] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/UndescriptiveLiteralsDescription -[#rspecunspecifiedexception] == RSpec/UnspecifiedException |=== @@ -6166,7 +5704,6 @@ Enforces one of an Exception type, a string, or a regular expression to match against the exception message as a parameter to `raise_error` -[#examples-rspecunspecifiedexception] === Examples [source,ruby] @@ -6192,12 +5729,10 @@ expect { expect { do_something }.not_to raise_error ---- -[#references-rspecunspecifiedexception] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/UnspecifiedException -[#rspecvariabledefinition] == RSpec/VariableDefinition |=== @@ -6212,10 +5747,8 @@ expect { do_something }.not_to raise_error Checks that memoized helpers names are symbols or strings. -[#examples-rspecvariabledefinition] === Examples -[#enforcedstyle_-symbols-_default_-rspecvariabledefinition] ==== EnforcedStyle: symbols (default) [source,ruby] @@ -6229,7 +5762,6 @@ subject(:user) { create_user } let(:user_name) { 'Adam' } ---- -[#enforcedstyle_-strings-rspecvariabledefinition] ==== EnforcedStyle: strings [source,ruby] @@ -6243,7 +5775,6 @@ subject('user') { create_user } let('user_name') { 'Adam' } ---- -[#configurable-attributes-rspecvariabledefinition] === Configurable attributes |=== @@ -6254,12 +5785,10 @@ let('user_name') { 'Adam' } | `symbols`, `strings` |=== -[#references-rspecvariabledefinition] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableDefinition -[#rspecvariablename] == RSpec/VariableName |=== @@ -6277,10 +5806,8 @@ Checks that memoized helper names use the configured style. Variables can be excluded from checking using the `AllowedPatterns` option. -[#examples-rspecvariablename] === Examples -[#enforcedstyle_-snake_case-_default_-rspecvariablename] ==== EnforcedStyle: snake_case (default) [source,ruby] @@ -6294,7 +5821,6 @@ subject(:user_name_1) { 'Adam' } let(:user_name_2) { 'Adam' } ---- -[#enforcedstyle_-camelcase-rspecvariablename] ==== EnforcedStyle: camelCase [source,ruby] @@ -6308,7 +5834,6 @@ subject(:userName1) { 'Adam' } let(:userName2) { 'Adam' } ---- -[#allowedpatterns-configuration-rspecvariablename] ==== AllowedPatterns configuration [source,ruby] @@ -6327,7 +5852,6 @@ subject(:userFood_1) { 'spaghetti' } let(:userFood_2) { 'fettuccine' } ---- -[#configurable-attributes-rspecvariablename] === Configurable attributes |=== @@ -6342,12 +5866,10 @@ let(:userFood_2) { 'fettuccine' } | Array |=== -[#references-rspecvariablename] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableName -[#rspecverifieddoublereference] == RSpec/VerifiedDoubleReference |=== @@ -6357,22 +5879,19 @@ let(:userFood_2) { 'fettuccine' } | Yes | Always (Unsafe) | 2.10.0 -| 2.12 +| <> |=== Checks for consistent verified double reference style. -Only investigates references that are one of the supported styles. +=== Safety -This cop can be configured in your configuration using the -`EnforcedStyle` option and supports `--auto-gen-config`. +This cop is unsafe because the correction requires loading the class. +Loading before stubbing causes RSpec to only allow instance methods +to be stubbed. -[#examples-rspecverifieddoublereference] === Examples -[#_enforcedstyle_-constant_-_default_-rspecverifieddoublereference] -==== `EnforcedStyle: constant` (default) - [source,ruby] ---- # bad @@ -6386,24 +5905,7 @@ let(:foo) do end ---- -[#_enforcedstyle_-string_-rspecverifieddoublereference] -==== `EnforcedStyle: string` - -[source,ruby] ----- -# bad -let(:foo) do - instance_double(ClassName, method_name: 'returned_value') -end - -# good -let(:foo) do - instance_double('ClassName', method_name: 'returned_value') -end ----- - -[#reference-is-not-in-the-supported-style-list_-no-enforcement-rspecverifieddoublereference] -==== Reference is not in the supported style list. No enforcement +==== Reference is any dynamic variable. No enforcement [source,ruby] ---- @@ -6413,24 +5915,11 @@ let(:foo) do end ---- -[#configurable-attributes-rspecverifieddoublereference] -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| EnforcedStyle -| `constant` -| `constant`, `string` -|=== - -[#references-rspecverifieddoublereference] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubleReference * https://rspec.info/features/3-12/rspec-mocks/verifying-doubles -[#rspecverifieddoubles] == RSpec/VerifiedDoubles |=== @@ -6445,7 +5934,6 @@ end Prefer using verifying doubles over normal doubles. -[#examples-rspecverifieddoubles] === Examples [source,ruby] @@ -6466,7 +5954,6 @@ let(:foo) do end ---- -[#configurable-attributes-rspecverifieddoubles] === Configurable attributes |=== @@ -6481,14 +5968,12 @@ end | Boolean |=== -[#references-rspecverifieddoubles] === References * https://rspec.rubystyle.guide/#doubles * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubles * https://rspec.info/features/3-12/rspec-mocks/verifying-doubles -[#rspecvoidexpect] == RSpec/VoidExpect |=== @@ -6503,7 +5988,6 @@ end Checks void `expect()`. -[#examples-rspecvoidexpect] === Examples [source,ruby] @@ -6515,12 +5999,10 @@ expect(something) expect(something).to be(1) ---- -[#references-rspecvoidexpect] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VoidExpect -[#rspecyield] == RSpec/Yield |=== @@ -6535,7 +6017,6 @@ expect(something).to be(1) Checks for calling a block within a stub. -[#examples-rspecyield] === Examples [source,ruby] @@ -6547,7 +6028,6 @@ allow(foo).to receive(:bar) { |&block| block.call(1) } expect(foo).to receive(:bar).and_yield(1) ---- -[#references-rspecyield] === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Yield diff --git a/lib/rubocop/cop/rspec/string_as_instance_double_constant.rb b/lib/rubocop/cop/rspec/string_as_instance_double_constant.rb deleted file mode 100644 index c7a346821..000000000 --- a/lib/rubocop/cop/rspec/string_as_instance_double_constant.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - # Do not use a string as `instance_double` constant. - # - # @safety - # This cop is unsafe because the correction requires loading the class. - # Loading before stubbing causes RSpec to only allow instance methods - # to be stubbed. - # - # @example - # # bad - # instance_double('User', name: 'John') - # - # # good - # instance_double(User, name: 'John') - # - class StringAsInstanceDoubleConstant < Base - extend AutoCorrector - - MSG = 'Do not use a string as `instance_double` constant.' - RESTRICT_ON_SEND = %i[instance_double].freeze - - # @!method stringified_instance_double_const?(node) - def_node_matcher :stringified_instance_double_const?, <<~PATTERN - (send nil? :instance_double $str ...) - PATTERN - - def on_send(node) - stringified_instance_double_const?(node) do |args_node| - add_offense(args_node) do |corrector| - autocorrect(corrector, args_node) - end - end - end - - def autocorrect(corrector, node) - corrector.replace(node, node.value) - end - end - end - end -end diff --git a/lib/rubocop/cop/rspec/verified_double_reference.rb b/lib/rubocop/cop/rspec/verified_double_reference.rb index b4f6e8d38..1a3621a26 100644 --- a/lib/rubocop/cop/rspec/verified_double_reference.rb +++ b/lib/rubocop/cop/rspec/verified_double_reference.rb @@ -5,14 +5,14 @@ module Cop module RSpec # Checks for consistent verified double reference style. # - # Only investigates references that are one of the supported styles. - # # @see https://rspec.info/features/3-12/rspec-mocks/verifying-doubles # - # This cop can be configured in your configuration using the - # `EnforcedStyle` option and supports `--auto-gen-config`. + # @safety + # This cop is unsafe because the correction requires loading the class. + # Loading before stubbing causes RSpec to only allow instance methods + # to be stubbed. # - # @example `EnforcedStyle: constant` (default) + # @example # # bad # let(:foo) do # instance_double('ClassName', method_name: 'returned_value') @@ -23,18 +23,7 @@ module RSpec # instance_double(ClassName, method_name: 'returned_value') # end # - # @example `EnforcedStyle: string` - # # bad - # let(:foo) do - # instance_double(ClassName, method_name: 'returned_value') - # end - # - # # good - # let(:foo) do - # instance_double('ClassName', method_name: 'returned_value') - # end - # - # @example Reference is not in the supported style list. No enforcement + # @example Reference is any dynamic variable. No enforcement # # # good # let(:foo) do @@ -42,9 +31,9 @@ module RSpec # end class VerifiedDoubleReference < Base extend AutoCorrector - include ConfigurableEnforcedStyle - MSG = 'Use a %