title: Better way to test if method is called x times with MiniTest?
body: <p>Today I've started with some basic implementation of minitest and finally figured a way out to test if a method on a class is called twice.</p>
  
  <p>In RSpec I would do something like:</p>
  
  <pre><code>expect(@foo).to receive(:some_heavy_calculation).once
  2.times { @foo.bar }
  </code></pre>
  
  <p>Now, I've came up with the following implementation for MiniTest, but I'm not sure if this is the way to implement this, because this. Here's what I've got</p>
  
  <pre><code>require 'minitest/autorun'
  
  class Foo
    def bar
      @cached_value ||= some_heavy_calculation
    end
  
    def some_heavy_calculation
      "result"
    end
  end
  
  class FooTest &lt; Minitest::Test
    def setup
      @foo = Foo.new
    end
  
    def cache_the_value_when_calling_bar_twice
      mock = Minitest::Mock.new
      mock.expect(:some_heavy_calculation, [])
      @foo.stub :some_heavy_calculation, -&gt; { mock.some_heavy_calculation } do
        2.times { assert_equal_set @foo.bar, [] }
      end
      mock.verify
    end
  end
  </code></pre>
  
  <p>Do I really have to implement this with a mock, which will be the result of the stub of the subject on the method that has to be called x times?</p>