Skip to content

Commit a0756eb

Browse files
authored
Merge pull request rails#55075 from EduardoGHdez/docs/assert-difference-notes
docs: Adding example to assert_difference method
2 parents fc55e5b + 228de01 commit a0756eb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

activesupport/lib/active_support/testing/assertions.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ def assert_nothing_raised
7171
# post :delete, params: { id: ... }
7272
# end
7373
#
74-
# An array of expressions can also be passed in and evaluated.
74+
# An array of expressions can be passed in and evaluated.
7575
#
7676
# assert_difference [ 'Article.count', 'Post.count' ], 2 do
7777
# post :create, params: { article: {...} }
7878
# end
7979
#
80-
# A hash of expressions/numeric differences can also be passed in and evaluated.
80+
# A hash of expressions/numeric differences can be passed in and evaluated.
8181
#
82-
# assert_difference ->{ Article.count } => 1, ->{ Notification.count } => 2 do
82+
# assert_difference({ 'Article.count' => 1, 'Notification.count' => 2 }) do
8383
# post :create, params: { article: {...} }
8484
# end
8585
#
86-
# A lambda or a list of lambdas can be passed in and evaluated:
86+
# A lambda, a list of lambdas or a hash of lambdas/numeric differences can be passed in and evaluated:
8787
#
8888
# assert_difference ->{ Article.count }, 2 do
8989
# post :create, params: { article: {...} }
@@ -93,6 +93,10 @@ def assert_nothing_raised
9393
# post :create, params: { article: {...} }
9494
# end
9595
#
96+
# assert_difference ->{ Article.count } => 1, ->{ Notification.count } => 2 do
97+
# post :create, params: { article: {...} }
98+
# end
99+
#
96100
# An error message can be specified.
97101
#
98102
# assert_difference 'Article.count', -1, 'An Article should be destroyed' do

0 commit comments

Comments
 (0)