I've been recruited as a SW Dev and I'm trying to get into Unit Testing with RSPEC and RR in ruby but having an hard time deciding on a specific strategy mainly because I was assigned to write unit tests to a code which is already written.
Consider the following code which is a part of a big method called method1:
if (["5234541252", "6236253223"].include?(self.id))
self.DoCheck
logs.add 'Doing check', "id = #{self.id}"
return
end
The relevant unit test for this part of the method would've been something like:
"should do check only if id = 5234541252 or 6236253223"
But i'm running into a few questions, basically involving best practices, for example:
How can I check if DoCheck has been called from within "method1" using RR and RSPEC?
I've tried using dont_allow(Object).DoCheck but it won't work.
describe :do_route do
it "should do check only if id = 5234541252 or 6236253223" do
user = Factory(:User)
user.id = "5234541252"
dont_allow(user).DoCheck
user.method1
end
Is there any other way to conclude if "DoCheck" was called or not?