From: cremes.devlist@... Date: 2006-06-06T01:58:10+09:00 Subject: Re: Need help with TDD, stubs and mocks On Jun 5, 2006, at 10:57 AM, Jim Weirich wrote: > cr wrote: >> 4. How do you test a method that utilizes an instance variable that >> was set somewhere else? E.g. #methodA calculates @result. #methodB >> retrieves @second_result. #methodC compares @result and >> @second_result. > > Construct your test case so that methodA and methodB are called before > methodC does its work. > > Example: > > def test_comparison > thing = Thing.new > thing.methodA > thing.methodB > assert_equal ExpectedResult, thing.methodC > end Jim, thanks for your response. I do need some additional clarification on this final point. The way I see your answer, you are NOT suggesting I pass instance variables as parameters. Instead, I should enforce the order of operations for my methods and allow them "global" (in this class instance) access to the instance variables. I still see this as somewhat problematic if there is a long chain of "custody" in between where the instance variable gets set and where it gets used again by a later method. I'll have to think on this a bit more. BTW, I really appreciated the distinctions you made on mocks versus stubs. I think I get it now. Now all I need to do is repeat this a thousand times to imprint it on my brain. Time to test! cr