<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Yes, sorry.  I should have checked out trunk before sending you something :)<DIV><BR class="khtml-block-placeholder"></DIV><DIV>I do like the fluent interface that Mocha provides.  I was trying to think of something more readable and would allow you to return values and then raise.  I considered then_return and then_raise, but in the end neither seemed better than simply providing a comma delimited list.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Anyway, thanks for the response.</DIV><DIV>Jay</DIV><DIV><BR><DIV><DIV>On Sep 24, 2006, at 5:17 PM, James Mead wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite">On 22/09/06, <B class="gmail_sendername">Jay</B> &lt;<A href="mailto:jay@jayfields.com">jay@jayfields.com</A>&gt; 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;"> I recently needed the behavior of my object to change on subsequent<BR>method calls so I added the syntax above.<BR><BR>Here's the diff of changes I made:<BR><BR>Index: test/mocha/expectation_test.rb<BR>=================================================================== <BR>--- test/mocha/expectation_test.rb      (revision 854)<BR>+++ test/mocha/expectation_test.rb      (working copy)<BR>@@ -95,6 +95,12 @@<BR>      assert_equal 99, expectation.invoke<BR>    end<BR><BR>+  def test_should_return_values_in_order <BR>+    expectation = Expectation.new(:expected_method).returns(9).then(10)<BR>+    assert_equal 9, expectation.invoke<BR>+    assert_equal 10, expectation.invoke<BR>+  end<BR>+<BR>    def test_should_return_nil_if_no_value_specified <BR>      expectation = Expectation.new(:expected_method)<BR>      assert_nil expectation.invoke<BR>Index: lib/mocha/expectation.rb<BR>===================================================================<BR>--- lib/mocha/expectation.rb    (revision 854) <BR>+++ lib/mocha/expectation.rb    (working copy)<BR>@@ -21,7 +21,7 @@<BR>        @method_name = method_name<BR>        @count = 1<BR>        @parameters, @parameter_block = AlwaysEqual.new, nil<BR>-      @invoked, @return_value = 0, nil <BR>+      @invoked = 0<BR>        @backtrace = backtrace || caller<BR>      end<BR><BR>@@ -69,19 +69,29 @@<BR>      end<BR>      def returns(value)<BR>-      @return_value = value<BR>+      return_value &lt;&lt; value<BR>         self<BR>      end<BR>+<BR>+    def then(value)<BR>+      return_value &lt;&lt; value<BR>+      self<BR>+    end<BR>+<BR>+    def return_value<BR>+      @return_value ||= []<BR>+    end<BR><BR>      def raises(exception = RuntimeError, message = nil) <BR>-      @return_value = lambda{ raise exception, message }<BR>+      return_value &lt;&lt; lambda{ raise exception, message }<BR>        self<BR>      end<BR>      def invoke<BR>        @invoked += 1<BR>        yield(*@parameters_to_yield) if yield? and block_given? <BR>-      @return_value.is_a?(Proc) ? @return_value.call : @return_value<BR>+      this_return = return_value.size &gt; 1 ? return_value.shift :<BR>return_value.first<BR>+      this_return.is_a?(Proc) ? this_return.call : this_return <BR>      end<BR>      def verify<BR></BLOCKQUOTE></DIV><BR>Hi Jay,<BR><BR>Thanks for your patch and in particular for including a test. Interestingly I recently made a change (revision #55) to allow consecutive return values to be specified like this... <BR><BR><SPAN style="font-family: courier new,monospace;">  object = mock()</SPAN><BR style="font-family: courier new,monospace;"><SPAN style="font-family: courier new,monospace;">  object.expects(:expected_method).returns(:result1, :result2, :result3) </SPAN><BR style="font-family: courier new,monospace;"><SPAN style="font-family: courier new,monospace;">  </SPAN><BR style="font-family: courier new,monospace;"><SPAN style="font-family: courier new,monospace;">  object.expected_method # =&gt; :result1</SPAN><BR style="font-family: courier new,monospace;"><SPAN style="font-family: courier new,monospace;">  object.expected_method # =&gt; :result2</SPAN><BR style="font-family: courier new,monospace;"><SPAN style="font-family: courier new,monospace;">   object.expected_method # =&gt; :result3</SPAN><BR style="font-family: courier new,monospace;"><SPAN style="font-family: courier new,monospace;">  object.expected_method # =&gt; nil</SPAN><BR style="font-family: courier new,monospace;"> <BR>I wonder if this would be sufficient for your needs. Let me know what you think.<BR><BR>I hope to do a release in the next few days.<BR clear="all"><BR>Thanks.<BR>-- <BR>James.<BR><A href="http://blog.floehopper.org"> http://blog.floehopper.org</A><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">mocha-developer mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:mocha-developer@rubyforge.org">mocha-developer@rubyforge.org</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://rubyforge.org/mailman/listinfo/mocha-developer">http://rubyforge.org/mailman/listinfo/mocha-developer</A></DIV> </BLOCKQUOTE></DIV><BR></DIV></BODY></HTML>