title: What is the best practice when it comes to testing "infinite loops"?
body: <p>My basic logic is to have an infinite loop running somewhere and test it as best as possible. The reason for having an infinite loop is not important (main loop for games, daemon-like logic...) and I'm more asking about best practices regarding a situation like that.</p>
  
  <p>Let's take this code for example:</p>
  
  <pre><code>module Blah
    extend self
  
    def run
       some_initializer_method
       loop do
          some_other_method
          yet_another_method
       end
    end
  end
  </code></pre>
  
  <p>I want to test the method <code>Blah.run</code> using Rspec (also I use <a href="https://github.com/btakita/rr" rel="noreferrer">RR</a>, but plain rspec would be an acceptable answer).</p>
  
  <p>I figure the best way to do it would be to decompose a bit more, like separating the loop into another method or something:</p>
  
  <pre><code>module Blah
    extend self
  
    def run
       some_initializer_method
       do_some_looping
    end
  
   def do_some_looping
     loop do
       some_other_method
       yet_another_method
     end
   end
  end
  </code></pre>
  
  <p>... this allows us to test <code>run</code> and mock the loop... but at some point the code inside the loop needs to be tested.</p>
  
  <p>So what would you do in such a situation? </p>
  
  <p>Simply not testing this logic, meaning test <code>some_other_method</code> &amp; <code>yet_another_method</code> but not <code>do_some_looping</code> ?</p>
  
  <p>Have the loop break at some point via a mock? </p>
  
  <p>... something else?</p>