title: ruby rr: How to stub/mock built-in variables like $?
body: <p>While writing a unit test for following:</p>
  
  <pre><code>def foo()
    popen_response = ""
    IO.popen(@packaging_cmd, :err=&gt;[:child, :out]) {|io| popen_response = io.read }
    rc = $?
    @log.debug{"Response from IO.popen() : #{popen_response}. rc: '#{rc}'"}
    if rc.exitstatus != 0
      @log.error{"Packaging failed. rc: '#{rc}'"}
      raise PackagingError.new("Packaging failed. rc: '#{rc}'")
    end
  end
  </code></pre>
  
  <p>I'm stuck because I don't know how to mock/stub what <code>$?</code> evaluates to. I can hack around by creating a function that returns <code>$?</code> and mock that function or tinker with teh command passed to <code>IO.popen()</code>, but I wonder if there is any official way in RR that I can use.</p>
  
  <p>I'm using <code>rr</code> with stock <code>Test::Unit::TestCase</code></p>
  
  <pre><code>require 'test/unit'
  require 'rr'
  </code></pre>