<?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>Simon &#187; Rails</title>
	<atom:link href="http://owls-count.net/blog/category/computer/rails/feed" rel="self" type="application/rss+xml" />
	<link>http://owls-count.net</link>
	<description>I am me</description>
	<lastBuildDate>Fri, 30 Jul 2010 05:34:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Testing in Ruby on Rails</title>
		<link>http://owls-count.net/blog/computer/testing-in-ruby-on-rails</link>
		<comments>http://owls-count.net/blog/computer/testing-in-ruby-on-rails#comments</comments>
		<pubDate>Thu, 01 Mar 2007 10:14:15 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://owls-count.net/blog/computer/testing-in-ruby-on-rails</guid>
		<description><![CDATA[The main struggle I had when I first started coding in Ruby on Rails was working out how to use tests. Ruby, and Rails, have a great testing framework, but I had no background in knowing how, and what, to test. As I have progressed with the language I have become more confident in writing [...]]]></description>
			<content:encoded><![CDATA[<p>The main struggle I had when I first started coding in <a href="http://www.rubyonrails.org/">Ruby on Rails</a> was working out how to use tests. Ruby, and Rails, have a great testing framework, but I had no background in knowing how, and what, to test. As I have progressed with the language I have become more confident in writing tests and I am now noticing the benefit of writing them.</p>
<p>A couple of the tools I use in testing are <a href="http://eigenclass.org/hiki.rb?rcov">rcov</a> and <a href="http://glu.ttono.us/articles/2006/12/19/tormenting-your-tests-with-heckle">Heckle</a>. Between these tools you can reveal just how well you are testing your Ruby application.<br />
<span id="more-48"></span><br />
<b>rcov</b><br />
With rcov you can run your tests and see which lines of code were executed during the tests. I find this really useful for reminding me which sections of code I have forgotten to write tests for. I use a modification of Mike Clark&#8217;s <a href="http://www.clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask">suggestion</a> for running the coverage tests.<br />
<code>namespace :test do<br />
  desc 'Measure test coverage'<br />
  task :coverage do<br />
    system("rcov --rails --text-summary -Ilib --xrefs --html test/unit/*_test.rb test/functional/*_test.rb test/views/*_test.rb test/integration/*_test.rb")<br />
    system("open coverage/index.html") if PLATFORM['darwin']<br />
    system("firefox coverage/index.html") if PLATFORM['linux']<br />
  end<br />
end</code><br />
Note that the firing of Firefox to view the tests on Linux will only work if you can type <i>firefox</i> in a terminal and have it open a web browser for you. If this does not work then you can replace &#8216;firefox&#8217; with another browser. On Kubuntu (and, so, I assume the rest of the Ubuntu family) <i>sensible-browser</i> will work.</p>
<p><b>Heckle</b><br />
While rcov lets you know if a line of code is executed during testing it is useful to know if the line is actually tested. This is where Heckle comes in. It tests your tests.</p>
<p>Simply you run it with<br />
<code>heckle [classname]</code><br />
and watch it go to work on your code. It takes the code in the class, mutates it in some way, and runs it against your tests. If your tests do not fail when code in the class is mutated then that section of code was never being tested. Simple and effective.</p>
]]></content:encoded>
			<wfw:commentRss>http://owls-count.net/blog/computer/testing-in-ruby-on-rails/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
