Note that there are some explanatory texts on larger screens.

plurals
  1. POMocha Mock Carries To Another Test
    primarykey
    data
    text
    <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 "should get learn" do get 'learn' assert_response :success end test "learn passes a random word" 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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload