title: TDD(iOS) SUT fails when I don't make a local variable and run some operation
body: <p>I have written a test and in my test a <code>router</code> spy routes to the next logic of my app. using <code>start()</code> function. When I directly call <code>start</code> function on my <code>makeSUT</code> function test fails. However when I make a local SUT variable and then call start function test passes. I think it might be that my escaping closure <code>self</code> gets nil or something however I am not sure. Please do let me know so I can understand what's happening under the hood</p>
  <p>Here's the code.</p>
  <pre><code>class FlowTest: XCTestCase {
      
      var router: RouterSpy!
  
      func makeSUT(questions: [String]) -&gt; Flow {
          router = RouterSpy()
          return  Flow(questions: questions, router: router);
      }
  
      // THIS Test FAILS WHEN I DO makeSUT(questions: [&quot;First One&quot;, &quot;Second&quot;, &quot;Third&quot;]).start()
  
      func test_startAndAnswerFirstAndSecondQuestion_withTwoQuestions_routeToSecondAndThirdQuestion(){
          let sut = makeSUT(questions: [&quot;First One&quot;, &quot;Second&quot;, &quot;Third&quot;])
          sut.start()
          router.answerCallback(&quot;A1&quot;)
          router.answerCallback(&quot;A2&quot;)
          XCTAssertEqual(router.routedQuestions, [&quot;First One&quot;, &quot;Second&quot;,&quot;Third&quot;])
      }
  
      class RouterSpy: Router {
          
          
          var routedQuestions: [String] = []
          var answerCallback:  Router.AnswerCallback = {_ in}
          
          func routeTo(question: String,answerCallback: @escaping  Router.AnswerCallback) {
              routedQuestions.append(question)
              self.answerCallback = answerCallback
          }
      }
  }
  
  </code></pre>
  <p>Here's my Flow class and my Router Protocol</p>
  <pre><code>protocol Router {
      typealias AnswerCallback = (String) -&gt; Void
      func routeTo(question: String, answerCallback: @escaping AnswerCallback)
  }
  
  
  class Flow {
      private let router: Router
      private let questions: [String]
      
      init(questions: [String] = [], router: Router) {
          self.router = router
          self.questions = questions
      }
      
      func start() {
          if let firstQuestion = questions.first {
              self.router.routeTo(question: firstQuestion, answerCallback: routeNext(from : firstQuestion))
          }
      }
      
      private func routeNext(from question: String) -&gt; Router.AnswerCallback {
          return {  [weak self] _ in
              guard let self = self else {return}
              if let index = self.questions.firstIndex(of: question){
                  if index + 1 &lt; self.questions.count {
                      let nextQuestion = self.questions[index + 1]
                      self.router.routeTo(question: nextQuestion, answerCallback: self.routeNext(from : nextQuestion))
                  }
                  
              }
          }
      }
  }
  </code></pre>