module ActiveSupport::Testing::MethodCallAssertions

def assert_called(object, method_name, message = nil, times: 1, returns: nil, &block)

def assert_called(object, method_name, message = nil, times: 1, returns: nil, &block)
  times_called = 0
  object.stub(method_name, proc { times_called += 1; returns }, &block)
  error = "Expected #{method_name} to be called #{times} times, " \
    "but was called #{times_called} times"
  error = "#{message}.\n#{error}" if message
  assert_equal times, times_called, error
end