<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Robby on Rails: Tag bdd</title>
    <link>http://www.robbyonrails.com/articles/tag/bdd</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>Spec Your Views</title>
      <description>&lt;p&gt;I meant to work on this post&amp;#8230; oh about 7 months ago.&lt;/p&gt;


	&lt;p&gt;Way back in January (7 months ago), Jamis Buck posted an article titled, &lt;a href="http://weblog.jamisbuck.org/2007/1/29/testing-your-views"&gt;Testing your views&lt;/a&gt;, which gave a few tips on using Test::Unit to, as the title suggests, test your views.&lt;/p&gt;


	&lt;p&gt;While, I&amp;#8217;m not going to rewrite everything that Jamis wrote, I&amp;#8217;d like to show you how to test these views with RSpec. (you might take a moment to quickly read his post&amp;#8230;)&lt;/p&gt;


	&lt;p&gt;In this example, I&amp;#8217;m going to show you how we&amp;#8217;re able to write specs for the following &lt;span class="caps"&gt;RHTML&lt;/span&gt;, which  you&amp;#8217;ll notice matches the code that he wrote tests for.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  &amp;lt;% if @user.administrator? %&amp;gt;
    Hi &amp;lt;%= @user.name %&amp;gt;! You appear to be an administrator.
    &amp;lt;%= link_to "Click here", admin_url, :id =&amp;gt; "admin_link" %&amp;gt;
    to see the admin stuff!
  &amp;lt;% end %&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Jamis writes, &lt;em&gt;&amp;#8220;The only really significant thing you ought to be testing here is that the admin link only shows up for administrators. &amp;#8220;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;So, let&amp;#8217;s do just that, but with RSpec.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m not sure how Jamis is handling his view tests, but we&amp;#8217;re going to approach our view specs, much like we approach our controller specs, with the use of mocks and stubs, because we really don&amp;#8217;t need to spec any of our models at this level in the application.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Write specifications for your models&amp;#8230; in your model specs &lt;strong&gt;not&lt;/strong&gt; in your controller or view specs.&lt;/p&gt;


	&lt;p&gt;The first thing that we&amp;#8217;re going to do is setup a custom spec helper, because for something like an mocked user, will probably get reused in other areas of the user interface. Spec helpers are essentially modules that you can include in your RSpec descriptions (the block that starts with &lt;code&gt;describe&lt;/code&gt;) and reuse.&lt;/p&gt;


	&lt;p&gt;In this spec helper, I&amp;#8217;m going to include two methods, to mock the User model and stub out any of the methods that are necessary for spec&amp;#8217;n this view.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
module MockUserHelper
  def mock_normal_user
    user = mock(User)
    user.stub!(:administrator?).and_return(false)   # &amp;lt;--- NOT an admin
    user.stub!(:name).and_return('David Chelimsky')
    return user
  end

  def mock_admin_user
    user = mock(User)
    user.stub!(:administrator?).and_return(true)    # &amp;lt;--- IS an admin
    user.stub!(:name).and_return('Aslak Hellesoy')
    return user
  end
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;In the &lt;code&gt;mock_normal_user&lt;/code&gt; method, we&amp;#8217;re constructing a mock object and stubbing out the methods that we see are being called in the &lt;span class="caps"&gt;RHTML&lt;/span&gt; code. In &lt;code&gt;mock_admin_user&lt;/code&gt;, we&amp;#8217;re basically doing the same thing, but just stubbing the &lt;code&gt;administrator?&lt;/code&gt; method to return &lt;code&gt;true&lt;/code&gt; for this mock user.&lt;/p&gt;


	&lt;p&gt;By stubbing these methods, we&amp;#8217;ll be able to send a non-ActiveRecord object to the view and have it render without knowing the difference. For example, the &lt;code&gt;if @user.administrator?&lt;/code&gt; condition will return true or false, depending on how we stubbed it.&lt;/p&gt;


	&lt;p&gt;For more information on mocks and stubs, &lt;a href="http://rspec.rubyforge.org/documentation/mocks/index.html"&gt;read here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Now that we have our spec helper, let&amp;#8217;s go ahead and dive into a few specifications for the view.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
describe "index page" do
  include MockUserHelper

  it "should render an admin link for an admin user" do
    assigns[:user] = mock_admin_user
    render 'index'
    response.should have_tag('a#admin_link')
  end

  it "should not render an admin link for a normal, non-admin user" do
    assigns[:user] = mock_normal_user
    render 'index'
    response.should_not have_tag('a#admin_link')
  end
end  
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;strong&gt;Please note:&lt;/strong&gt; This code example is only longer than the one shown by Jamis because he didn&amp;#8217;t include how he setup all his user sessions/objects. ;-)&lt;/p&gt;


	&lt;p&gt;When these specs are run, we can see the following results.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/rspec_results-20070801-233809.jpg" alt="" /&gt;&lt;br /&gt;&lt;small&gt;Pretty output courtesy of RSpec + TextMate bundle&lt;/small&gt;&lt;/p&gt;


	&lt;p&gt;Great, we&amp;#8217;ve been able to write specifications for our Rails views without a lot of pain. Stay tuned for more posts on this topic as I continue writing about how Designers and Developers can work together, in harmony. (&lt;a href="http://www.robbyonrails.com/articles/2007/08/01/designers-developers-and-the-x_-factor"&gt;see my last post on this topic&lt;/a&gt;)&lt;/p&gt;


	&lt;p&gt;For more information on adopting RSpec, please visit the &lt;a href="http://rspec.rubyforge.org"&gt;RSpec project homepage&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Thu, 02 Aug 2007 02:00:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c21e25cf-1a4a-4b9f-a628-89fc00945829</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/08/02/spec-your-views</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>rails</category>
      <category>rubyonrails</category>
      <category>testing</category>
      <category>driven</category>
      <category>bdd</category>
      <category>rspec</category>
      <category>behavior</category>
      <category>mocks</category>
      <category>designers</category>
      <category>rhtml</category>
      <category>html</category>
      <category>specs</category>
    </item>
    <item>
      <title>All the cool kids are doing it... why aren't you?</title>
      <description>&lt;p&gt;&lt;a href="http://joshknowles.com/"&gt;Josh Knowles&lt;/a&gt; just mentioned an article written by David Chelminsky, titled, &lt;a href="http://blog.davidchelimsky.net/articles/2007/05/14/an-introduction-to-rspec-part-i"&gt;an introduction to RSpec &amp;#8211; Part I&lt;/a&gt;. In this article, David introduces you to some of &lt;a href="http://blog.davidchelimsky.net/articles/2007/03/11/describe-it-with-rspec"&gt;the new language&lt;/a&gt; that appeared in some of the recent versions of &lt;a href="http://rspec.rubyforge.org/"&gt;RSpec&lt;/a&gt; as well as give you a complete tutorial on building some specs.&lt;/p&gt;


	&lt;p&gt;Last night, I had the opportunity to sit down with &lt;a href="http://blog.aslakhellesoy.com/"&gt;Aslak Hellesøy&lt;/a&gt; and &lt;a href="http://blog.davidchelimsky.net/"&gt;David Chelimsky&lt;/a&gt; for a few hours and talk about my experiences of using RSpec at &lt;a href="http://www.planetargon.com/"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; and how it&amp;#8217;s helped us redefine and evolve our process. In particular, how RSpec  has helped us reshape our process of gathering user interaction specifications from our Interaction Design team and business rules from our clients.&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re in town and are using RSpec&amp;#8230; or are thinking about using RSpec&amp;#8230; and see these guys&amp;#8230; thank them for all the hard work that they&amp;#8217;re doing&amp;#8230; and of course, if you run into anybody else on &lt;a href="http://rspec.rubyforge.org/team.html"&gt;the team.&lt;/a&gt;.. do the same. :-)&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.flickr.com/photos/robbyrussell/501899079/" title="Photo Sharing"&gt;&lt;img src="http://farm1.static.flickr.com/202/501899079_5fc58f65fc.jpg" width="500" height="333" alt="Aslak Hellesøy and David Chelimsky" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;small&gt;Aslak Hellesøy and David Chelimsky&lt;/small&gt;&lt;/p&gt;


	&lt;p&gt;Also, by the end of the &lt;a href="http://railsconf.org"&gt;conference&lt;/a&gt;... &lt;a href="http://blog.imperialdune.com/"&gt;Graeme&lt;/a&gt; and I are hoping to have a small project done to help encourage more adoption of &lt;a href="http://behaviour-driven.org/"&gt;Behavior-Driven Development&lt;/a&gt;&lt;/p&gt;
</description>
      <pubDate>Thu, 17 May 2007 13:15:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:1237cc2b-8b0c-4a6d-bd3d-b32173b169df</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/05/17/all-the-cool-kids-are-doing-it-why-arent-you</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>rspec</category>
      <category>bdd</category>
      <category>aslak</category>
      <category>ruby</category>
      <category>rubyonrails</category>
      <category>railsconf</category>
    </item>
    <item>
      <title>You Might Learn Something at the Back of the Train</title>
      <description>&lt;p&gt;I love to look at other peoples code. Initially, that&amp;#8217;s what got me excited about Open Source software. Otherwise, I was looking at small snippets on various developer sites and really not getting the complete picture for how everything tied together.&lt;/p&gt;


	&lt;p&gt;Last night, I finally had a chance to checkout the &lt;a href="http://sample.caboo.se/"&gt;sample caboose application&lt;/a&gt;, which was created as a way for people to get an idea for how some of developers in &lt;a href="http://caboo.se"&gt;caboo.se&lt;/a&gt; are putting together their applications.&lt;/p&gt;


	&lt;p&gt;Some things that you might want to check out it&amp;#8217;s using&amp;#8230;&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://rspec.rubyforge.org/"&gt;RSpec&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://weblog.techno-weenie.net/2006/8/1/restful-authentication-plugin"&gt;RESTful Authentication&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://weblog.jamisbuck.org/2007/2/2/introducing-tztime"&gt;TzTime&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://blog.caboo.se/articles/2007/2/21/the-fabulous-spider-fuzz-plugin"&gt;SpiderTest&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;It&amp;#8217;s definitely worth taking 15 or so minutes to check it out and get some fresh ideas.&lt;/p&gt;


	&lt;p&gt;There are a few things that I&amp;#8217;m not quite sure that didn&amp;#8217;t quite make sense, so&amp;#8230; perhaps I&amp;#8217;ll submit a patch. :-)&lt;/p&gt;


	&lt;p&gt;&lt;code&gt;svn co svn://caboo.se/plugins/court3nay/empty_apps/tags/v_003&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;Have fun!&lt;/p&gt;
</description>
      <pubDate>Thu, 19 Apr 2007 11:13:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:5755dab3-9bd6-4f5b-802b-45dc499ab652</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/04/19/you-might-learn-something-at-the-back-of-the-train</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>caboose</category>
      <category>development</category>
      <category>rspec</category>
      <category>bdd</category>
      <category>restful</category>
    </item>
    <item>
      <title>BDD is still kinky</title>
      <description>&lt;p&gt;&lt;a href="http://flickr.com/photos/planetargon/447627473"&gt;&lt;img src="http://farm1.static.flickr.com/214/447627473_36d5614c82.jpg" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;I still believe that &lt;a href="http://www.robbyonrails.com/articles/2007/02/08/is-bdd-kinkier-than-tdd"&gt;Behavior-Driven Development is kinkier than Test-Driven Development&lt;/a&gt;...&lt;/p&gt;
</description>
      <pubDate>Tue, 10 Apr 2007 16:51:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:936e15de-98f3-41da-8ef2-895c8c6dbb0d</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/04/10/bdd-is-still-kinky</link>
      <category>Programming</category>
      <category>bdd</category>
      <category>tdd</category>
      <category>behavior</category>
      <category>driven</category>
      <category>agile</category>
      <category>development</category>
      <category>kinky</category>
      <category>rspec</category>
    </item>
    <item>
      <title>Embracing Failure, part 1</title>
      <description>&lt;p&gt;I&amp;#8217;m currently reading &lt;a href="http://www.amazon.com/Engineer-Human-Failure-Successful-Design/dp/0679734163"&gt;To Engineer is Human&lt;/a&gt;, by Henry Petroski and found the following applicable to software development and managing client and customer expectations.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;As much as it is human to make mistakes, it is also human to want to avoid them. Murphy&amp;#8217;s Law, holding that anything that can go wrong will, is not a law of nature but a joke. All the light bulbs that last until we tire of the lamp, all the shoelaces that outlast their shoes, all the automobiles that give trouble-free service until they are traded in have the last laugh on Murphy. Just as he will not outlive his law, so nothing manufactured can be or is expected to last forever. Once we recognize this elementary fact, the possibility of a machine or a building being as near to perfect for its designed lifetime as its creators may strive to be for theirs is not only a realistic goal but also a reasonable expectation for consumers. It is only when we set ourselves such an unrealistic goal as buying a shoelace that will never break, inventing a perpetual motion machine, or building a vehicle that will never break down that we appear to be fools and not rational beings.&amp;#8221;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;I&amp;#8217;m sure that most of us are guilty of having high expectations for products that we purchased. (why does my ipod screen scratch so easily when in my pocket?) We also set high expectations for the code that we develop, which is why we (hopefully) continue to refine our process. We&amp;#8217;re bound to time and budget constraints, which often prevent us from testing every imaginable edge case. Given our constraints, problems are almost always going to arise. It&amp;#8217;s no wonder that we see Test-Driven Development as an important part of a healthy development process. We want to catch our failures as early as possible.&lt;/p&gt;


	&lt;p&gt;Our clients often have high expectations and it&amp;#8217;s almost always very reasonable. That&amp;#8217;s not to say that some clients will not have highly irrational expectations. It&amp;#8217;s our job to manage these expectations as best as possible.&lt;/p&gt;


	&lt;p&gt;Do we mislead our clients by convincing them that our &lt;span class="caps"&gt;TDD&lt;/span&gt;/BDD process is going to prevent any bugs from creeping from the woodwork after the development cycle is finished?&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;&amp;#8220;I thought that we paid you to fully test the code?&amp;#8221;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;Really&amp;#8230; is that even possible? Can we predict (and test) every possible interaction within an application? Highly unlikely.&lt;/p&gt;


	&lt;p&gt;What we &lt;em&gt;can&lt;/em&gt; do is plan for and embrace failure. We can help our clients understand that almost every application needs to be &lt;em&gt;maintained&lt;/em&gt; after it&amp;#8217;s initial development cycle. Bugs are inevitable and there needs to be a &lt;a href="http://daringfireball.net/linked/2007/march#wed-14-adobedevcycle"&gt;clear process for handling them&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Perhaps I&amp;#8217;m abusing the bug fixing process by calling it a failure&amp;#8230; but I&amp;#8217;ve also found that yes&amp;#8230; many bugs are due to failure. Whether that be a failure to &lt;a href="http://behavior-driven.org/"&gt;specify application behavior&lt;/a&gt;, a failure to understand the project goals, a &lt;a href="http://www.robbyonrails.com/articles/2006/09/27/project-enlightenment-with-d3"&gt;failure in communication&lt;/a&gt;, ...or maybe a failure in our software architecture. We&amp;#8217;re constantly failing.. and it&amp;#8217;s okay!&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;IT&amp;#8217;S &lt;span class="caps"&gt;OKAY TO FAIL&lt;/span&gt;!&lt;/strong&gt; (some of the time&amp;#8230;)&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;No one &lt;em&gt;wants&lt;/em&gt; to learn by mistakes, but we cannot learn enough from successes to go beyond the state of the art. Contrary to their popular characterization as intellectual conservatives, engineers are really among the avant-garde. They are constantly seeking to employ new concepts to reduce the weigh and thus the cost of their structures, and they are constantly striving to do more with less so the resulting structure represents an efficient use of materials. The engineer always believes he is trying something without error, but the truth of the matter is that each new structure can be a new trial. In the meantime the layman, whose spokesman is often a poet or writer, can be threatened by both the failures &lt;em&gt;and&lt;/em&gt; the successes. Such is the nature not only of science and engineering, but of all human endeavors.&amp;#8221;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;As we&amp;#8217;re creating these virtual structures&amp;#8230; are we really taking the time to reflect on our failures? This is why some teams adopt practices like iteration retrospectives and post-mortems.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ll end this with a few questions, which I hope that you&amp;#8217;ll share your experiences about&amp;#8230;&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;In what ways is your team embracing the failures of your development projects?&lt;/li&gt;
		&lt;li&gt;How do you help manage your clients expectations&amp;#8230; so that they too can plan for and embrace failure? Isn&amp;#8217;t their new business venture on the web&amp;#8230; likely to experience some failure?&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;We have so much to learn&amp;#8230;&lt;/p&gt;
</description>
      <pubDate>Tue, 10 Apr 2007 16:38:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b216559d-75b1-443f-a42b-65a8feefe92d</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/04/10/embracing-failure-part-1</link>
      <category>Business</category>
      <category>Programming</category>
      <category>d3</category>
      <category>book</category>
      <category>tdd</category>
      <category>development</category>
      <category>testing</category>
      <category>agile</category>
      <category>design</category>
      <category>clients</category>
      <category>communication</category>
      <category>bdd</category>
      <category>failure</category>
      <category>expectations</category>
      <category>engineering</category>
    </item>
    <item>
      <title>On Apologies</title>
      <description>&lt;p&gt;Recently, Seth Godin posted a short blog post, titled, &lt;a href="http://sethgodin.typepad.com/seths_blog/2007/02/apologies_ranke.html"&gt;Apologies, ranked&lt;/a&gt;, which points out several ways of apologizing. When you work in a service industry, it becomes very important to develop good apology skills. Let&amp;#8217;s be honest for a moment. Not everything works out for the best in every customer experience. Sometimes it&amp;#8217;s their fault and many times&amp;#8230; it&amp;#8217;s our fault.&lt;/p&gt;


	&lt;p&gt;In response to Seth&amp;#8217;s post, &lt;a href="http://marcchung.com/"&gt;Marc Chung&lt;/a&gt; has written up a similar post that adapts this to software bugs, titled, &lt;a href="http://marcchung.com/2007/02/06/seth-on-fixing-bugs/"&gt;Seth on Fixing Bugs&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;s worth a read and definitely relates to the communication issues that we keep talking about within the &lt;a href="http://dialogue-driven.org/"&gt;Dialogue-Driven Development&lt;/a&gt; community and how that can translate to a healthy testing process with &lt;a href="http://behavior-driven.org/"&gt;&lt;span class="caps"&gt;BDD&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Thoughts?&lt;/p&gt;
</description>
      <pubDate>Thu, 15 Feb 2007 16:01:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:9afeee96-348e-462e-8685-56f9e696aff2</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/02/15/on-apologies</link>
      <category>My Book</category>
      <category>bdd</category>
      <category>dialogue</category>
      <category>customers</category>
      <category>apologies</category>
      <category>d3</category>
      <category>communication</category>
    </item>
    <item>
      <title>Be Careful that you don't Stub your Big Toe</title>
      <description>&lt;p&gt;In a project that I&amp;#8217;m currently working on, we&amp;#8217;re handling recurring payments for subscribers. I&amp;#8217;ve decided to play with a different payment service &lt;span class="caps"&gt;API&lt;/span&gt; on this project (&lt;a href="http://www.trustcommerce.com/"&gt;TrustCommerce&lt;/a&gt;), which supposedly has one of the easier systems to handle recurring payments as well as one-time charges to the same credit cards. They store all the credit card data so that our delivered product to the client is &lt;a href="http://usa.visa.com/merchants/risk_management/cisp.html"&gt;&lt;span class="caps"&gt;CISP&lt;/span&gt;-compliant&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;I came across the &lt;a href="http://www.agilewebdevelopment.com/plugins/trustcommerce_subscription"&gt;TrustCommerce Subscription&lt;/a&gt; plugin for Rails, which does just everything that I need to do in this first product release&amp;#8230; as well as things that aren&amp;#8217;t requirements just yet.&lt;/p&gt;


	&lt;p&gt;Well, I got my test account from TrustCommerce and was working on some RSpecs to test my new subscription and noticed that it was failing. After some snooping around the error responses, I realized that&amp;#8230; test accounts don&amp;#8217;t give you the ability to test the &lt;a href="http://www.trustcommerce.com/citadel.php"&gt;Citadel&lt;/a&gt; features of TrustCommerce. It&amp;#8217;ll be another week or so before finish getting our account setup, so what am I to do? I really want to finish writing these specs and move on to the other portions that are dependent upon this working.&lt;/p&gt;


	&lt;p&gt;Suppose that you were going to perform something like this in an AR callback.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class BillingDetail &amp;lt; ActiveRecord::Base

  # validations    

  before_create :store_credit_card_data_with_trust_commerce

  private 

    def store_credit_card_data_with_trust_commerce
      # some of this is still test data... prettyu much copied from the README
      # TODO: refactor... but keep me out of controllers!
      response = TrustCommerceGateway::Subscription.create(
          :cc =&amp;gt;  self.credit_card_number, 
          :exp =&amp;gt; '0412', 
          :name =&amp;gt; self.customer_name,
          :amount =&amp;gt; 1,
          :cycle =&amp;gt; '1y',
          :demo =&amp;gt; 'y'
        )

      if response['status'] == 'approved'
          self.billing_id = response['billingid']
        else
        # handle failure
        end
    end
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;Enter Mock Objects&lt;/h2&gt;


	&lt;p&gt;Since I am unable to succesfully use the &lt;code&gt;TrustCommerceGateway::Subscription.create&lt;/code&gt; method until I get our real account, I needed a simple way to emulate the interaction with the web service.&lt;/p&gt;


	&lt;p&gt;This can be done by using a Mock object, which RSpec provides for you.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
TrustCommerceGateway::Subscription.stub!(:create).and_return( {expected response} )
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Let&amp;#8217;s look at the following spec file (much of it removed to protect the innocent).&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
module ValidBillingDetail
  def valid_attributes
    { # a hash of valid key/values for this model }
  end

  def approved_trust_commerce_subscription
    { 'status' =&amp;gt; 'approved', 'billingid' =&amp;gt; '1093423' } 
  end
end

context "A new billing detail" do
  include ValidBillingDetail

  setup do
    TrustCommerceGateway::Subscription.stub!(:create).and_return( approved_trust_commerce_subscription )
  end

  # bunch of other specs

  specify "should store new billing info with 3rd party API and store the billingid" do
    @billing_detail = BillingDetail.create( valid_attributes )
    @billing_detail.billing_id.should_not_be nil
  end
end  
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;You&amp;#8217;ll notice a few things. First, you&amp;#8217;ll see that I&amp;#8217;ve stubbed the &lt;code&gt;create&lt;/code&gt; method and when it is called in the method in my model, it&amp;#8217;ll return the hash that I&amp;#8217;ve specified.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;TrustCommerceGateway::Subscription.stub!(:create).and_return( approved_trust_commerce_subscription )&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;In the spec, you will see that I am checking that that the &lt;code&gt;.billing_id.should_not_be nil&lt;/code&gt;. If you look back in the method in the model above, you will notice that an approved subscription returns a &lt;code&gt;billing_id&lt;/code&gt;, which is set when the transaction is successful.&lt;/p&gt;


	&lt;p&gt;This is working out great for me and because the documentation is fairly easy to follow, I&amp;#8217;m going to be able to mock much of the behavior that I&amp;#8217;ll be using in the application, without needing to even connect to their &lt;span class="caps"&gt;API&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re using RSpec, I highly encourage you to read more about &lt;a href="http://rspec.rubyforge.org/documentation/mocks/mocks.html"&gt;mocks objects&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Tue, 13 Feb 2007 01:09:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:6e9733fb-1d6b-42a8-a0ad-29948aacd45c</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/02/13/be-careful-that-you-dont-stub-your-big-toe</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>rspec</category>
      <category>bdd</category>
      <category>mocks</category>
      <category>stubs</category>
      <category>trustcommerce</category>
      <category>plugins</category>
      <category>testing</category>
    </item>
    <item>
      <title>RSpec Bundle for TextMate</title>
      <description>&lt;p&gt;Just a quick follow up to my post last night, &lt;a href="http://www.robbyonrails.com/articles/2007/02/11/sharing-custom-textmate-bundles-with-subversion"&gt;Sharing Custom TextMate Bundles with Subversion&lt;/a&gt;. It appears that I missed the &lt;a href="http://rspec.rubyforge.org/tools/extensions/editors/textmate.html"&gt;RSpec bundle&lt;/a&gt; for &lt;a href="http://www.macromates.com"&gt;TextMate&lt;/a&gt;, which is listed on the &lt;a href="http://rspec.rubyforge.org"&gt;RSpec webpage&lt;/a&gt;.&lt;/p&gt;


	&lt;h2&gt;Install the RSpec Bundle&lt;/h2&gt;


	&lt;p&gt;Installation is quite simple, just change directories to your TextMate bundle directory.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    $ cd ~/Library/Application\ Support/TextMate/Bundles/
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Check out the RSpec bundle from the subversion repository.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    $ svn co svn://rubyforge.org/var/svn/rspec/trunk/RSpec.tmbundle
    # lots of files...
    A    RSpec.tmbundle/Support/spec/fixtures/example_failing_spec.rb
    A    RSpec.tmbundle/Support/spec/fixtures/example_passing_spec.rb
    A    RSpec.tmbundle/Support/spec/spec_mate_spec.rb
    Checked out revision 1489.
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, just reload your bundles in TextMate and you&amp;#8217;re good to go!&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Bundles &amp;gt; Bundle Editor &amp;gt; Reload Bundles&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;d like to thank &lt;a href="http://blog.aslakhellesoy.com/"&gt;Aslak Hellesøy&lt;/a&gt; for pointing me to this and for also providing me with the correct subversion &lt;span class="caps"&gt;URL&lt;/span&gt;, which is currently outdated on the RSpec page until the next release.&lt;/p&gt;
</description>
      <pubDate>Mon, 12 Feb 2007 07:58:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:f183d1d4-0531-48e7-b389-1e5684d86590</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/02/12/rspec-bundle-for-textmate</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>rspec</category>
      <category>bdd</category>
      <category>textmate</category>
      <category>bundle</category>
      <category>subversion</category>
    </item>
    <item>
      <title>Is BDD kinkier than TDD?</title>
      <description>&lt;p&gt;If you&amp;#8217;re in need of a compelling reason to switch from Test-Driven Development to &lt;a href="http://www.behavior-driven.org/"&gt;Behavior-Driven Development&lt;/a&gt;... consider this.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&lt;em&gt;&amp;#8220;BDD sounds kinkier.&amp;#8221;&lt;/em&gt;  -Michael K. Loukides, Book Editor for O&amp;#8217;Reilly&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;...on that &lt;em&gt;bombshell&lt;/em&gt;... I am going to suggest that this be used as the official &lt;span class="caps"&gt;BDD&lt;/span&gt; logo.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://www.robbyonrails.com/files/kinkier_than_tdd.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;There you have it. Deep down&amp;#8230; the biggest reason that I switched from Test::Unit to &lt;a href="http://rspec.rubyforge.org"&gt;RSpec&lt;/a&gt;... was the sex appeal. ;-)&lt;/p&gt;


	&lt;p&gt;What was your reason?&lt;/p&gt;
</description>
      <pubDate>Thu, 08 Feb 2007 13:20:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:95d594a2-43ce-4682-b024-2a01af278078</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/02/08/is-bdd-kinkier-than-tdd</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>bdd</category>
      <category>tdd</category>
      <category>behavior</category>
      <category>driven</category>
      <category>agile</category>
      <category>development</category>
      <category>kinky</category>
      <category>sex</category>
      <category>handcuffs</category>
      <category>rspec</category>
    </item>
    <item>
      <title>The Zen of Auto Rspec</title>
      <description>&lt;p&gt;Several months ago, I heard that people were using a program called &lt;a href="http://nubyonrails.com/articles/2006/04/19/autotest-rails"&gt;autotest&lt;/a&gt; to have their tests continue to run as you made changes to your code base, which comes with &lt;a href="http://zentest.rubyforge.org/ZenTest/"&gt;ZenTest&lt;/a&gt;. It&amp;#8217;s a really nice tool written by Ryan Davis and I hadn&amp;#8217;t gotten a chance to play with it as of yet. Well, our team isn&amp;#8217;t spending too much time in the &lt;code&gt;test/&lt;/code&gt; directory these days as we jumped ship near the end of last summer and found ourselves hanging out on the &lt;a href="http://blog.brightredglow.com/2006/10/4/what-s-it-worth-to-me"&gt;Isle of &lt;span class="caps"&gt;BDD&lt;/span&gt;&lt;/a&gt;. The locals are &lt;a href="http://blog.daveastels.com/articles/2005/07/05/a-new-look-at-test-driven-development"&gt;quite thoughtful&lt;/a&gt; about these sorts of things.&lt;/p&gt;


	&lt;p&gt;I just started working on a project that has been under development for several months and as I&amp;#8217;m getting to learn the ins/outs of the system, I find myself having to rerun the specs, which can take quite a bit of time watching. Watching your specs or tests run sometimes is as productive as watching your code compile. Oddly enough, this is as close to compilation as we really get when working with Ruby on Rails&amp;#8230; and it&amp;#8217;s a productivity killer for me.&lt;/p&gt;


	&lt;h2&gt;There Must Be a Better Way!&lt;/h2&gt;


	&lt;p&gt;So, I did a quick google search and found &lt;a href="http://blog.nicksieger.com/articles/2006/11/15/rspec-autotest-now-a-rails-plugin"&gt;an announcement&lt;/a&gt; for Rails that ran specs through ZenTest. This was exactly what I was searching for!&lt;/p&gt;


	&lt;h3&gt;Some requirements&lt;/h3&gt;


	&lt;p&gt;Please makes sure that you have the following gems installed in your development environment as they are dependencies to make this all work.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;zentest &lt;/li&gt;
		&lt;li&gt;diff-lcs&lt;/li&gt;
	&lt;/ul&gt;


&lt;pre&gt;&lt;code&gt;
$ sudo gem install zentest diff-lcs 
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;strong&gt;note&lt;/strong&gt; I&amp;#8217;m going to assume that you have rspec and rspec for rails installed&amp;#8230; if not&amp;#8230; tsk. ;-)&lt;/p&gt;


	&lt;h3&gt;Install RSpec autotest&lt;/h3&gt;


&lt;pre&gt;&lt;code&gt;
$ script/plugin install http://svn.caldersphere.net/svn/main/plugins/rspec_autotest
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;If you&amp;#8217;re using subversion, you might consider installing it as an external.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ script/plugin install -x http://svn.caldersphere.net/svn/main/plugins/rspec_autotest
&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Running  RSpec autotest&lt;/h3&gt;


	&lt;p&gt;This is where it gets tricky. ;-)&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ rake spec:autotest
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, you can keep a terminal window open and autotest will watch your application and detect when files change. When they change, it&amp;#8217;ll attempt to rerun your specs (specifically those that changed). This helps save you the time of having to rerun all your specs throughout the development process and keep your spec:all sanity checks for when you&amp;#8217;re about to commit code to your repository.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ll post another entry in the next few days to show you how you can use &lt;a href="http://growl.info/"&gt;Growl&lt;/a&gt; with RSpec Autotest to keep you from having to look at your terminal all the time.&lt;/p&gt;


	&lt;p&gt;Until then&amp;#8230; have fun!&lt;/p&gt;
</description>
      <pubDate>Wed, 10 Jan 2007 11:08:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:dfc3e9d1-5548-4a55-a66b-9e36b6a07580</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/01/10/the-zen-of-auto-rspec</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>bdd</category>
      <category>rspec</category>
      <category>autotest</category>
      <category>rake</category>
      <category>subversion</category>
      <category>productivity</category>
      <category>development</category>
    </item>
    <item>
      <title>The Circular Perspective of BDD</title>
      <description>&lt;p&gt;A few weeks ago, Brian Ford was in my office and we were discussing &lt;span class="caps"&gt;BDD&lt;/span&gt; and how we can make this process even easier for our clients to understand&amp;#8230; much less our own internal staff. With all concepts, each person has their own idea about what it is, why it is important, regardless of whether or not it&amp;#8217;s accurate. This can cause some people to not find a good need for some practices.&lt;/p&gt;


	&lt;p&gt;During our discussion, Brian grabbed one of my whiteboard markers and drew diagrams to explain how he saw &lt;span class="caps"&gt;BDD&lt;/span&gt; vary from &lt;span class="caps"&gt;TDD&lt;/span&gt;. He has since posted an article on his blog titled, &lt;a href="http://blog.brightredglow.com/2006/10/4/what-s-it-worth-to-me"&gt;what&amp;#8217;s it worth to me&lt;/a&gt;, and discusses his circular view of &lt;a href="http://blog.brightredglow.com/2006/10/4/what-s-it-worth-to-me"&gt;Behavior-Driven Developent&lt;/a&gt; and the importance of using &lt;a href="http://www.dialogue-driven.org"&gt;Dialogue&lt;/a&gt; to &lt;a href="http://www.seedsofunfolding.org/issues/04_06/features_1.htm"&gt;evolve shared meaning&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Thu, 12 Oct 2006 09:56:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:307718be-a5c2-4ee5-b137-6913857a706d</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2006/10/12/the-circular-perspective-of-bdd</link>
      <category>Programming</category>
      <category>d3</category>
      <category>bdd</category>
      <category>agile</category>
      <category>d3</category>
      <category>dialogue</category>
      <category>brian</category>
    </item>
  </channel>
</rss>
