On 13/10/06, <b class="gmail_sendername">Tim Case</b> <<a href="mailto:gk@karmacrash.com">gk@karmacrash.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi, I'm new to mocha and stubba but eager to learn. I have a rails<br>functional test in which I would like to stub an instance method of<br>particular class to always return true. I tried the following:<br><br>def test_post_checkout
<br> Order.any_instance.stubs(:successful?).returns(true)<br> post :checkout<br> assert_response :redirect<br> assert_equal "Checkout was successful.", flash[:notice]<br>end<br><br>I expected that the stub would help my test pass but instead it failed
<br>and the failure included the following:<br><br> test/functional/store_controller_test.rb:103:in `test_post_checkout']:<br>#<Mocha::Mock: 28754118>.successful?() - expected calls: 0, actual calls: 1<br><br>I was confused by this and it seemed to indicate that I need to tell
<br>Order that a call to #successful? was expected. Do I have to create a<br>mock in order to stub? How do I do this?<br><br>Thanks,<br><br>Tim Case<br><a href="mailto:tim@karmacrash.com">tim@karmacrash.com</a><br></blockquote>
</div><br>Hi Tim,<br><br>A first glance your test looks fine and it sounds like you understand how it should work. Can you send the code for your checkout action? Also can you tell me whether you are using the gem (which version?) or the Rails plugin (which revision?) - I've been making a few fairly big changes in HEAD recently and I may have inadvertantly introduced a bug to the Rails plugin.
<br clear="all">-- <br>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org</a>