Thanks for clearing things up Pat!<div>I&#39;ll give the story stuff I try, I haven&#39;t looked at it yet.</div><div><br class="webkit-block-placeholder"></div><div>Does this actually mean I need to start describing some stories, then start with writing the examples/code for the first story by using mock objects for every layer?&nbsp;
</div><div>Do I eventually need to replace all the mocks by real objects?</div><div>And is it bad to do partially stubbing on objects, or does this indicate an object should provide more information about its state?</div>
<div><br class="webkit-block-placeholder"></div><div>For instance, take a look at this pastie&nbsp;<a href="http://pastie.caboo.se/102174">http://pastie.caboo.se/102174</a>, is this a good way to write an example for a behaviour or am I taking a wrong approach?
</div><div><br class="webkit-block-placeholder"></div><div>I feel the need for some small, simple, clean example programs, to take a look through.</div><div>Maybe, I just need to put my current pet project online and let people shoot at it.
</div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div>- Matthijs&nbsp;</div><div><br class="webkit-block-placeholder"></div><div><br><div><span class="gmail_quote">On 9/30/07, 
<b class="gmail_sendername">Pat Maddox</b> &lt;<a href="mailto:pergesu@gmail.com">pergesu@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
On 9/29/07, Matthijs Langenberg &lt;<a href="mailto:mlangenberg@gmail.com">mlangenberg@gmail.com</a>&gt; wrote:<br>&gt; Many posts on this list are about using RSpec with Rails and that&#39;s the way<br>&gt; I&#39;m also using RSpec all the time.
<br>&gt; Unfortunately there isn&#39;t that much info about using RSpec for standalone<br>&gt; Ruby projects.<br><br>I don&#39;t think that matters much, the principles are the same.&nbsp;&nbsp;You<br>write stories for features, and write specs to drive object
<br>implementation.&nbsp;&nbsp;In fact I would say that Rails presents some unique<br>challenges for BDDing, and that a &quot;pure&quot; ruby project is easier!<br><br>&gt; I must admit I&#39;m really having a hard time writing the very first example(s)
<br>&gt; for a fresh standalone Ruby project. I haven&#39;t really got a clue where to<br>&gt; start, how to call the first example and how to describe it.<br><br>Begin at the beginning :P<br><br>There are a couple approaches.&nbsp;&nbsp;First thing I would do is write a
<br>story for one feature you want in the system.&nbsp;&nbsp;Having that story means<br>that you stay focused on one particular task and building the<br>infrastructure that will be used.&nbsp;&nbsp;I actually wrote a blog post a<br>while back on what I call &quot;design deep, not wide&quot;&nbsp;&nbsp;[1]
<br><br>On a simpler level, stories represent real progress.&nbsp;&nbsp;When you&#39;re done<br>with a story you should have actual value, and that is fulfilling and<br>motivating.<br><br>Also, you can start with smaller stories and build out from there.&nbsp;&nbsp;In
<br>Dan North&#39;s article about introducing rbehave [2] he works with simple<br>objects instead of a full application stack like you might in Rails.<br>When I first read it, I thought a standard spec might be more<br>appropriate.&nbsp;&nbsp;Once it hit me though (which was a couple months later),
<br>I fell in love with that approach.<br><br>To give you an idea, here&#39;s the starting code:<br><br>Story &quot;transfer to cash account&quot;,<br>%(As a savings account holder<br>&nbsp;&nbsp;I want to transfer money from my savings account
<br>&nbsp;&nbsp;So that I can get cash easily from an ATM) do<br><br>&nbsp;&nbsp;Scenario &quot;savings account is in credit&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp;Given &quot;my savings account balance is&quot;, 100<br>&nbsp;&nbsp;&nbsp;&nbsp;Given &quot;my cash account balance is&quot;, 10
<br>&nbsp;&nbsp;&nbsp;&nbsp;When &quot;I transfer&quot;, 20<br>&nbsp;&nbsp;&nbsp;&nbsp;Then &quot;my savings account balance should be&quot;, 80<br>&nbsp;&nbsp;&nbsp;&nbsp;Then &quot;my cash account balance should be&quot;, 30<br>&nbsp;&nbsp;end<br><br>&nbsp;&nbsp;Scenario &quot;savings account is overdrawn&quot; do
<br>&nbsp;&nbsp;&nbsp;&nbsp;Given &quot;my savings account balance is&quot;, -20<br>&nbsp;&nbsp;&nbsp;&nbsp;Given &quot;my cash account balance is&quot;, 10<br>&nbsp;&nbsp;&nbsp;&nbsp;When &quot;I transfer&quot;, 20<br>&nbsp;&nbsp;&nbsp;&nbsp;Then &quot;my savings account balance should be&quot;, -20
<br>&nbsp;&nbsp;&nbsp;&nbsp;Then &quot;my cash account balance should be&quot;, 10<br>&nbsp;&nbsp;end<br>end<br><br>Eventually he sticks objects in there as he implements them, but at<br>least at the very beginning there&#39;s no code to speak of.&nbsp;&nbsp;It&#39;s just a
<br>user story.&nbsp;&nbsp;The beauty of it is that all you&#39;re doing is specifying<br>acceptance criteria - what it means to be &quot;done.&quot;&nbsp;&nbsp;One scary part of<br>doing lower level specs is on some level you&#39;re designing code without
<br>any real sense of direction.&nbsp;&nbsp;You might not necessarily know what<br>objects you need.&nbsp;&nbsp;While specs are excellent for discovering the<br>behavior of objects, as far as what operations they perform and<br>interactions they have, they don&#39;t do much to help with the desired
<br>behavior of the system.<br><br>So, basically, writing stories forces you to think about what you want<br>to achieve, and gives you a clear way to measure progress.&nbsp;&nbsp;You know<br>where you want to end, and you know all the steps it takes to get
<br>there, and that gives you the knowledge of where to start.<br><br>&gt; I want to use the outside-in approach, but that suggests the first example<br>&gt; you write should specify the workings of the whole project, right?
<br>&gt; I alway catch myself focusing on dependancies and start from the inside<br>&gt; instead of the outside. (if I implement this first, I can use it as a<br>&gt; building brick for that feature, and if that feature is implemented I can
<br>&gt; work on that other feature.)<br><br>This is where mock objects yield their greatest benefits.&nbsp;&nbsp;A lot of<br>people think mock objects are good only for isolating expensive<br>resources, but they&#39;re fantastic in allowing you to design well in
<br>chunks.&nbsp;&nbsp;For example, something as simple as:<br><br>customer.place_order some_item, 12<br><br>Will require that I have a customer class, a place_order method, an<br>item class, and probably an order class somewhere.&nbsp;&nbsp;I&#39;m adding a
<br>little feature, and all of a sudden I have to implement all these<br>classes, at least in bits, and because I&#39;m only handling a little bit<br>of the behavior I don&#39;t have any idea how they&#39;re going to be used in
<br>other parts of the system.&nbsp;&nbsp;It&#39;s scary because there&#39;s more pressure<br>to get it right the first time.<br><br>mocks, otoh, allow you to defer all of that until later.&nbsp;&nbsp;When working<br>on a feature, I can concern myself only with that feature and not
<br>worry about all the plumbing that it may need.&nbsp;&nbsp;A couple things happen<br>there<br><br>1. I tend to end up with a clean, layered architecture.&nbsp;&nbsp;This happens<br>because I&#39;m only working on one layer at a time.&nbsp;&nbsp;When I&#39;m bouncing
<br>back and forth between layers, I have to be extra mindful of what I&#39;m<br>dealing with, otherwise stuff that should be in one layer creeps into<br>another and now I&#39;ve got a muddled, difficult to understand design.
<br>2. My life is easier!&nbsp;&nbsp;With mocks, I can isolate my thinking to a<br>certain level or chunk of the code.&nbsp;&nbsp;Instead of pushing and popping<br>all kinds of stuff on my mental stack, I limit the number of little<br>things I need to think about at one time.&nbsp;&nbsp;I wasn&#39;t blessed with
<br>unlimited brain space, so that&#39;s a huge win for me.&nbsp;&nbsp;It also creates<br>extra room to think about what I&#39;m doing at a higher level and keep<br>everything in perspective.<br><br>It&#39;s interesting, because your questions really boil down to being
<br>overwhelmed with what you have to do.&nbsp;&nbsp;It&#39;s a feeling I know all too<br>well.&nbsp;&nbsp;Fortunately RSpec provides two tools that do a fantastic job in<br>easing the uncertainty.&nbsp;&nbsp;First you have user stories which help give
<br>you direction in the project.&nbsp;&nbsp;You know what you want to get done,<br>have a good measure of progress as you implement it, and finally have<br>a clear understanding of when you&#39;ve completed it.&nbsp;&nbsp;On a lower level,<br>
mock objects help keep your thinking focused instead of running off in<br>all different directions writing the all the infrastructure that it<br>may take to write one line of code.&nbsp;&nbsp;You become less likely to code<br>yourself into a corner, and you keep your mental stack in check.
<br><br>I hope that was helpful.&nbsp;&nbsp;I completely understand sitting at the<br>keyboard wondering just what the hell I should be doing.&nbsp;&nbsp;I&#39;ve found<br>that RSpec helps me out a great deal both in terms of capturing<br>desired business outcomes and in implementing the code to achieve
<br>them.&nbsp;&nbsp;It can take a while to really get it, but you may come to find<br>that once you do you&#39;re hooked.<br><br>Pat<br><br>[1] <a href="http://evang.eli.st/blog/2006">http://evang.eli.st/blog/2006</a>/12/18/design-deep-not-wide
<br>[2] <a href="http://dannorth.net/2007/06">http://dannorth.net/2007/06</a>/introducing-rbehave<br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org">
rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman">http://rubyforge.org/mailman</a>/listinfo/rspec-users<br></blockquote></div><br></div>