I have a rails controller which I would like to test a method test_method
.
class ActiveController < ActionController::Base
def test_method
user = acc_users.all_users.find params[:id]
if !user.active?
user.call_method!
end
end
end
I have to test that call_method
isn't being called. This is what I have come up with but I don't think this will work.
it "should not call call_method" do
u = user(@acc)
put :test_method, :id => u.id
expect(u).not_to have_received(:call_method!)
end
I followed this question here and found it almost similar except that the method being called is in another class. When I try this above code I get an error message like "expected Object to respond to has_received?
"
I believe I will not be able to test this with the given setup as the user is not being injected in the test_method
.
call_method
is a call to a method that enqueues a job so I want to be sure it doesn't get invoked.
How would I go about testing this method?