<?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>I.NFECTIO.US: Testing Gotchas in Rails</title>
    <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>"Nothing in life is worth doing if you have no life while doing it"</description>
    <item>
      <title>Testing Gotchas in Rails</title>
      <description>I just spent the past several hours tracking down an issue with my tests. I use a combination of autotest from the &lt;a href="http://www.zenspider.com/ZSS/Products/ZenTest/"&gt;ZenTest Suite&lt;/a&gt; and &lt;a href="http://blog.codahale.com/2006/05/26/rails-plugin-rails_rcov/"&gt;rails_rcov&lt;/a&gt; for my Rails testing. While testing using autotest, all my tests were passing just fine. I then went to check test-code coverage and all of a sudden I have a failing test.&lt;br /&gt;&lt;br /&gt;

* rake test:functionals:rcov - failed.&lt;br /&gt;
* rake test:functionals - failed&lt;br /&gt;
* ruby test/functional/clients_controller_test.rb - passed&lt;br /&gt;
* autotest - passed

&lt;br /&gt;&lt;br /&gt;
So what gives? Basically, when running tests using the rake tasks, the test databases are recreated each time you run the task via rake db:test:clone. The real problem was that I was failed to load one of my fixtures in my functional test, but since the data existed from a previous test which used those fixtures, the tests passed. But when running the test from the rake task which resets all the tables, no fixture data existed in the database causing the difference in behavior between the two tools.
&lt;br /&gt;&lt;br /&gt;
As always, if your tests are hokie, CHECK YOUR FIXTURES FIRST! Enjoy this tip.&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 09 Oct 2006 21:07:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:dbaec1b3-4d16-4dbf-9813-ebc13cebcdfa</guid>
      <author>Bob Silva</author>
      <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails</link>
      <category>Ruby on Rails</category>
      <category>rails</category>
      <category>testing</category>
    </item>
    <item>
      <title>"Testing Gotchas in Rails" by matt</title>
      <description>I most often run my tests seperatly, during development, so I experience this problem from the other direction.  Loading up the fixtures returns the db to an expected state that tests depend on.  What ends up happening when you forget to include the fixtures is that an earlier test will run, loading up the db and manipulating the records, then when it gets to the next test, the db isn't in expected state, so the test fails.  

Yea, first time, it was really confusing why individual tests passed, but the entire test suite failed.</description>
      <pubDate>Thu, 22 Feb 2007 11:15:39 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:8616fcf2-d813-49f3-bd87-0b883c04d511</guid>
      <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails#comment-264</link>
    </item>
    <item>
      <title>"Testing Gotchas in Rails" by Bob Silva</title>
      <description>I just run them separately.</description>
      <pubDate>Thu, 02 Nov 2006 11:45:07 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:6ed473ec-40f5-4b79-990f-13818ed9b066</guid>
      <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails#comment-215</link>
    </item>
    <item>
      <title>"Testing Gotchas in Rails" by Rich Waters</title>
      <description>Ran into the same issue not long ago.

Btw, are you getting autotest to run rcov? or are you just using them both separately?</description>
      <pubDate>Wed, 01 Nov 2006 11:34:26 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:d16d490f-701d-44bf-9ce0-1b48b1aff345</guid>
      <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails#comment-213</link>
    </item>
    <item>
      <title>"Testing Gotchas in Rails" by Rich Waters</title>
      <description>Ran into the same issue not long ago.

Btw, are you getting autotest to run rcov? or are you just using them both separately?</description>
      <pubDate>Wed, 01 Nov 2006 11:34:24 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:561e4136-63d0-4ae5-a577-de103871661a</guid>
      <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails#comment-212</link>
    </item>
    <item>
      <title>"Testing Gotchas in Rails" by Luke Redpath</title>
      <description>Its things like that make me avoid Rails fixtures like the plague - a terribly thought out idea if there ever was one. There is a perfectly natural home for test fixtures....setup/teardown. Create fixtures as and when you need them - loading in fixtures in bulk using Rails' fixtures functionality makes your tests slow and brittle (you'd be amazed at the speed increase you get by not using them!). More:

&lt;a href="http://glu.ttono.us/articles/2006/08/07/why-fixtures-suck-and-how-we-can-fix-them" rel="nofollow"&gt;http://glu.ttono.us/articles/2006/08/07/why-fixtures-suck-and-how-we-can-fix-them&lt;/a&gt;</description>
      <pubDate>Tue, 10 Oct 2006 05:54:58 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:03a56d34-0285-45cd-83e6-a2977c8eca0c</guid>
      <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails#comment-186</link>
    </item>
    <item>
      <title>"Testing Gotchas in Rails" by seb</title>
      <description>Damn correct, I spent a long time months ago on this!!
Great to share it on your blog
&lt;br /&gt;
Seb
</description>
      <pubDate>Mon, 09 Oct 2006 23:45:39 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:5a255fb7-4172-42df-862e-cd993a41872c</guid>
      <link>http://i.nfectio.us/articles/2006/10/09/testing-gotchas-in-rails#comment-185</link>
    </item>
  </channel>
</rss>
