<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rails on the Run &#187; TDD</title>
	<atom:link href="http://railsontherun.com/tag/tdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://railsontherun.com</link>
	<description>Rails experiments by Matt Aimonetti</description>
	<lastBuildDate>Tue, 23 Feb 2010 07:28:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to test a XML builder view</title>
		<link>http://railsontherun.com/2007/10/31/how-to-test-a-xml-builder-view/</link>
		<comments>http://railsontherun.com/2007/10/31/how-to-test-a-xml-builder-view/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 08:32:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[hpricot]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[xml builder]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/10/31/how-to-test-a-xml-builder-view</guid>
		<description><![CDATA[As a good Rubyist, I do TDD and even BDD. 
Since I&#8217;ve started using RSpec I&#8217;ve started writing tests against my views. RSpec makes things really easy and I&#8217;ve been enjoying testing my views.
I&#8217;m not the only one having fun, check this great post from Mr Planet Argon aka Robby Russel
Recently I was working on [...]]]></description>
			<content:encoded><![CDATA[<p>As a good Rubyist, I do <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> and even <a href="http://en.wikipedia.org/wiki/Behavior_driven_development">BDD</a>. </p>
<p>Since I&#8217;ve started using <a href="http://rspec.rubyforge.org/">RSpec</a> I&#8217;ve started writing tests against my views. RSpec makes things really easy and I&#8217;ve been enjoying testing my views.</p>
<p>I&#8217;m not the only one having fun, check <a href="http://www.robbyonrails.com/articles/2007/08/02/spec-your-views">this great post</a> from Mr <a href="http://www.planetargon.com/">Planet Argon</a> aka <a href="http://www.robbyonrails.com">Robby Russel</a></p>
<p>Recently I was working on implementing some <a href="http://railsontherun.com/2007/10/4/sexy-charts-in-less-than-5-minutes">Sexy Charts</a> and I was using a XML builder to create an XML view of for a controller. Since I wanted to be a good Rails Ninja and obey the BDD rules, I figured I needed to test my XML view. Making sure that the nodes and the attributes were properly created. Turned out that is wasn&#8217;t too hard, there was many options but none were very well documented so I decided to write this quick tutorial.</p>
<h2>UPDATE 31 Oct 2007: After a comment from <a href="http://joshknowles.com">Josh Knowles</a>, I updated the tests to test with have_tags (built in RSpec) and hpricot.</h2>
<h2>Hpricot</h2>
<p><a href="http://code.whytheluckystiff.net/hpricot/">hpricot</a> is a awesome HTML parser perfect for <a href="http://en.wikipedia.org/wiki/Screen_scraping">screen scraping</a>. But wait, there&#8217;s more to this awesome library, <a href="http://code.whytheluckystiff.net/hpricot/wiki/HpricotXML">hpricot can also parse XML</a>.</p>
<p>If you watched the excellent <a href="http://peepcode.com/products">RSpec peepcasts</a> you probably noticed that <a href="http://topfunky.com/">topfunky</a> aka <a href="http://geoffreygrosenbach.com/">Geoffrey Grosenbach</a> uses hpricot to test a remote API.</p>
<p>In our case, we&#8217;ll use hpricot to test that our generated XML follows our expectations.</p>
<h2>XML Builder + RSpec</h2>
<p>Let&#8217;s write a quick test to make sure our controller uses a XML builder view:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt><strong>15</strong><tt>
</tt>16<tt>
</tt>17<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  describe <span class="co">AveragesController</span>, <span class="s"><span class="dl">&quot;</span><span class="k">handling GET /averages.xml</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt><tt>
</tt>    before <span class="r">do</span><tt>
</tt>      <span class="co">Average</span>.stub!(<span class="sy">:find</span>).and_return(<span class="iv">@average</span>)<tt>
</tt>    <span class="r">end</span><tt>
</tt>  <tt>
</tt>    <span class="r">def</span> <span class="fu">do_get</span><tt>
</tt>      <span class="iv">@request</span>.env[<span class="s"><span class="dl">&quot;</span><span class="k">HTTP_ACCEPT</span><span class="dl">&quot;</span></span>] = <span class="s"><span class="dl">&quot;</span><span class="k">application/xml</span><span class="dl">&quot;</span></span><tt>
</tt>      get <span class="sy">:index</span><tt>
</tt>    <span class="r">end</span><tt>
</tt>  <tt>
</tt>    it <span class="s"><span class="dl">&quot;</span><span class="k">should render the action using the XML builder</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>      do_get<tt>
</tt>      response.should render_template(<span class="s"><span class="dl">'</span><span class="k">averages/index.xml.builder</span><span class="dl">'</span></span>)<tt>
</tt>    <span class="r">end</span><tt>
</tt><tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>To make this example pass, we need to modify our rspec generated controller.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="r">def</span> <span class="fu">index</span><tt>
</tt>    <span class="iv">@averages</span> = <span class="co">Average</span>.find(<span class="sy">:all</span>)<tt>
</tt>  <tt>
</tt>    respond_to <span class="r">do</span> |format|<tt>
</tt>      format.html <span class="c"># index.html.erb</span><tt>
</tt>      format.xml  { render <span class="sy">:action</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">index.xml.builder</span><span class="dl">&quot;</span></span>, <span class="sy">:layout</span> =&gt; <span class="pc">false</span> }<tt>
</tt>    <span class="r">end</span><tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>(Please note that I&#8217;m using Rails 2.0 and that&#8217;s why I&#8217;m not using a .rxml view)</p>
<p>Here is what our XML file should end up looking like:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt><strong>15</strong><tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt><strong>25</strong><tt>
</tt>26<tt>
</tt>27<tt>
</tt>28<tt>
</tt>29<tt>
</tt><strong>30</strong><tt>
</tt>31<tt>
</tt>32<tt>
</tt>33<tt>
</tt>34<tt>
</tt><strong>35</strong><tt>
</tt>36<tt>
</tt>37<tt>
</tt>38<tt>
</tt>39<tt>
</tt><strong>40</strong><tt>
</tt>41<tt>
</tt>42<tt>
</tt>43<tt>
</tt>44<tt>
</tt><strong>45</strong><tt>
</tt>46<tt>
</tt>47<tt>
</tt>48<tt>
</tt>49<tt>
</tt><strong>50</strong><tt>
</tt>51<tt>
</tt>52<tt>
</tt>53<tt>
</tt>54<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  &lt;<span class="i">?x</span>ml version=<span class="s"><span class="dl">&quot;</span><span class="k">1.0</span><span class="dl">&quot;</span></span> encoding=<span class="s"><span class="dl">&quot;</span><span class="k">UTF-8</span><span class="dl">&quot;</span></span>?&gt;<tt>
</tt>  &lt;chart&gt;<tt>
</tt>    &lt;series&gt;<tt>
</tt>      &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">0</span><span class="dl">&quot;</span></span>&gt;<span class="co">January</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>      &lt;value xid=&quot;1&quot;&gt;February&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>      &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">2</span><span class="dl">&quot;</span></span>&gt;<span class="co">March</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>      &lt;value xid=&quot;3&quot;&gt;April&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>      &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">4</span><span class="dl">&quot;</span></span>&gt;<span class="co">May</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt><tt>
</tt>      &lt;value xid=&quot;5&quot;&gt;June&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>      &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">6</span><span class="dl">&quot;</span></span>&gt;<span class="co">July</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>      &lt;value xid=&quot;7&quot;&gt;August&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>      &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">8</span><span class="dl">&quot;</span></span>&gt;<span class="co">September</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>      &lt;value xid=&quot;9&quot;&gt;October&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>      &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">10</span><span class="dl">&quot;</span></span>&gt;<span class="co">November</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt><tt>
</tt>      &lt;value xid=&quot;11&quot;&gt;December&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>    &lt;<span class="rx"><span class="dl">/</span><span class="k">series&gt;<tt>
</tt>    &lt;graphs&gt;<tt>
</tt>      &lt;graph fill_alpha=&quot;50&quot; color=&quot;#FF0000&quot; fill_color=&quot;#CC0000&quot; title=&quot;high&quot;&gt;<tt>
</tt>        &lt;value xid=&quot;0&quot;&gt;65.1&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">1</span><span class="dl">&quot;</span></span>&gt;<span class="fl">65.7</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;2&quot;&gt;64.9&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt><tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">3</span><span class="dl">&quot;</span></span>&gt;<span class="fl">66.7</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;4&quot;&gt;67.1&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">5</span><span class="dl">&quot;</span></span>&gt;<span class="fl">69.3</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;6&quot;&gt;73.0&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">7</span><span class="dl">&quot;</span></span>&gt;<span class="fl">74.8</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;8&quot;&gt;75.4&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt><tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">9</span><span class="dl">&quot;</span></span>&gt;<span class="fl">73.4</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;10&quot;&gt;68.9&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">11</span><span class="dl">&quot;</span></span>&gt;<span class="fl">65.3</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>      &lt;</span><span class="dl">/</span></span>graph&gt;<tt>
</tt>      &lt;graph fill_alpha=<span class="s"><span class="dl">&quot;</span><span class="k">50</span><span class="dl">&quot;</span></span> color=<span class="s"><span class="dl">&quot;</span><span class="k">#0000CC</span><span class="dl">&quot;</span></span> fill_color=<span class="s"><span class="dl">&quot;</span><span class="k">#0000CC</span><span class="dl">&quot;</span></span> title=<span class="s"><span class="dl">&quot;</span><span class="k">low</span><span class="dl">&quot;</span></span>&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">0</span><span class="dl">&quot;</span></span>&gt;<span class="fl">48.9</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;1&quot;&gt;50.7&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt><tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">2</span><span class="dl">&quot;</span></span>&gt;<span class="fl">52.9</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;3&quot;&gt;55.6&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">4</span><span class="dl">&quot;</span></span>&gt;<span class="fl">59.2</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;5&quot;&gt;61.9&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">6</span><span class="dl">&quot;</span></span>&gt;<span class="fl">65.7</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;7&quot;&gt;67.3&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt><tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">8</span><span class="dl">&quot;</span></span>&gt;<span class="fl">65.7</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;9&quot;&gt;61.0&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>        &lt;value xid=<span class="s"><span class="dl">&quot;</span><span class="k">10</span><span class="dl">&quot;</span></span>&gt;<span class="fl">54.0</span>&lt;<span class="rx"><span class="dl">/</span><span class="k">value&gt;<tt>
</tt>        &lt;value xid=&quot;11&quot;&gt;48.7&lt;</span><span class="dl">/</span></span>value&gt;<tt>
</tt>      &lt;<span class="rx"><span class="dl">/</span><span class="k">graph&gt;<tt>
</tt>    &lt;</span><span class="dl">/</span></span>graphs&gt;<tt>
</tt>  &lt;<span class="rx"><span class="dl">/</span><span class="k">chart&gt;<tt>
</tt>  </span></span></pre>
</td>
</tr>
</table>
<p>Let&#8217;s write some tests to make sure our view is ok:</p>
<p>index.xml.builder_spec.rb</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt><strong>15</strong><tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt><strong>25</strong><tt>
</tt>26<tt>
</tt>27<tt>
</tt>28<tt>
</tt>29<tt>
</tt><strong>30</strong><tt>
</tt>31<tt>
</tt>32<tt>
</tt>33<tt>
</tt>34<tt>
</tt><strong>35</strong><tt>
</tt>36<tt>
</tt>37<tt>
</tt>38<tt>
</tt>39<tt>
</tt><strong>40</strong><tt>
</tt>41<tt>
</tt>42<tt>
</tt>43<tt>
</tt>44<tt>
</tt><strong>45</strong><tt>
</tt>46<tt>
</tt>47<tt>
</tt>48<tt>
</tt>49<tt>
</tt><strong>50</strong><tt>
</tt>51<tt>
</tt>52<tt>
</tt>53<tt>
</tt>54<tt>
</tt><strong>55</strong><tt>
</tt>56<tt>
</tt>57<tt>
</tt>58<tt>
</tt>59<tt>
</tt><strong>60</strong><tt>
</tt>61<tt>
</tt>62<tt>
</tt>63<tt>
</tt>64<tt>
</tt><strong>65</strong><tt>
</tt>66<tt>
</tt>67<tt>
</tt>68<tt>
</tt>69<tt>
</tt><strong>70</strong><tt>
</tt>71<tt>
</tt>72<tt>
</tt>73<tt>
</tt>74<tt>
</tt><strong>75</strong><tt>
</tt>76<tt>
</tt>77<tt>
</tt>78<tt>
</tt>79<tt>
</tt><strong>80</strong><tt>
</tt>81<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">require <span class="co">File</span>.dirname(<span class="pc">__FILE__</span>) + <span class="s"><span class="dl">'</span><span class="k">/../../spec_helper</span><span class="dl">'</span></span><tt>
</tt>require <span class="s"><span class="dl">'</span><span class="k">hpricot</span><span class="dl">'</span></span><tt>
</tt><tt>
</tt>describe <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>  include <span class="co">AveragesHelper</span><tt>
</tt>  <tt>
</tt>  before <span class="r">do</span><tt>
</tt>    average_1 = mock_model(<span class="co">Average</span>)<tt>
</tt>    average_1.stub!(<span class="sy">:month</span>).and_return(<span class="s"><span class="dl">&quot;</span><span class="k">January</span><span class="dl">&quot;</span></span>)<tt>
</tt>    average_1.stub!(<span class="sy">:high</span>).and_return(<span class="s"><span class="dl">&quot;</span><span class="k">74.5</span><span class="dl">&quot;</span></span>)<tt>
</tt>    average_1.stub!(<span class="sy">:low</span>).and_return(<span class="s"><span class="dl">&quot;</span><span class="k">61.5</span><span class="dl">&quot;</span></span>)<tt>
</tt>    average_2 = mock_model(<span class="co">Average</span>)<tt>
</tt>    average_2.stub!(<span class="sy">:month</span>).and_return(<span class="s"><span class="dl">&quot;</span><span class="k">February</span><span class="dl">&quot;</span></span>)<tt>
</tt>    average_2.stub!(<span class="sy">:high</span>).and_return(<span class="s"><span class="dl">&quot;</span><span class="k">82.5</span><span class="dl">&quot;</span></span>)<tt>
</tt>    average_2.stub!(<span class="sy">:low</span>).and_return(<span class="s"><span class="dl">&quot;</span><span class="k">71.5</span><span class="dl">&quot;</span></span>)<tt>
</tt><tt>
</tt>    assigns[<span class="sy">:averages</span>] = [average_1, average_2]<tt>
</tt>  <span class="r">end</span><tt>
</tt><tt>
</tt>  it <span class="s"><span class="dl">&quot;</span><span class="k">should render the months in the series</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">value</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">'</span><span class="k">January</span><span class="dl">'</span></span>)<tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">value</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">'</span><span class="k">February</span><span class="dl">'</span></span>)<tt>
</tt>    <span class="c"># Same thing but with Hpricot</span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:value</span>).first.inner_html.should == <span class="s"><span class="dl">'</span><span class="k">January</span><span class="dl">'</span></span><tt>
</tt>    (doc/<span class="sy">:value</span>)[<span class="i">1</span>].inner_html.should == <span class="s"><span class="dl">'</span><span class="k">February</span><span class="dl">'</span></span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  it <span class="s"><span class="dl">&quot;</span><span class="k">should set the xid attributes for the series</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">value[xid=0]:first-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">value[xid=1]:last-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    <span class="c"># Same thing but with Hpricot</span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:value</span>).first[<span class="s"><span class="dl">&quot;</span><span class="k">xid</span><span class="dl">&quot;</span></span>].should == <span class="s"><span class="dl">'</span><span class="k">0</span><span class="dl">'</span></span><tt>
</tt>    (doc/<span class="sy">:value</span>).last[<span class="s"><span class="dl">&quot;</span><span class="k">xid</span><span class="dl">&quot;</span></span>].should == <span class="s"><span class="dl">'</span><span class="k">1</span><span class="dl">'</span></span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  it <span class="s"><span class="dl">&quot;</span><span class="k">should have 2 graphs and they should have a title</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph[title=high]:first-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph[title=low]:last-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    <span class="c"># Same thing but with Hpricot</span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:graph</span>).size.should == <span class="i">2</span><tt>
</tt>    (doc/<span class="sy">:graph</span>).first[<span class="s"><span class="dl">&quot;</span><span class="k">title</span><span class="dl">&quot;</span></span>].should == <span class="s"><span class="dl">'</span><span class="k">high</span><span class="dl">'</span></span><tt>
</tt>    (doc/<span class="sy">:graph</span>).last[<span class="s"><span class="dl">&quot;</span><span class="k">title</span><span class="dl">&quot;</span></span>].should == <span class="s"><span class="dl">'</span><span class="k">low</span><span class="dl">'</span></span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  it <span class="s"><span class="dl">&quot;</span><span class="k">should have a color set by graph</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph[color]:first-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph[color]:last-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph[fill_color]:last-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph[fill_alpha]:last-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    <span class="c"># Same thing but with Hpricot</span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:graph</span>).first[<span class="s"><span class="dl">&quot;</span><span class="k">color</span><span class="dl">&quot;</span></span>].should_not be_nil<tt>
</tt>    (doc/<span class="sy">:graph</span>).last[<span class="s"><span class="dl">&quot;</span><span class="k">color</span><span class="dl">&quot;</span></span>].should_not be_nil<tt>
</tt>    (doc/<span class="sy">:graph</span>).last[<span class="s"><span class="dl">&quot;</span><span class="k">fill_color</span><span class="dl">&quot;</span></span>].should_not be_nil<tt>
</tt>    (doc/<span class="sy">:graph</span>).last[<span class="s"><span class="dl">&quot;</span><span class="k">fill_alpha</span><span class="dl">&quot;</span></span>].should_not be_nil<tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  it <span class="s"><span class="dl">&quot;</span><span class="k">should have an xid for each graph value</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph &gt; value[xid=0]:first-child</span><span class="dl">&quot;</span></span>)<tt>
</tt>    <span class="c"># Same thing but with Hpricot</span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:graph</span>/<span class="sy">:value</span>).first[<span class="s"><span class="dl">&quot;</span><span class="k">xid</span><span class="dl">&quot;</span></span>].should == <span class="s"><span class="dl">&quot;</span><span class="k">0</span><span class="dl">&quot;</span></span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  it <span class="s"><span class="dl">&quot;</span><span class="k">should have the high average as values of the first graph</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    response.should have_tag(<span class="s"><span class="dl">&quot;</span><span class="k">graph &gt; value:first-child</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">74.5</span><span class="dl">&quot;</span></span>)<tt>
</tt>    <span class="c"># Same thing but with Hpricot</span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:graph</span>/<span class="sy">:value</span>).first.inner_html.should == <span class="s"><span class="dl">&quot;</span><span class="k">74.5</span><span class="dl">&quot;</span></span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>The first thing you must do (after installing the hpricot gem) is to require hpricot in your test:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  require <span class="s"><span class="dl">'</span><span class="k">hpricot</span><span class="dl">'</span></span></pre>
</td>
</tr>
</table>
<p>Now that hpricot is created we can use it to parse the response and check against our expectations.</p>
<p>(we create mock objects to pass to the view so we know exactly what to expect and we separate Model/Controller/Views tests)</p>
<p>To check against our response we have to use hpricot parser syntax. It might look at bit funny at first, but believe me it&#8217;s really easy once you get it.</p>
<p>But first, let&#8217;s parse the view:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="c"># Render the mocked up data using the xml view</span><tt>
</tt>render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt><span class="c"># Load and parse the view response body:</span><tt>
</tt>doc = <span class="co">Hpricot</span>.XML(response.body.to_s)  </pre>
</td>
</tr>
</table>
<p>Let&#8217;s look at the first test:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  it <span class="s"><span class="dl">&quot;</span><span class="k">should render the months in the series</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:value</span>).first.inner_html.should == <span class="s"><span class="dl">'</span><span class="k">January</span><span class="dl">'</span></span><tt>
</tt>    (doc/<span class="sy">:value</span>)[<span class="i">1</span>].inner_html.should == <span class="s"><span class="dl">'</span><span class="k">February</span><span class="dl">'</span></span><tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>(doc/:value) returns all the value nodes, we take the first one and extract its content. We expect that it would match the name of the month for the first average.</p>
<p>Let&#8217;s now look at another test:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>7<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  it <span class="s"><span class="dl">&quot;</span><span class="k">should have 2 graphs and they should have a title</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:graph</span>).size.should == <span class="i">2</span><tt>
</tt>    (doc/<span class="sy">:graph</span>).first[<span class="s"><span class="dl">&quot;</span><span class="k">title</span><span class="dl">&quot;</span></span>].should == <span class="s"><span class="dl">'</span><span class="k">high</span><span class="dl">'</span></span><tt>
</tt>    (doc/<span class="sy">:graph</span>).last[<span class="s"><span class="dl">&quot;</span><span class="k">title</span><span class="dl">&quot;</span></span>].should == <span class="s"><span class="dl">'</span><span class="k">low</span><span class="dl">'</span></span><tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>The thing to look at here is the fact that we are checking on the node&#8217;s attribute &#8220;title&#8221;. Really simple syntax and clean test, isn&#8217;t it?</p>
<p>Finally let&#8217;s look at the last example:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  it <span class="s"><span class="dl">&quot;</span><span class="k">should have the high average as values of the first graph</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>    render <span class="s"><span class="dl">&quot;</span><span class="k">/averages/index.xml.builder</span><span class="dl">&quot;</span></span><tt>
</tt>    doc = <span class="co">Hpricot</span>.XML(response.body.to_s)<tt>
</tt>    (doc/<span class="sy">:graph</span>/<span class="sy">:value</span>).first.inner_html.should == <span class="s"><span class="dl">&quot;</span><span class="k">74.5</span><span class="dl">&quot;</span></span><tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>We are checking that the content of the first value node nested inside a graph node is equal to 74.5 which is the high average for the first month. </p>
<p>In practice, you probably won&#8217;t write all these tests at once, but anyway, let&#8217;s look at our XML builder which will make all these tests pass:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt><strong>15</strong><tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">xml.instruct! <span class="sy"> <img src='http://railsontherun.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml</span>, <span class="sy">:version</span>=&gt;<span class="s"><span class="dl">&quot;</span><span class="k">1.0</span><span class="dl">&quot;</span></span>, <span class="sy">:encoding</span>=&gt;<span class="s"><span class="dl">&quot;</span><span class="k">UTF-8</span><span class="dl">&quot;</span></span><tt>
</tt>xml.chart <span class="r">do</span><tt>
</tt>  xml.series <span class="r">do</span>    <tt>
</tt>    <span class="iv">@averages</span>.each_with_index <span class="r">do</span> |average, index|<tt>
</tt>      xml.value average.month, <span class="sy"> <img src='http://railsontherun.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> id</span> =&gt; index<tt>
</tt>    <span class="r">end</span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  xml.graphs <span class="r">do</span><tt>
</tt>    xml.graph <span class="sy">:title</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">high</span><span class="dl">'</span></span>, <span class="sy">:color</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">#FF0000</span><span class="dl">&quot;</span></span>, <span class="sy">:fill_alpha</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">50</span><span class="dl">&quot;</span></span>, <span class="sy">:fill_color</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">#CC0000</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>      <span class="iv">@averages</span>.each_with_index <span class="r">do</span> |average, index|<tt>
</tt>        xml.value average.high, <span class="sy"> <img src='http://railsontherun.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> id</span> =&gt; index<tt>
</tt>      <span class="r">end</span><tt>
</tt>    <span class="r">end</span><tt>
</tt>    <tt>
</tt>    xml.graph <span class="sy">:title</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">low</span><span class="dl">'</span></span>, <span class="sy">:color</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">#0000CC</span><span class="dl">&quot;</span></span>, <span class="sy">:fill_alpha</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">50</span><span class="dl">&quot;</span></span>, <span class="sy">:fill_color</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">#0000CC</span><span class="dl">&quot;</span></span> <span class="r">do</span><tt>
</tt>      <span class="iv">@averages</span>.each_with_index <span class="r">do</span> |average, index|<tt>
</tt>        xml.value average.low, <span class="sy"> <img src='http://railsontherun.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> id</span> =&gt; index<tt>
</tt>      <span class="r">end</span><tt>
</tt>    <span class="r">end</span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Hpricot is a <em>really</em> nice tool which can make your BDD life much easier. And even if you don&#8217;t do BDD/TDD yet, it&#8217;s a great way to verify that any XML data you receive/generate is valid.</p>
<h2>Happy testing</h2>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/10/31/how-to-test-a-xml-builder-view/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Create a Rails Edge / RSpec project</title>
		<link>http://railsontherun.com/2007/06/06/create-a-rails-edge-rspec-project/</link>
		<comments>http://railsontherun.com/2007/06/06/create-a-rails-edge-rspec-project/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 19:34:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[autotest]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[hackfest]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[texmate]]></category>
		<category><![CDATA[zentest]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2007/06/06/create-a-rails-edge-rspec-project</guid>
		<description><![CDATA[Recently I helped few people moving to Rails Edge and start using RSpec. I realized that I learned few tricks and even if for me everything seemed quite simple, things are not that simple when you recently started with Rails.
This would work on Mac and Linux, sorry Windows users, you&#8217;ll have to slightly change the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I helped few people moving to <a href="http://dev.rubyonrails.org/">Rails Edge</a> and start using <a href="http://rspec.rubyforge.org">RSpec</a>. I realized that I learned few tricks and even if for me everything seemed quite simple, things are not that simple when you recently started with Rails.</p>
<p>This would work on Mac and Linux, sorry Windows users, you&#8217;ll have to slightly change the code below.</p>
<h1>Live on the Edge</h1>
<p>This is actually a bit tricky but it was very well covered by <a href="http://addictedtonew.com/about/">John Nunemaker</a> in <a href="http://railstips.org/2007/5/31/even-edgier-than-edge-rails">this post</a></p>
<p>To sum John&#8217;s post:</p>
<p>Create a normal rails project:</p>
<pre><code>$ rails my_project
$ cd my_project

$ rake rails:freeze:edge
</code></pre>
<p>(or use checkout edge in the vendor folder)</p>
<pre><code>$ cd ..
$ ruby my_project/vendor/rails/railties/bin/rails my_edgie_project
</code></pre>
<p>You now have have a real Edge project called my<em>edgie</em>project. You can delete the my_project folder since we only used it to create our real edge project.</p>
<p>Now, we are not really done since we need to add the Edge files into our vendor folder so we don&#8217;t use our local rails gem.</p>
<p>I would refer to another post from John, that you can find <a href="http://railstips.org/2007/3/5/my-local-rails-setup">there</a></p>
<pre><code>$ mkdir ~/rails
$ cd ~/rails
$ svn co http://dev.rubyonrails.com/svn/rails/trunk .
</code></pre>
<p>We just created a rails folder called rails in our home folder and we checked out edge/trunk in it.<br />
Now let&#8217;s go in our Rails app and setup a symlink to the trunk folder we just created.</p>
<pre><code>$ cd ~/rails_projects/my_edgie_project
$ ln -s ~/rails/trunk vendor/rails
</code></pre>
<p>If you are using subversion, you can ignore the symlink so it doesnâ€™t try to version it:</p>
<pre><code>$ svn propset svn:ignore "rails" vendor/
$ svn commit -m "using new sweet rails setup as recommended by John Nunemaker"
$ svn up
</code></pre>
<p><a href="http://railstips.org/2007/3/5/my-local-rails-setup">Read more</a> for advanced settings etc&#8230;</p>
<h1>Install RSpec</h1>
<p>Very straight forward, you just need to follow <a href="http://rspec.rubyforge.org/documentation/rails/install.html">the documentation</a></p>
<pre><code>$ cd ~/rails_projects/my_edgie_project
$ ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec
$ ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails
</code></pre>
<p>If you have TextMate, you might want to download the <a href="http://rubyforge.org/frs/?group_id=797">latest RSpec-X.Y.Z.tmbundle.tgz Bundle</a></p>
<p>Next thing you want to do is to install <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">ZenTest</a></p>
<pre><code>$ sudo gem install ZenTest
</code></pre>
<p>Make sure you install all the required packages.</p>
<p>If you are using <a href="http://growl.info/">Growl</a> create a new file called .autotest in your home directory:</p>
<pre><code>$mate ~./autotest
</code></pre>
<p>and add the following 2 lines to be warned when your specs/examples fail/pass</p>
<pre><code>require 'autotest/redgreen'
require 'autotest/growl'
</code></pre>
<p>Now, lets go back to our project and create a model using the rspec scaffold (it uses scaffold_resource generator and create all the specs for you)</p>
<pre><code>$ cd ~/rails_projects/my_edgie_project
$ ruby script/generate rspec_scaffold User first_name:string last_name:string :age:integer
</code></pre>
<p>Now, let&#8217;s start autotest (from zentest) so out code is tested in the background</p>
<pre><code>$ autotest
</code></pre>
<p>There you go, really to modify your RSpec examples, make them fail, fix your code, examples should pass, refactor your code and start again <img src='http://railsontherun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2007/06/06/create-a-rails-edge-rspec-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

