title: Mocha Mock Carries To Another Test
body: <p>I have been following the <a href="http://andrzejonsoftware.blogspot.com/2007/05/15-tdd-steps-to-create-rails.html" rel="noreferrer" title="15 TDD steps to create a Rails application">15 TDD steps to create a Rails application</a> guide - but have run into an issue I cannot seem to resolve.  For the functional test of the WordsController, I have the following code:</p>
  <pre><code>class WordsControllerTest &lt; ActionController::TestCase
    
    test &quot;should get learn&quot; do
      get 'learn'
      assert_response :success
    end
  
    test &quot;learn passes a random word&quot; do    
      some_word = Word.new
      Word.expects(:random).returns(some_word)
      get 'learn'
      assert_equal some_word, assigns('word')
    end
  end
  </code></pre>
  <p>In the Word class I have the following code:</p>
  <pre><code>class Word &lt; ActiveRecord::Base
    def self.random
      all = Word.find :all
      all[rand(all.size)]
    end
  end
  </code></pre>
  <p>When I run the tests, I experience the following error (shortened for brevity):</p>
  <pre><code>1) Failure: unexpected invocation: Word(...).random() satisfied expectations:
  - expected exactly once, already invoked once: Word(...).random()
  </code></pre>
  <p>I have tried changing changing the order of the tests along with a multitude of other things, but time and time again I continue to receive the same test failure - that Word.random() has already been invoked.</p>
  <p>I'm running Rails 3.0 beta 4 and Mocha 0.9.8. I've searched long and hard for a solution to my problem, but I can't seem to find it.  I'm new to Ruby/Rails so am rather unfamiliar with the language and the frameworks.</p>
  <p>Thanks in advance!</p>