<?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 rspec</title>
    <link>http://www.robbyonrails.com/articles/tag/rspec</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>Things (in the Rails world) You Don't Yet Understand</title>
      <description>&lt;p&gt;This is inspired by a recent post by Seth Godin titled, &lt;a href="http://sethgodin.typepad.com/seths_blog/2008/03/things-you-dont.html"&gt;Things you don&amp;#8217;t understand&lt;/a&gt;, where he shared a list of things that he probably could understand if he put your mind to it, but doesn&amp;#8217;t. I decided to post a list of five (5) things in response within the context of Ruby/Rails.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m really interested in various things but am really unable to prioritize them high enough to spend the time to understand them.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;RSpec User Stories&lt;/li&gt;
		&lt;li&gt;Using Selenium with RSpec&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://jquery.com/"&gt;JQuery&lt;/a&gt; (&lt;a href="http://blog.imperialdune.com/"&gt;Graeme&lt;/a&gt; speaks highly of it)&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://code.google.com/p/jsspec/"&gt;JSSpec&lt;/a&gt; (BDD for Javascript)&lt;/li&gt;
		&lt;li&gt;Using the Google Charts &lt;span class="caps"&gt;API&lt;/span&gt; with Rails&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;What about you? What&amp;#8217;s your list of things that you&amp;#8217;d like to understand more about?&lt;/p&gt;
</description>
      <pubDate>Tue, 25 Mar 2008 10:12:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2ad10b2f-7185-4d43-bc2e-1e881281f1c5</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/03/25/things-in-the-rails-world-you-dont-yet-understand</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>question</category>
      <category>rspec</category>
      <category>jquery</category>
      <category>javascript</category>
      <category>ruby</category>
      <category>rubyonrails</category>
      <category>rails</category>
      <category>google</category>
      <category>charts</category>
      <category>godin</category>
    </item>
    <item>
      <title>Launch your own RubyURL</title>
      <description>&lt;p&gt;A few weeks ago, I moved &lt;a href="http://rubyurl.com"&gt;RubyURL&lt;/a&gt; from subversion to git. During that process, I decided to use my invite to &lt;a href="http://github.com"&gt;GitHub&lt;/a&gt; and have decided to go ahead and open up the source code.&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;s currently a whopping 92 &lt;span class="caps"&gt;LOC&lt;/span&gt; with a 1:2.5 code to spec ratio. (I had a goal to keep is below 100 &lt;span class="caps"&gt;LOC&lt;/span&gt;)&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;RubyURL on GitHub: &lt;a href="http://github.com/robbyrussell/rubyurl"&gt;http://github.com/robbyrussell/rubyurl&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Public Clone &lt;span class="caps"&gt;URL&lt;/span&gt;: &lt;a href="git://github.com/robbyrussell/rubyurl.git"&gt;git://github.com/robbyrussell/rubyurl.git&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Feel free to grab it and help contribute. This has served almost &lt;strong&gt;14 million&lt;/strong&gt; redirects since August 2007 and is running on a &lt;a href="http://planetargon.com/hosting.html"&gt;Rails Boxcar&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;To grab it with git.. run: &lt;code&gt;git clone git://github.com/robbyrussell/rubyurl.git&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;Feel free to submit tickets to the &lt;a href="http://planetargon.lighthouseapp.com/projects/4059-rubyurl"&gt;Rubyurl ticket system&lt;/a&gt;.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://planetargon.lighthouseapp.com/projects/4059-rubyurl"&gt;http://planetargon.lighthouseapp.com/projects/4059-rubyurl&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Enjoy!&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;&lt;/strong&gt; Ryan McGeary was kind enough to be the first person to help track down a bug and &lt;a href="http://github.com/robbyrussell/rubyurl/commits/master"&gt;submit patches&lt;/a&gt;. :-)&lt;/p&gt;
</description>
      <pubDate>Sat, 01 Mar 2008 18:31:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:a1e839d1-4c9b-47d6-931c-b0559ea71539</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/03/01/launch-your-own-rubyurl</link>
      <category>RubyURL</category>
      <category>Ruby on Rails</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>rubyurl</category>
      <category>boxcar</category>
      <category>git</category>
      <category>subversion</category>
      <category>github</category>
      <category>open</category>
      <category>source</category>
      <category>rails</category>
      <category>rspec</category>
    </item>
    <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>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>Sharing Custom TextMate Bundles with Subversion</title>
      <description>&lt;p&gt;Early last year, I began to start creating a bunch of snippets and such for &lt;a href="http://macromates.com"&gt;TextMate&lt;/a&gt;, all of which were lost several months ago due to &lt;a href="http://www.robbyonrails.com/articles/2006/08/11/isight-magnet-is-teh-suck"&gt;Hurricane iSight&lt;/a&gt;. I recently decided to start building some again, especially some that sped up my &lt;a href="http://rspec.rubyforge.org"&gt;RSpec&lt;/a&gt; writing. After creating a few, I wondered, &amp;#8220;would anybody else on my team want to help me write some?&amp;#8221; So, I thought that it was time to figure out how to share my bundle with others and allow them to add stuff to it&amp;#8230; which seems like a good job for Ms. Subversion.&lt;/p&gt;


	&lt;p&gt;I couldn&amp;#8217;t find a quick walk-through online and found myself in the &lt;code&gt;#textmate&lt;/code&gt; IRC channel getting proper instructions. (thank you &lt;a href="http://macromates.com/blog/"&gt;Allan&lt;/a&gt;!)&lt;/p&gt;


	&lt;h2&gt;Create Your Bundle&lt;/h2&gt;


	&lt;p&gt;In TextMate, you can open up the Bundle Editor and create a new bundle. Let&amp;#8217;s call our custom bundle, &lt;strong&gt;RSpec&lt;/strong&gt;. Go ahead and begin adding some snippets, commands, etc to your new custom bundle. Once you have something in your Bundle, you&amp;#8217;ll want to reload your bundles, by going to &lt;strong&gt;Bundles &amp;gt; Bundle Editor &amp;gt; Reload Bundles&lt;/strong&gt;. This will write your new bundle to disk to &lt;code&gt;~/Library/Application\ Support/TextMate/Bundles/&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    $ ls -al ~/Library/Application\ Support/TextMate/Bundles/
    total 0
    drwxr-xr-x   5 robbyrus  robbyrus  170 Feb 11 21:10 .
    drwxr-xr-x   4 robbyrus  robbyrus  136 Feb 11 20:11 ..
    drwxr-xr-x   5 robbyrus  robbyrus  170 Jan 12 16:58 PLANET ARGON.tmbundle
    drwxr-xr-x   3 robbyrus  robbyrus  102 Feb 11 21:10 RSpec.tmbundle
    drwxr-xr-x   4 robbyrus  robbyrus  136 Oct 21 13:38 Robby Russell???s Bundle.tmbundle
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;Importing your Bundle into Subversion&lt;/h2&gt;


	&lt;p&gt;You&amp;#8217;ll want to first import your new bundle into Subversion.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    $ cd ~/Library/Application\ Support/TextMate/Bundles/
    $ svn import RSpec.tmbundle/ -m "Initial import of RSpec (test) bundle" http://{respository_url}/{repository_name}/RSpec.tmbundle/
    Adding         RSpec.tmbundle/info.plist
    Adding         RSpec.tmbundle/Snippets
    Adding         RSpec.tmbundle/Snippets/new specification.tmSnippet
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, now it&amp;#8217;s in Subversion. Now, you&amp;#8217;ll want to check it back out so that TextMate is running off of the version from Subversion.&lt;/p&gt;


	&lt;p&gt;The simplest way to do this is to delete your local copy and checkout the latest from Subversion.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    $ rm -rf RSpec.tmbundle/; svn co http://{respository_url}/{repository_name}/RSpec.tmbundle/
    A    RSpec.tmbundle/Snippets
    A    RSpec.tmbundle/Snippets/new specification.tmSnippet
    A    RSpec.tmbundle/info.plist
    Checked out revision 5.
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;All that you need to do now, is relaod your bundles again. Now that you know where the bundle files are stored, you can commit any changes as they are made.&lt;/p&gt;


	&lt;h2&gt;Committing Bundle Changes&lt;/h2&gt;


	&lt;p&gt;When you make changes to your TextMate bundle, you can do the following to commit your updates to the Subversion repository.&lt;/p&gt;


	&lt;h3&gt;See Your Pending Changes&lt;/h3&gt;


	&lt;p&gt;You can change directories to your custom bundle and run &lt;code&gt;svn status&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    $ cd ~/Library/Application\ Support/TextMate/Bundles/RSpec.tmbundle/
    $ svn status
    ?      Snippets/new context.tmSnippet
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;You&amp;#8217;ll see that the new snippet that I created needs to be added to Subversion.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    $ svn add Snippets/new\ context.tmSnippet 
    A         Snippets/new context.tmSnippet
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, let&amp;#8217;s commit it to the repository.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ svn ci -m "Adding new context snippet" 
Adding         Snippets/new context.tmSnippet
Transmitting file data .
Committed revision 6.
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;At this point, all Subversion tips and tricks apply&amp;#8230; so&amp;#8230; it&amp;#8217;s time to leave it to you to figure out the rest. :-)&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;TIP&lt;/span&gt;: Always reload your bundles before and after running svn update or svn commit&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;...and there you have it! You and your friends can (with a little work) share and develop your own custom bundles for TextMate. I&amp;#8217;m hoping to get my teammates at &lt;a href="http://www.planetargon.com/"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; to help me build a bunch for RSpec, which I&amp;#8217;ll try to release into the wild soon. If anybody is already working on RSpec snippets and other TextMate hacks, please let me know.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.robbyonrails.com/articles/2007/02/11/sharing-custom-textmate-bundles-with-subversion#comments"&gt;Aslak kindly commented&lt;/a&gt; on this post and has pointed me to bundle available in the RSpec subversion repository, which I &lt;a href="http://www.robbyonrails.com/articles/2007/02/12/rspec-bundle-for-textmate"&gt;blogged about.&lt;/a&gt;) :-)&lt;/p&gt;


	&lt;p&gt;Happy hacking!&lt;/p&gt;
</description>
      <pubDate>Sun, 11 Feb 2007 23:35:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:f8505a28-84eb-43ea-8504-2d60385d1460</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/02/11/sharing-custom-textmate-bundles-with-subversion</link>
      <category>Ruby on Rails</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>rspec</category>
      <category>textmate</category>
      <category>subversion</category>
      <category>tutorial</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>
  </channel>
</rss>
