title: How do I stub a method of an instance only if a specific instance variable has a value?
body: <p>I have an object <code>MyObject</code>: </p>
  
  <pre><code>class MyObject
  
    def initialize(options = {})
      @stat_to_load = options[:stat_to_load] || 'test'
    end
  
    def results
     []
    end
  end
  </code></pre>
  
  <p>I want to stub the <code>results</code> method only if <code>stat_to_load = "times"</code>. How can I do that?  I tried: </p>
  
  <pre><code>MyObject.any_instance.stubs(:initialize).with({
    :stat_to_load =&gt; "times"
  }).stubs(:results).returns(["klala"])
  </code></pre>
  
  <p>but it does not work. Any idea?</p>