<?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>PMA Media Group&#187; rspec</title>
	<atom:link href="http://www.pmamediagroup.com/tag/rspec/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pmamediagroup.com</link>
	<description>Unique Marketing Techniques and Strategies with Guaranteed Results!</description>
	<lastBuildDate>Fri, 27 Aug 2010 18:14:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Why Test?</title>
		<link>http://www.pmamediagroup.com/2009/06/why-test/</link>
		<comments>http://www.pmamediagroup.com/2009/06/why-test/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 20:23:19 +0000</pubDate>
		<dc:creator>fugufish</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=843</guid>
		<description><![CDATA[I come to PMA from a large corporation over 40,000 employees strong, including an entire army of QA Engineers testing every change and release we made, something we took full advantage of. At first, I was of the opinion (as many BDD converts) that the process of defining the and testing the code before actually [...]]]></description>
			<content:encoded><![CDATA[<p>I come to PMA from a large corporation over 40,000 employees strong, including an entire army of QA Engineers testing every change and release we made, something we took full advantage of. At first, I was of the opinion (as many BDD converts) that the process of defining the and testing the code before actually writing the code would slow me down. As I moved more and more to BDD however, I found that I was completing tasks faster. The time saved comes from the ability to define how you expect your application to work. By doing this you will find that your actual code requires much less debugging. Things just seem to work. It continuously surprises me using BDD that things just work, so instead of spending hours looking for a mistyped association, I can spend those hours in actually coding.</p>
<p>Even with an army of QA Engineers, some bugs will sneak through. QA time on untested code takes longer, and debugging the code even longer than that. The release process can go from a day to several days, or even weeks.</p>
<p>With BDD, when new features are added to the application, it as easy as running your spec or test suite to ensure that the original functionality is undamaged. It of course seems like a no brainer to me now. It&#8217;s like looking back and remembering when you thought the world was flat, and seeing how narrow minded you were. The moral of the story? Test before you code! You fill find yourself with more time, and less headaches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/06/why-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Culerity and Celerity, JavaScript enabled testing in Cucumber</title>
		<link>http://www.pmamediagroup.com/2009/06/culerity-and-celerity-javascript-enabled-testing-in-cucumber/</link>
		<comments>http://www.pmamediagroup.com/2009/06/culerity-and-celerity-javascript-enabled-testing-in-cucumber/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 23:02:30 +0000</pubDate>
		<dc:creator>fugufish</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[activescaffold]]></category>
		<category><![CDATA[celerity]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[culerity]]></category>
		<category><![CDATA[htmUnit]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=821</guid>
		<description><![CDATA[As you may know, testing JavaScript inesnsive applications using Cucumber can be a pain. There are several ways to handle this; Selenium, Watir and the like. The easiest way I have found however is by using Celerity a jRuby API for htmlUnit, a fully functional headless browser that completely supports JavaScript, and you don&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know, testing JavaScript inesnsive applications using Cucumber can be a pain. There are several ways to handle this; Selenium, Watir and the like. The easiest way I have found however is by using <a title="Celerity" href="http://celerity.rubyforge.org/">Celerity</a> a jRuby API for htmlUnit, a fully functional headless browser that completely supports JavaScript, and you don&#8217;t have to serve your application on jRuby to use it!. I was able to get Celerity to play nice duruing Cucumber tests by doing the following:  First, you will need of course jRuby. The Culerity gem will start up Celerity in the jRuby environment, and proxy the actual browser through it. Download <a title="jRuby" href="http://jruby.codehaus.org/">jRuby</a> and extract it to wherever you want it located. In my case I put it in /opt, and set your PATH accordingly.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">export PATH=$HOME<span style="color:#006600; font-weight:bold;">/</span>jruby<span style="color:#006600; font-weight:bold;">/</span>bin:$PATH</pre></div></div>

<p>Next install the Celerity gem in jRuby (we are using the github version rather than the ruby forge version, as it provides a later version):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">jruby <span style="color:#006600; font-weight:bold;">-</span>S gem install jarib<span style="color:#006600; font-weight:bold;">-</span>celerity <span style="color:#006600; font-weight:bold;">--</span>source=http:<span style="color:#006600; font-weight:bold;">//</span>gems.<span style="color:#9900CC;">github</span>.<span style="color:#9900CC;">com</span></pre></div></div>

<p>Now install the Culerity gem. This provides the interface between Celerity and your environment without forcing you to run in jRuby</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> gem install langalex<span style="color:#006600; font-weight:bold;">-</span>culerity <span style="color:#006600; font-weight:bold;">--</span>source http:<span style="color:#006600; font-weight:bold;">//</span>gems.<span style="color:#9900CC;">github</span>.<span style="color:#9900CC;">com</span></pre></div></div>

<p>Place this in your test environment:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># config/environments/test.rb</span>
&nbsp;
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;langalex-culerity&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>

<p>I call <code>:lib =&gt; false</code> here to avoid loading the gem. This is done in the file generated by culerity.  Finally remove <code>features/steps/webrat_steps.rb</code> as it will conflict with Culerity, and run:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>generate culerity</pre></div></div>

<p>Enjoy!  Culerity should have very similar syntax to webrat, however keep in mind you may see some differences that you may need to adjust.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/06/culerity-and-celerity-javascript-enabled-testing-in-cucumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: How to install/setup RSpec (and Factory Girl) in Rails</title>
		<link>http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-factory-girl/</link>
		<comments>http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-factory-girl/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 22:04:56 +0000</pubDate>
		<dc:creator>Alan Carl Mitchell</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[factory girl]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=277</guid>
		<description><![CDATA[This tutorial assumes that you have ruby, rails, and mysql installed on your machine. This tutorial also doesn&#8217;t explain much about RSpec or Factory Girl and will just show you a quick way to get them working in a RoR environment.

 .code_div {   background:#000000;   color:#ffffff;   padding:10px;   margin:15px; [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial assumes that you have ruby, rails, and mysql installed on your machine. This tutorial also doesn&#8217;t explain much about <a href="http://rspec.info/">RSpec</a> or <a href="http://www.thoughtbot.com/projects/factory_girl/">Factory Girl</a> and will just show you a quick way to get them working in a RoR environment.</p>
<p><span id="more-277"></span></p>
<style> .code_div {   background:#000000;   color:#ffffff;   padding:10px;   margin:15px; }</style>
<style>  .step_number {   font-weight: bold;   font-size: 1.2em; } </style>
<style> .file_name_div {   font-weight: bold;   margin:15px; }  </style>
<p><span class="step_number">Create the Rails Project</span><br />
Go to your projects directory and create a rails project. Just for fun, let&#8217;s call it &#8216;bank&#8217;:</p>
<div class="code_div">user@host:~$ cd projects<br />
user@host:~/projects$ rails -d mysql bank<br />
user@host:~/projects$ cd bank<br />
user@host:~/projects/bank$</div>
<p><span class="step_number">Create MySQL Databases</span><br />
Go into mysql and create the two databases that rails has set up the bank project to use:</p>
<div class="code_div">user@host:~/projects/bank$ mysql -u root -p<br />
mysql&gt;create database bank_development<br />
mysql&gt;create database bank_test<br />
mysql&gt;exit<br />
Bye<br />
user@host:~/projects/bank$</div>
<p><span class="step_number">Put Gems Into Environments</span><br />
Edit the files</p>
<div class="file_name_div">config/environments/development.rb</div>
<p>and</p>
<div class="file_name_div">config/environments/test.rb:</div>
<p>and add the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;thoughtbot-factory_girl&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'factory_girl'</span>, <span style="color:#ff3333; font-weight:bold;">:source</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'http://gems.github.com'</span>
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;rspec&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1.2.2'</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'spec'</span>
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;rspec-rails&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1.2.2'</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>

<p>This sets up the test and development environments to use rspec and factory girl.</p>
<p><span class="step_number">Install the Gems</span><br />
Install the gems referenced in your environments:</p>
<div class="code_div">user@host:~/projects/bank$ rake gems:install</div>
<p>You&#8217;ll see output that says that the gems were installed, if you didn&#8217;t have them already.</p>
<p><span class="step_number">Bootstrap RSpec</span><br />
Do a:</p>
<div class="code_div">user@host:~/projects/bank$ script/generate rspec</div>
<p>You will see the following:</p>
<div class="code_div">user@host:~/projects/bank$ script/generate rspec<br />
exists  lib/tasks<br />
create  lib/tasks/rspec.rake<br />
create  script/autospec<br />
create  script/spec<br />
create  script/spec_server<br />
create  spec<br />
create  spec/rcov.opts<br />
create  spec/spec.opts<br />
create  spec/spec_helper.rb<br />
user@host:~/projects/bank$</div>
<p>This generates some default rspec files and directories that the project will use.</p>
<p><span class="step_number">Generate Model, Test, and Migration with rspec_model</span><br />
Do a:</p>
<div class="code_div">user@host:~/projects/bank$ script/generate rspec_model BankAccount</div>
<p>You will see the following output:</p>
<div class="code_div">user@host:~/projects/bank$ script/generate rspec_model BankAccount<br />
exists  app/models/<br />
create  spec/models/<br />
create  spec/fixtures/<br />
create  app/models/bank_account.rb<br />
create  spec/models/bank_account_spec.rb<br />
create  spec/fixtures/bank_accounts.yml<br />
create  db/migrate<br />
create  db/migrate/20090402160952_create_bank_accounts.rb<br />
user@host:~/projects/bank$</div>
<p>This will create a default test at</p>
<div class="file_name_div">spec/models/bank_account_spec.rb</div>
<p>and a BankAccount model in</p>
<div class="file_name_div">app/models/bank_account.rb</div>
<p>and a migration in</p>
<div class="file_name_div">db/migrate/20090402160952_create_bank_accounts.rb</div>
<p>You can also do a script/generate rspec_scaffold BankAccount.</p>
<p><span class="step_number">Edit the Test</span><br />
Go to</p>
<div class="file_name_div">spec/models/bank_account_spec.rb</div>
<p>and you will see:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../spec_helper'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
describe BankAccount <span style="color:#9966CC; font-weight:bold;">do</span>
  before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#0066ff; font-weight:bold;">@valid_attributes</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  it <span style="color:#996600;">&quot;should create a new instance given valid attributes&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    BankAccount.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>@valid_attributes<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Since this is a bank account, one of the behaviors that we would expect is to be able to make deposits into it. That being the case, let&#8217;s change the test to</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../spec_helper'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
describe BankAccount <span style="color:#9966CC; font-weight:bold;">do</span>
  before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#0066ff; font-weight:bold;">@bank_account</span> = BankAccount.<span style="color:#9900CC;">create</span>
    <span style="color:#0066ff; font-weight:bold;">@bank_account</span>.<span style="color:#9900CC;">balance</span> = <span style="color:#006666;">0</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  it <span style="color:#996600;">&quot;should increase the balance upon deposit&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#0066ff; font-weight:bold;">@bank_account</span>.<span style="color:#9900CC;">deposit</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@bank_account</span>.<span style="color:#9900CC;">balance</span>.<span style="color:#9900CC;">should</span> == <span style="color:#006666;">100</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Also, edit</p>
<div class="file_name_div">spec/spec.opts</div>
<p>and change &#8216;progress&#8217; to &#8217;specdoc&#8217; (because it will make rspec output look a lot better)</p>
<p><span class="step_number">Edit the Migration</span><br />
We need to add the &#8216;balance&#8217; attribute to the model. Go to</p>
<div class="file_name_div">db/migrate/20090402160952_create_bank_accounts</div>
<p>(or some file like that)</p>
<p>and change the migration to</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateBankAccounts <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:bank_accounts</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#CC0066; font-weight:bold;">float</span> <span style="color:#ff3333; font-weight:bold;">:balance</span>
&nbsp;
      t.<span style="color:#9900CC;">timestamps</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    drop_table <span style="color:#ff3333; font-weight:bold;">:bank_accounts</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><span class="step_number">Edit the Model</span> Now we need to add the deposit method to the BankAccount model. Go to</p>
<div class="file_name_div">app/models/bank_account.rb</div>
<p>Change the class to</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> BankAccount <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> deposit<span style="color:#006600; font-weight:bold;">&#40;</span>amount<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">balance</span> = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">balance</span> <span style="color:#006600; font-weight:bold;">+</span> amount
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><span class="step_number">Migrate the DB, Run RSpec</span> Now, do a</p>
<div class="code_div">user@host:~/projects/bank$ rake db:migrate</div>
<p>and then a</p>
<div class="code_div">user@host:~/projects/bank$ rake spec</div>
<p>You should see:</p>
<div class="code_div">user@host:~/projects/bank$ rake spec<br />
(in /home/osadmin/projects/bank_account/bank)</p>
<p>BankAccount<br />
<span style="color:green;">- should increase the balance upon deposit</span></p>
<p>Finished in 0.066398 seconds</p>
<p><span style="color:green;">1 example, 0 failures</span><br />
user@host:~/projects/bank$</div>
<p>At this point, RSpec is functioning.</p>
<p><span class="step_number">Add Factory Girl</span><br />
Want to add Factory Girl? The environments are already set up and gem is installed. The rest is not hard:</p>
<p>Create a &#8216;factories&#8217; directory under the &#8217;spec&#8217; directory.</p>
<div class="code_div">user@host:~/projects/bank$ mkdir spec/factories<br />
user@host:~/projects/bank$</div>
<p>and make the file</p>
<div class="file_name_div">spec/factories/bank_accounts.rb</div>
<p>and put this inside:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:bank_account</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>ba<span style="color:#006600; font-weight:bold;">|</span>
  ba.<span style="color:#9900CC;">add_attribute</span> <span style="color:#ff3333; font-weight:bold;">:balance</span>, <span style="color:#006666;">0</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><span class="step_number">Edit the Test</span><br />
Open</p>
<div class="file_name_div">spec/models/bank_account_spec.rb</div>
<p>Change the body of the before each block to</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@bank_account</span> = Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:bank_account</span>, <span style="color:#ff3333; font-weight:bold;">:balance</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Since the factory you just made (spec/factories/bank_accounts.rb) automatically sets the balance to 0, you could leave the body with just</p>
<p>@bank_account = Factory(:bank_account)</p>
<p>and it would still work.</p>
<p>The finished <span style="font-weight:bold;">spec/models/bank_account_spec.rb</span> will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../spec_helper'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
describe BankAccount <span style="color:#9966CC; font-weight:bold;">do</span>
  before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#0066ff; font-weight:bold;">@bank_account</span> = Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:bank_account</span>, <span style="color:#ff3333; font-weight:bold;">:balance</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  it <span style="color:#996600;">&quot;should increase the balance upon deposit&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#0066ff; font-weight:bold;">@bank_account</span>.<span style="color:#9900CC;">deposit</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@bank_account</span>.<span style="color:#9900CC;">balance</span>.<span style="color:#9900CC;">should</span> == <span style="color:#006666;">100</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><span class="step_number">Watch RSpec Run With Factory Girl</span><br />
Watch the test run with Factory Girl:</p>
<div class="code_div">user@host:~/projects/bank$ rake spec<br />
(in /home/osadmin/projects/bank_account/bank)</p>
<p>BankAccount<br />
<span style="color:green;">- should increase the balance upon deposit</span></p>
<p>Finished in 0.066398 seconds</p>
<p><span style="color:green;">1 example, 0 failures</span><br />
user@host:~/projects/bank$</div>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-factory-girl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.pmamediagroup.com @ 2012-02-05 02:54:43 -->
