Skip to content

Commit 68bfe98

Browse files
committed
Update docs
1 parent 9c86416 commit 68bfe98

File tree

4 files changed

+69
-55
lines changed

4 files changed

+69
-55
lines changed

docs/modules/ROOT/pages/cops.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* xref:cops_rspec.adoc#rspecdescribesymbol[RSpec/DescribeSymbol]
2323
* xref:cops_rspec.adoc#rspecdescribedclass[RSpec/DescribedClass]
2424
* xref:cops_rspec.adoc#rspecdescribedclassmodulewrapping[RSpec/DescribedClassModuleWrapping]
25-
* xref:cops_rspec.adoc#rspecdiscardedmatcher[RSpec/DiscardedMatcher]
2625
* xref:cops_rspec.adoc#rspecdialect[RSpec/Dialect]
26+
* xref:cops_rspec.adoc#rspecdiscardedmatcher[RSpec/DiscardedMatcher]
2727
* xref:cops_rspec.adoc#rspecduplicatedmetadata[RSpec/DuplicatedMetadata]
2828
* xref:cops_rspec.adoc#rspecemptyexamplegroup[RSpec/EmptyExampleGroup]
2929
* xref:cops_rspec.adoc#rspecemptyhook[RSpec/EmptyHook]

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,55 +1129,6 @@ end
11291129
* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClassModuleWrapping
11301130
* https://github.com/rubocop/rubocop-rspec/issues/735
11311131
1132-
[#rspecdiscardedmatcher]
1133-
== RSpec/DiscardedMatcher
1134-
1135-
|===
1136-
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
1137-
1138-
| Enabled
1139-
| Yes
1140-
| No
1141-
| <<next_version>>
1142-
| -
1143-
|===
1144-
1145-
Checks for matchers that are used in void context.
1146-
1147-
Matcher calls like `change`, `receive`, etc. that appear as standalone
1148-
expressions have their result silently discarded. This usually means a
1149-
missing `.and` to chain compound matchers.
1150-
1151-
[#examples-rspecdiscardedmatcher]
1152-
=== Examples
1153-
1154-
[source,ruby]
1155-
----
1156-
# bad
1157-
specify do
1158-
expect { result }.to \
1159-
change { obj.foo }.from(1).to(2)
1160-
change { obj.bar }.from(3).to(4)
1161-
end
1162-
1163-
# good
1164-
specify do
1165-
expect { result }.to \
1166-
change { obj.foo }.from(1).to(2)
1167-
.and change { obj.bar }.from(3).to(4)
1168-
end
1169-
1170-
# good
1171-
specify do
1172-
expect { result }.to change { obj.foo }.from(1).to(2)
1173-
end
1174-
----
1175-
1176-
[#references-rspecdiscardedmatcher]
1177-
=== References
1178-
1179-
* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DiscardedMatcher
1180-
11811132
[#rspecdialect]
11821133
== RSpec/Dialect
11831134
@@ -1265,6 +1216,69 @@ end
12651216
12661217
* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect
12671218
1219+
[#rspecdiscardedmatcher]
1220+
== RSpec/DiscardedMatcher
1221+
1222+
|===
1223+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
1224+
1225+
| Pending
1226+
| Yes
1227+
| No
1228+
| <<next>>
1229+
| -
1230+
|===
1231+
1232+
Checks for matchers that are used in void context.
1233+
1234+
Matcher calls like `change`, `receive`, etc. that appear as
1235+
standalone expressions have their result silently discarded.
1236+
This usually means a missing `.and` to chain compound matchers.
1237+
1238+
The list of matcher methods can be configured
1239+
with `CustomMatcherMethods`.
1240+
1241+
[#examples-rspecdiscardedmatcher]
1242+
=== Examples
1243+
1244+
[source,ruby]
1245+
----
1246+
# bad
1247+
specify do
1248+
expect { result }
1249+
.to change { obj.foo }.from(1).to(2)
1250+
change { obj.bar }.from(3).to(4)
1251+
end
1252+
1253+
# good
1254+
specify do
1255+
expect { result }
1256+
.to change { obj.foo }.from(1).to(2)
1257+
.and change { obj.bar }.from(3).to(4)
1258+
end
1259+
1260+
# good
1261+
specify do
1262+
expect { result }.to change { obj.foo }.from(1).to(2)
1263+
end
1264+
----
1265+
1266+
[#configurable-attributes-rspecdiscardedmatcher]
1267+
=== Configurable attributes
1268+
1269+
|===
1270+
| Name | Default value | Configurable values
1271+
1272+
| CustomMatcherMethods
1273+
| `[]`
1274+
| Array
1275+
|===
1276+
1277+
[#references-rspecdiscardedmatcher]
1278+
=== References
1279+
1280+
* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DiscardedMatcher
1281+
12681282
[#rspecduplicatedmetadata]
12691283
== RSpec/DuplicatedMetadata
12701284

lib/rubocop/cop/rspec/discarded_matcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def on_send(node)
4747
check_discarded_matcher(node, node)
4848
end
4949

50-
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
50+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
5151
check_discarded_matcher(node.send_node, node)
5252
end
5353

spec/rubocop/cop/rspec/discarded_matcher_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,18 @@
158158
RUBY
159159
end
160160

161-
it 'does not register for `change` in modifier `if` without expect' do
161+
it 'does not register for `change` in modifier `if`' do
162162
expect_no_offenses(<<~RUBY)
163163
specify do
164-
change { obj.bar } if condition
164+
expect { result }.to change { obj.bar } if condition
165165
end
166166
RUBY
167167
end
168168

169-
it 'does not register for `change` in modifier `unless` without expect' do
169+
it 'does not register for `change` in modifier `unless`' do
170170
expect_no_offenses(<<~RUBY)
171171
specify do
172-
change { obj.bar } unless condition
172+
expect { result }.to change { obj.bar } unless condition
173173
end
174174
RUBY
175175
end

0 commit comments

Comments
 (0)