diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-08-20 07:37:59 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-08-20 07:37:59 +0200 |
commit | c83b117d4b8b6e78ba503d2744b640cc71fd8e8f (patch) | |
tree | 931715ed35d97393500cae8a2a89fcaf28523f3f /activesupport | |
parent | 3ee7c5706fb81fda6cb138b3288a5039388e0b92 (diff) | |
parent | 63a70ad6ff3223e20ae27c6738dc6bc7d2c6c11c (diff) | |
download | rails-c83b117d4b8b6e78ba503d2744b640cc71fd8e8f.tar.gz rails-c83b117d4b8b6e78ba503d2744b640cc71fd8e8f.tar.bz2 rails-c83b117d4b8b6e78ba503d2744b640cc71fd8e8f.zip |
Merge pull request #21279 from ronakjangir47/test_cleanup
Cleaned up generators tests using internal assertion helper
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/testing/method_call_assertions.rb | 6 | ||||
-rw-r--r-- | activesupport/test/testing/method_call_assertions_test.rb | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/testing/method_call_assertions.rb b/activesupport/lib/active_support/testing/method_call_assertions.rb index 155d3344d3..fccaa54f40 100644 --- a/activesupport/lib/active_support/testing/method_call_assertions.rb +++ b/activesupport/lib/active_support/testing/method_call_assertions.rb @@ -1,11 +1,13 @@ +require 'minitest/mock' + module ActiveSupport module Testing module MethodCallAssertions # :nodoc: private - def assert_called(object, method_name, message = nil, times: 1) + def assert_called(object, method_name, message = nil, times: 1, returns: nil) times_called = 0 - object.stub(method_name, proc { times_called += 1 }) { yield } + object.stub(method_name, proc { times_called += 1; returns }) { yield } error = "Expected #{method_name} to be called #{times} times, " \ "but was called #{times_called} times" diff --git a/activesupport/test/testing/method_call_assertions_test.rb b/activesupport/test/testing/method_call_assertions_test.rb index 2939cf0233..3e5ba7c079 100644 --- a/activesupport/test/testing/method_call_assertions_test.rb +++ b/activesupport/test/testing/method_call_assertions_test.rb @@ -33,6 +33,12 @@ class MethodCallAssertionsTest < ActiveSupport::TestCase end end + def test_assert_called_returns + assert_called(@object, :increment, returns: 10) do + assert_equal 10, @object.increment + end + end + def test_assert_called_failure error = assert_raises(Minitest::Assertion) do assert_called(@object, :increment) do |