@@ -181,12 +181,24 @@ def assert_no_difference(expression, message = nil, &block)
181
181
#
182
182
# The keyword arguments +:from+ and +:to+ can be given to specify the
183
183
# expected initial value and the expected value after the block was
184
- # executed.
184
+ # executed. The comparison is done using case equality (===), which means
185
+ # you can specify patterns or classes:
185
186
#
187
+ # # Exact value match
186
188
# assert_changes :@object, from: nil, to: :foo do
187
189
# @object = :foo
188
190
# end
189
191
#
192
+ # # Case equality
193
+ # assert_changes -> { user.token }, to: /\w{32}/ do
194
+ # user.generate_token
195
+ # end
196
+ #
197
+ # # Type check
198
+ # assert_changes -> { current_error }, from: nil, to: RuntimeError do
199
+ # raise "Oops"
200
+ # end
201
+ #
190
202
# An error message can be specified.
191
203
#
192
204
# assert_changes -> { Status.all_good? }, 'Expected the status to be bad' do
@@ -238,12 +250,24 @@ def assert_changes(expression, message = nil, from: UNTRACKED, to: UNTRACKED, &b
238
250
# end
239
251
#
240
252
# Provide the optional keyword argument +:from+ to specify the expected
241
- # initial value.
253
+ # initial value. The comparison is done using case equality (===), which means
254
+ # you can specify patterns or classes:
242
255
#
256
+ # # Exact value match
243
257
# assert_no_changes -> { Status.all_good? }, from: true do
244
258
# post :create, params: { status: { ok: true } }
245
259
# end
246
260
#
261
+ # # Case equality
262
+ # assert_no_changes -> { user.token }, from: /\w{32}/ do
263
+ # user.touch
264
+ # end
265
+ #
266
+ # # Type check
267
+ # assert_no_changes -> { current_error }, from: RuntimeError do
268
+ # retry_operation
269
+ # end
270
+ #
247
271
# An error message can be specified.
248
272
#
249
273
# assert_no_changes -> { Status.all_good? }, 'Expected the status to be good' do
0 commit comments