<br><br><div><span class="gmail_quote">On 13/10/06, <b class="gmail_sendername">Tim Case</b> <<a href="mailto:gk@karmacrash.com">gk@karmacrash.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi James, thanks for your help I installed mocha as a rails plugin from<br>revision 70.<br><br>the checkout action calls process order:<br><br><br> def checkout<br> @order = Order.new_order(@store.bill_type.name, params[:order])
<br> @customer = find_or_create_customer<br> @order.store = @store<br> @line_items = @cart.line_items<br> @order.line_items << @cart.line_items<br> if @order.valid? and @customer.valid?<br> process_order
<br> else<br> append_to_order_errors @customer.errors<br> render_errors_in_order_summary<br> end<br> end<br><br> def process_order<br> if @order.process and @order.successful? #<---This is what I want
<br>to stub<br> @cart.empty!<br> if customer_logged_in?<br> flash[:notice] = "Checkout was successful."<br> else<br> flash[:notice] = "Checkout was successful, and your account was
<br>created."<br> end<br> redirect_to_order_confirmation @<a href="http://order.id">order.id</a><br> return<br> else<br> render_errors_in_order_summary<br> end<br> end<br><br>@order.successful
? is what I would like to return a true when I specify<br>it and at times false when I specify it.<br></blockquote></div><br>Hi Tim,<br><br>I still can't see anything obviously wrong - although my brain is in Friday afternoon mode. I've created a new Rails project and installed the same version of the plugin as you and I've tried some simple tests to try and replicate what you're seeing, but with no luck. I'm using version Rails
1.0.0 - what version are you using?<br><br><span style="font-family: courier new,monospace;">@order</span> should be a real <span style="font-family: courier new,monospace;">Order</span> unless you are doing some other mocking out in a
<span style="font-family: courier new,monospace;">setup()</span> method. Do you have any other setup code? The error you are seeing implies that <span style="font-family: courier new,monospace;">@order</span> is a mock object and not a real object - it is saying that there has been an unexpected call to the
<span style="font-family: courier new,monospace;">successful?</span> method. You can generate the same error by doing something like this...<br><br><span style="font-family: courier new,monospace;"> def test_me</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> order = mock()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> order.successful?</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> end</span><br style="font-family: courier new,monospace;"><br>But it should <span style="text-decoration: underline;">not</span> be possible to get the same error on a real object.
<br><br>I suggest you add the following line at the top of the process_order() method...<br><br><span style="font-family: courier new,monospace;"> p @order</span><br style="font-family: courier new,monospace;"><br>An then we can see whether its a mock or a real object.
<br clear="all"><br>The only other thing I can think of is that Mocha might not be clearing up correctly after itself between tests. Do you get the same error if you comment out all the other test methods in that <span style="font-family: courier new,monospace;">
TestCase</span>?<br>-- <br>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org</a>