1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

added tests for assert_no_difference with multiple expressions

This commit is contained in:
lxxxvi 2018-07-08 15:15:16 +02:00
parent 1d97b8f9e4
commit 4baad7bec6
2 changed files with 28 additions and 0 deletions

View file

@ -113,11 +113,23 @@ module ActiveSupport
# post :create, params: { article: invalid_attributes }
# end
#
# A lambda can be passed in and evaluated.
#
# assert_no_difference -> { Article.count } do
# post :create, params: { article: invalid_attributes }
# end
#
# An error message can be specified.
#
# assert_no_difference 'Article.count', 'An Article should not be created' do
# post :create, params: { article: invalid_attributes }
# end
#
# An array of expressions can also be passed in and evaluated.
#
# assert_no_difference [ 'Article.count', -> { Post.count } ] do
# post :create, params: { article: invalid_attributes }
# end
def assert_no_difference(expression, message = nil, &block)
assert_difference expression, 0, message, &block
end

View file

@ -52,6 +52,22 @@ class AssertionsTest < ActiveSupport::TestCase
assert_equal "Object Changed.\n\"@object.num\" didn't change by 0.\nExpected: 0\n Actual: 1", error.message
end
def test_assert_no_difference_with_multiple_expressions_pass
another_object = @object.dup
assert_no_difference ["@object.num", -> { another_object.num }] do
# ...
end
end
def test_assert_no_difference_with_multiple_expressions_fail
another_object = @object.dup
assert_raises(Minitest::Assertion) do
assert_no_difference ["@object.num", -> { another_object.num }], "Another Object Changed" do
another_object.increment
end
end
end
def test_assert_difference
assert_difference "@object.num", +1 do
@object.increment