aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing
diff options
context:
space:
mode:
authorbogdanvlviv <bogdanvlviv@gmail.com>2018-10-25 19:06:21 +0300
committerbogdanvlviv <bogdanvlviv@gmail.com>2018-10-25 21:29:39 +0300
commit9d0cf52096dd6f7cb4b153984630eed97dcd8a8c (patch)
tree009d3e5539acdbf0da3bc08797cbc8442b0e051e /activesupport/lib/active_support/testing
parenta3dcba42e2422eb9c2e77011a39ce72dc934b420 (diff)
downloadrails-9d0cf52096dd6f7cb4b153984630eed97dcd8a8c.tar.gz
rails-9d0cf52096dd6f7cb4b153984630eed97dcd8a8c.tar.bz2
rails-9d0cf52096dd6f7cb4b153984630eed97dcd8a8c.zip
`assert_called_with` should require `args` argument
There are two main reasons why `assert_called_with` should require `args` argument: 1) If we want to assert that some method should be called and we don't need to check with which arguments it should be called then we should use `assert_called`. 2) `assert_called_with` without `args` argument doesn't assert anything! ```ruby assert_called_with(@object, :increment) do @object.decrement end ``` It causes false assertions in tests that could cause regressions in the project. I found this bug by working on [minitest-mock_expectations](https://github.com/bogdanvlviv/minitest-mock_expectations) gem. This gem is an extension for minitest that provides almost the same method call assertions. I was wondering whether you would consider adding "minitest-mock_expectations" to `rails/rails` instead of private `ActiveSupport::Testing::MethodCallAssertions` module. If yes, I'll send a patch - https://github.com/bogdanvlviv/rails/commit/a970ecc42c3a9637947599f2c13e3762e4b59208
Diffstat (limited to 'activesupport/lib/active_support/testing')
-rw-r--r--activesupport/lib/active_support/testing/method_call_assertions.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/testing/method_call_assertions.rb b/activesupport/lib/active_support/testing/method_call_assertions.rb
index fdc70e1cd3..eba41aa907 100644
--- a/activesupport/lib/active_support/testing/method_call_assertions.rb
+++ b/activesupport/lib/active_support/testing/method_call_assertions.rb
@@ -17,7 +17,7 @@ module ActiveSupport
assert_equal times, times_called, error
end
- def assert_called_with(object, method_name, args = [], returns: nil)
+ def assert_called_with(object, method_name, args, returns: nil)
mock = Minitest::Mock.new
if args.all? { |arg| arg.is_a?(Array) }