<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Mocking with Ruby - a question of&#160;syntax</title>
	<atom:link href="http://www.magpiebrain.com/blog/2005/06/19/mocking-with-ruby-a-question-of-syntax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.magpiebrain.com/blog/2005/06/19/mocking-with-ruby-a-question-of-syntax/</link>
	<description>Sam Newman's blog</description>
	<pubDate>Sat, 05 Jul 2008 00:44:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: James Mead</title>
		<link>http://www.magpiebrain.com/blog/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-2879</link>
		<dc:creator>James Mead</dc:creator>
		<pubDate>Fri, 01 Sep 2006 18:09:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-2879</guid>
		<description>"Mocha":http://mocha.rubyforge.org builds on SchMock and allows you to mock methods on real (non-mock) objects and classes.</description>
		<content:encoded><![CDATA[<p><a href="http://mocha.rubyforge.org" onclick="javascript:pageTracker._trackPageview('/outbound/comment/mocha.rubyforge.org');">Mocha</a> builds on SchMock and allows you to mock methods on real (non-mock) objects and classes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Griffiths</title>
		<link>http://www.magpiebrain.com/blog/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-779</link>
		<dc:creator>Ben Griffiths</dc:creator>
		<pubDate>Sun, 26 Jun 2005 17:45:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-779</guid>
		<description>Schmock (http://rubyforge.org/projects/schmock/) is a very simple ruby mocking implementation that we knocked together in developing our apps. Nothing special, but a bit like jmock.
</description>
		<content:encoded><![CDATA[<p>Schmock (http://rubyforge.org/projects/schmock/) is a very simple ruby mocking implementation that we knocked together in developing our apps. Nothing special, but a bit like jmock.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nat</title>
		<link>http://www.magpiebrain.com/blog/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-778</link>
		<dc:creator>Nat</dc:creator>
		<pubDate>Mon, 20 Jun 2005 16:57:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-778</guid>
		<description>I would prefer the returns stuff to be outside the block.  E.g.:

  expect 1 { m.do_something() }.returns 10
  expect (at_least 1) { m.do_something_else() }.returns 20

That makes the expected call really distinct from the action.

I don't care about typing expect more than once if the resulting code is easier to read.</description>
		<content:encoded><![CDATA[<p>I would prefer the returns stuff to be outside the block.  E.g.:</p>
<p>  expect 1 { m.do_something() }.returns 10<br />
  expect (at_least 1) { m.do_something_else() }.returns 20</p>
<p>That makes the expected call really distinct from the action.</p>
<p>I don&#8217;t care about typing expect more than once if the resulting code is easier to read.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Newman</title>
		<link>http://www.magpiebrain.com/blog/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-777</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Mon, 20 Jun 2005 10:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-777</guid>
		<description>The _syntax_ (as far as Ruby goes) is fine - the problem is the implementation. With your second example, how to you determine which mock is having the expectations defined on it? The idea of having the mock _inside_ the expectaion block is so you can then have a single expectation block for your test. If having such a block doesn't help readability (or the implementation is too complex), then I'd favour your first example.</description>
		<content:encoded><![CDATA[<p>The <em>syntax</em> (as far as Ruby goes) is fine &#8211; the problem is the implementation. With your second example, how to you determine which mock is having the expectations defined on it? The idea of having the mock <em>inside</em> the expectaion block is so you can then have a single expectation block for your test. If having such a block doesn&#8217;t help readability (or the implementation is too complex), then I&#8217;d favour your first example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.magpiebrain.com/blog/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-776</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Mon, 20 Jun 2005 09:26:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/06/19/mocking-with-ruby-a-question-of-syntax/#comment-776</guid>
		<description>I've been having great fun in work recently playing around with the way we write tests, and as my colleague Mike said, developers spend more time reading code than writing it. Hence it makes sense to use the more readable approach to your mocking framework.

Whilst I use JMock and find it by far the best mock object implementation out there... I still find it has rather a lot of fluff around it. Particularly when more than one method call is made to an object.

With that said, I'd be tempted by the last syntax, except that I'd pull the mock object out hence:

mock1.expect{
   halve(eq(10)).returns(5)
}

however, it may be made more readable by using something similar to your first effort:

expect {
  :given =&#62; 10,
  :halve,
  :returns =&#62; 5
}

I've never coded Ruby, so forgive me if any of the syntax is incorrect, but I hope it kind of still makes sense.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been having great fun in work recently playing around with the way we write tests, and as my colleague Mike said, developers spend more time reading code than writing it. Hence it makes sense to use the more readable approach to your mocking framework.</p>
<p>Whilst I use JMock and find it by far the best mock object implementation out there&#8230; I still find it has rather a lot of fluff around it. Particularly when more than one method call is made to an object.</p>
<p>With that said, I&#8217;d be tempted by the last syntax, except that I&#8217;d pull the mock object out hence:</p>
<p>mock1.expect{</p>
<p>   halve(eq(10)).returns(5)<br />
}</p>
<p>however, it may be made more readable by using something similar to your first effort:</p>
<p>expect {</p>
<p>  :given => 10,<br />
  :halve,<br />
  :returns => 5<br />
}</p>
<p>I&#8217;ve never coded Ruby, so forgive me if any of the syntax is incorrect, but I hope it kind of still makes sense.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
