<?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; factory_girl</title>
	<atom:link href="http://railsontherun.com/tag/factory_girl/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>db fixtures replacement solution step by step</title>
		<link>http://railsontherun.com/2008/09/07/db-fixtures-replacement-solution-step-by-step/</link>
		<comments>http://railsontherun.com/2008/09/07/db-fixtures-replacement-solution-step-by-step/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 16:06:00 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[datamapper]]></category>
		<category><![CDATA[factory_girl]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[spec]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://railsontherun.com/2008/09/07/db-fixtures-replacement-solution-step-by-step</guid>
		<description><![CDATA[Like most people who started with Rails a while back, I first loved Rails fixtures and ended up hating them (slow, a pain to maintain etc&#8230;).
I went through different experiments, trying different existing libs, writing my own solutions etc&#8230; I wasn&#8217;t quite satisfied until I found factory_girl from thoughtbot.
You might not feel the need for [...]]]></description>
			<content:encoded><![CDATA[<p>Like most people who started with Rails a while back, I first loved Rails fixtures and ended up hating them (slow, a pain to maintain etc&#8230;).</p>
<p>I went through different experiments, trying different existing libs, writing my own solutions etc&#8230; I wasn&#8217;t quite satisfied until I found <a href="http://github.com/thoughtbot/factory_girl">factory_girl</a> from <a href="http://www.thoughtbot.com/">thoughtbot</a>.</p>
<p>You might not feel the need for a decent fixtures solution if you do a lot of mocking/stubbing, but I recently came back from my &#8220;mock everything you can outside of models&#8221; approach and I&#8217;m getting closer to the <a href="http://snipr.com/3nwry">mock roles, not objects</a> approach. So, I&#8217;m loosing my model/controller testing separation but I&#8217;m gaining by not having to maintain &#8220;dumb mocks&#8221; which don&#8217;t always represent the real API behind. I mean, how many times did I change a Model, messing up my app but all my specs were still passing. Anyway, that&#8217;s a long discussion, which will be covered by <a href="http://yehudakatz.com/">wycats</a> during <a href="http://merbcamp.com">merbcamp</a></p>
<p>So here is a simple example of how I use <a href="http://github.com/thoughtbot/factory_girl">factory girl</a> in a Merb + DataMapper app. (you can do the same in a Rails app, there is <strong>nothing</strong> specific to Merb in factory_girl).</p>
<ul>
<li>I. create an empty app, set the ORM etc&#8230;</li>
<li>II. git pull and install factory<em>girl from <a href="http://github.com/thoughtbot/factory_girl/tree/master">http://github.com/thoughtbot/factory</a></em><a href="http://github.com/thoughtbot/factory_girl/tree/master">girl/tree/master</a>. Or install thoughtbot-factory_girl gem using <a href="http://gems.github.com">GitHub gem server</a>.</li>
<li><strong>III.</strong> create a spec/factories.rb file. (You might prefer to create a folder called spec/factories and add a factory per model)</li>
<li><strong>IV.</strong> modify spec_helper.rb and add the following</li>
</ul>
<pre class="brush:ruby">
  require 'factory_girl'
  require File.dirname(__FILE__) + '/factories'
</pre>
<ul>
<li>V. write some specs against a Client model</li>
</ul>
<p><script src="http://gist.github.com/9276.js"></script></p>
<ul>
<li><strong>VI.</strong> Create the Model</li>
</ul>
<p><script src="http://gist.github.com/9277.js"></script></p>
<ul>
<li><strong>VII.</strong> create a factory</li>
</ul>
<p><script src="http://gist.github.com/9278.js"></script></p>
<ul>
<li>
<strong>IIX.</strong> run your specs</p>
<p><img src="http://img.skitch.com/20080907-tf8yy6fi82b23t78stqii3mpbe.jpg" alt="failing specs" />
</li>
<li>
<strong>IX.</strong> fix the model (note that I set <code>dependencies "dm-validations"</code> in my init.rb)
</li>
</ul>
<p><script src="http://gist.github.com/9279.js"></script></p>
<ul>
<li>X. run the specs
<p><img src="http://img.skitch.com/20080907-m7p2r6q1qau4k3qsmeadwu2tur.jpg" alt="passing specs" /></li>
<li><strong>XI.</strong> add more specs</li>
</ul>
<p><script src="http://gist.github.com/9264.js"></script></p>
<p>As you can see, Factory.build(:client) only creates a new instance of the Object, while Factory(:client) creates, saves and loads the instance.</p>
<ul>
<li><strong>XII.</strong> get them to pass</li>
</ul>
<p><script src="http://gist.github.com/9265.js"></script></p>
<p>Factory Girl makes fixtures simple and clean. Here is another example for creating associations:</p>
<p><script src="http://gist.github.com/9269.js"></script></p>
<p>Factory Girl also supports sequencing, check out FG <a href="http://github.com/thoughtbot/factory_girl">read me</a></p>
<h2>In conclusion, Factory Girl is a mature and solid factory solution which will take you less than 15 minutes to get used to. It will offer you loads of flexibility and less frustration than good old yaml fixtures. You can also use it with existing fixtures if you want to start using it in an existing app.</h2>
]]></content:encoded>
			<wfw:commentRss>http://railsontherun.com/2008/09/07/db-fixtures-replacement-solution-step-by-step/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

