minitest - pass any argument to expect

minitest, ruby

Solution

According to the docs:

args is compared to the expected args using case equality (ie, the '===' operator), allowing for less specific expectations.

For instance,

mock = MiniTest::Mock.new
mock.expect(:perform_async, 'goodbye', [Integer, Integer, String])
puts mock.perform_async(1, 1, 'hello')  #=>goodbye 
puts mock.perform_async(1, 1, 1)  #=>MockExpectationError

Problem

I have the following code that I am using to mock a call to a class method: ``` def test_calls_update_profile_job_for_a_lead input = ContactInput.new valid_attributes mock = MiniTest::Mock.new use_case = CreateContact.new user, input, mock mock.expect(:perform_async, nil, [user.id, 1, ::Contact]) use_case.run! assert mock.verify end ``` The problem is that I am having to pass in the specific values - [user.id, 1, ::Contact] to make the test pass. Is there a way that I don't have to specify the exact values or maybe at least constrain what the arguments are. I don't want to check the exact arguments, I just want to make sure that the method was called.

Original source