<?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>The Lucid &#187; Rails</title>
	<atom:link href="http://thelucid.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://thelucid.com</link>
	<description>Lightweight ramblings</description>
	<lastBuildDate>Tue, 27 Jul 2010 17:41:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>&#8220;Ramble&#8221;, the Javascript Cucumber Port (work in progress)</title>
		<link>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/</link>
		<comments>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 02:27:12 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=608</guid>
		<description><![CDATA[I am a great fan of Cucumber when it comes to integration testing, however testing heavy use of Javascript can be a little tedious. I have looked into the different solutions out there such as Selenium but found them all to be fiddly to setup, however Capybara helps on this front. I was thinking, what [...]]]></description>
			<content:encoded><![CDATA[<p>I am a great fan of <a href="http://cukes.info/">Cucumber</a> when it comes to integration testing, however testing heavy use of Javascript can be a little tedious.</p>
<p>I have looked into the different solutions out there such as <a href="http://seleniumhq.org/">Selenium</a> but found them all to be fiddly to setup, however <a href="http://github.com/jnicklas/capybara">Capybara</a> helps on this front. I was thinking, what if Cucumber could run in the browser? No need for Javascript adapters or XML parsers, Safari/Chrome/Firefox already do a great job of this. Manipulating the page such as filling in forms, clicking links etc. could all be done with jQuery, in a very concise manor.</p>
<p>I decided to create a proof-of-concept while it was still fresh in my head. This is by no means a fully working release and the code leaves a lot to be desired in it&#8217;s current state, however it shows the benefits of a &#8220;Cucumber in the browser&#8221;. The main benefits I can see so far (for both javascript and non javascript apps) are:</p>
<ul>
<li><strong>Speed</strong> &#8211; browsers are getting extremely quick at this DOM stuff.</li>
<li><strong>Flexibility</strong> &#8211; everything happens client-side meaning you can easily test with any server technology.</li>
<li><strong>Simplicity</strong> &#8211; no need for complex javascript adapters, XML parsers etc.</li>
</ul>
<p>The basic file structure is very similar to Cucumber:</p>
<pre>
  - features
    index.html
    - js
        ramble.js
        jquery-1.4.2.js
      my.feature
    - steps
        web-steps.js
    - support
        paths.js
</pre>
<p>Step definitions can be defined in plain old javascript files with plain old jQuery, in this case web-steps.js. Currently the step definition are expected to throw an error if they cannot be fulfilled, this may change when a solid API is nailed down:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #006600; font-style: italic;">// The value of 'this' is the current document as a jQuery object.</span>
  ramble.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^I follow &quot;(.+)&quot;$/</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>link_text<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> link_text<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>link.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">throw</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Can't find link: &quot;</span> <span style="color: #339933;">+</span> link_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    link.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Scenarios are exactly the same as in Cucumber, so you can do something like the following:</p>
<pre>
  Scenario: User fill out a form
    Given I am on the homepage
    And I follow "Tell us your name"
    And I fill in "First name" with "Jamie"
    And I fill in "Last name" with "Hill"
    And I press "Submit"
    Then I should see "Thank you for your details."
</pre>
<p>You can now simply drop the features folder into the public area of your app and visit the url in your browser. You should see the relevant steps go green or red as the app is navigated in an iFrame.</p>
<p>I plan to first tidy up the API (and unit test) and then aid the writing of scenarios by adding the ability to record them within the browser (Selenium style).</p>
<p>I&#8217;d like to hear peoples views on this&#8230; please don&#8217;t be too hard on the code, it&#8217;s more of a mind-dump than anything else at this stage (around 100 lines). There is an example of testing a static site included so just load the features/index.html file in your browser to see it run.</p>
<p>  <a href="http://github.com/soniciq/ramble">http://github.com/soniciq/ramble</a></p>
<p><strong>Update 04/07/10:</strong> As noted by Andrew in the comments, you will need a server running in order for browsers to get access to the pages for testing.</p>
<p>I have added a simple server script allowing the features to be run locally (requires Ruby). If you want to see it in action, just run:</p>
<pre>
cd /path/to/ramble/checkout
ruby server.rb
</pre>
<p>&#8230;and then visit <a href="http://localhost:1234/features">http://localhost:1234/features</a> in your browser (tested in Firefox, Chrome and Safari). Note that Ramble is not at all dependent on Ruby, it is just used for running a local test server.</p>
<h3>Screenshot</h3>
<p><a href="http://thelucid.com/files/ramble-in-action.png"><img src="http://thelucid.com/files/ramble-in-action-300x241.png" alt="Ramble in action" title="Ramble in action" width="300" height="241" class="aligncenter size-medium wp-image-620" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Nokogiri for Cucumber steps that need to compare HTML attributes</title>
		<link>http://thelucid.com/2010/02/14/nokogiri-for-cucumber-steps-that-need-to-compare-html-attributes/</link>
		<comments>http://thelucid.com/2010/02/14/nokogiri-for-cucumber-steps-that-need-to-compare-html-attributes/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 18:07:07 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails cucumber nokogiri ruby]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=564</guid>
		<description><![CDATA[I have found on numerous occasions that I need to look at HTML attributes when diffing tables etc. in Cucumber. My current need for this arrises as I have a gallery of thumbnails that all have alt tags who&#8217;s values I need to compare as there is not a text equivalent. A feature statement like [...]]]></description>
			<content:encoded><![CDATA[<p>I have found on numerous occasions that I need to look at HTML attributes when diffing tables etc. in Cucumber. My current need for this arrises as I have a gallery of thumbnails that all have alt tags who&#8217;s values I need to compare as there is not a text equivalent.</p>
<p>A feature statement like this:</p>
<pre>
Then I should see the following thumbnails
  | Mona Lisa  |
  | Sunflowers |
</pre>
<p>Could be achieved with the following step:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should see the following thumbnails$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>table<span style="color:#006600; font-weight:bold;">|</span>
  nodes = <span style="color:#6666ff; font-weight:bold;">Nokogiri::HTML</span><span style="color:#006600; font-weight:bold;">&#40;</span>response.<span style="color:#9900CC;">body</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">css</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'ul#gallery li img'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  table.<span style="color:#9900CC;">diff</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>nodes.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>img<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>img.<span style="color:#9900CC;">attributes</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'alt'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/02/14/nokogiri-for-cucumber-steps-that-need-to-compare-html-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I stopped using Pickle with Cucumber</title>
		<link>http://thelucid.com/2010/02/07/why-i-stopped-using-pickle-with-cucumber/</link>
		<comments>http://thelucid.com/2010/02/07/why-i-stopped-using-pickle-with-cucumber/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 02:12:48 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[pickle]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=558</guid>
		<description><![CDATA[&#8230;no, not because it leaves a bitter aftertaste, I&#8217;m talking about the Pickle step definitions for Cucumber. I have lately been using Pickle when writing Cucumber features, however I have come to the conclusion that this is a bad idea. The reason being that when using Pickle, you create entries directly, whereas the whole point [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;no, not because it leaves a bitter aftertaste, I&#8217;m talking about the <a href="http://github.com/ianwhite/pickle">Pickle</a> step definitions for <a href="http://github.com/aslakhellesoy/cucumber/">Cucumber</a>.</p>
<p>I have lately been using <a href="http://github.com/ianwhite/pickle">Pickle</a> when writing <a href="http://github.com/aslakhellesoy/cucumber/">Cucumber</a> features, however I have come to the conclusion that this is a bad idea. The reason being that when using Pickle, you create entries directly, whereas the whole point of Cucumber is that it is for high level integration testing.</p>
<p>What I do now, is to create any entries by filling out and submitting the relevant forms with a step definition, for example I may have the following:</p>
<pre>
Given an admin has created the following products
  | Name    | Variants                                  | Featured |
  | T-Shirt | Small: 10.99, Medium: 12.99, Large: 14.99 | Yes      |
  | Keyring | Default: 2.99                             | Yes      |
</pre>
<p>I would then write a step definition for this that would log in as the admin user, break this table appart and fill in the relevant forms.</p>
<p>I would go so far as to say that using factories at all in features is a bad idea and instead everything should happen via the user interface for better coverage. For any data that is known to exist when the app is deployed via &#8216;rake db:seed&#8217;, this can be loaded in the &#8216;env.rb&#8217; file e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'seeds.rb'</span></pre></div></div>

<p><strong>Update 11/2/2010:</strong> Sometimes this is simply not practical due to slowdown which is a shame, as noted by Amos in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/02/07/why-i-stopped-using-pickle-with-cucumber/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Devise Rails Authentication Gem Rocks!</title>
		<link>http://thelucid.com/2010/02/06/devise-rails-authentication-gem-rocks/</link>
		<comments>http://thelucid.com/2010/02/06/devise-rails-authentication-gem-rocks/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 21:36:28 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[authentication]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=555</guid>
		<description><![CDATA[I&#8217;ve had a set of rather bespoke requirements for authentication on a recent project and thought I&#8217;d give Devise a go. Devise uses Warden, which is an authentication solution build on Rack making it extremely flexible and usable across multiple frameworks e.g. Rails/Sinatra. Also, Devise is extremely modular meaning to can easily write custom &#8220;strategies&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a set of rather bespoke requirements for authentication on a recent project and thought I&#8217;d give <a href="http://github.com/plataformatec/devise">Devise</a> a go.</p>
<p>Devise uses <a href="http://github.com/hassox/warden/">Warden</a>, which is an authentication solution build on <a href="http://github.com/rack/rack">Rack</a> making it extremely flexible and usable across multiple frameworks e.g. Rails/Sinatra. Also, Devise is extremely modular meaning to can easily write custom &#8220;strategies&#8221; for specific behaviour.</p>
<p>I have used <a href="http://github.com/thoughtbot/clearance/">Clearance</a> in the past which is great if you want an engine that will just work. Devise however is by far the most flexible and extensible solution that I have come across with the same ease of use as Clearance. The only thing that you don&#8217;t get with devise that you do with Clearance is the signup stage, however as this is normally custom on a per-app basis I can live with this.</p>
<p>One more thing to note is that Devise lets you have multiple auth systems in play e.g. one for users and one for admins.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/02/06/devise-rails-authentication-gem-rocks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sexy Validation in Edge Rails (Rails 3)</title>
		<link>http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/</link>
		<comments>http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 16:32:47 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SonicIQ]]></category>
		<category><![CDATA[rails sexy-validations rails-3 ruby]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=533</guid>
		<description><![CDATA[I have just had my sexy validations patch excepted into Rails. Much thanks to José Valim for helping me get this applied. The reason for the name &#8220;sexy validations&#8221; is that it gives a much more concise way of defining validation and reusing custom validator classes. Much like what sexy migrations did for defining your [...]]]></description>
			<content:encoded><![CDATA[<p>I have just had my <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3058-patch-sexy-validations">sexy validations patch excepted</a> into Rails. Much thanks to José Valim for helping me get this applied.</p>
<p>The reason for the name &#8220;sexy validations&#8221; is that it gives a much more concise way of defining validation and reusing custom validator classes. Much like what <a href="http://ryandaigle.com/articles/2007/5/6/what-s-new-in-edge-rails-bringin-sexy-back">sexy migrations</a> did for defining your database schema.</p>
<p>Simple example of using existing Rails validations, the &#8220;sexy&#8221; way:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Film <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  validates <span style="color:#ff3333; font-weight:bold;">:title</span>, <span style="color:#ff3333; font-weight:bold;">:presence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:uniqueness</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:length</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:maximum</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">100</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  validates <span style="color:#ff3333; font-weight:bold;">:budget</span>, <span style="color:#ff3333; font-weight:bold;">:presence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:length</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:within</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 1..10000000 <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The power of the &#8220;validates&#8221; method comes though, when using in conjunction with custom validators:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> IntenseFilmTitleValidator <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::EachValidator</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> validate_each<span style="color:#006600; font-weight:bold;">&#40;</span>record, attribute, value<span style="color:#006600; font-weight:bold;">&#41;</span>
    record.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span>attribute<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;must start with 'The'&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> value =~ <span style="color:#006600; font-weight:bold;">/</span>^The<span style="color:#006600; font-weight:bold;">/</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;">class</span> SpendValidator <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::EachValidator</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> validate_each<span style="color:#006600; font-weight:bold;">&#40;</span>record, attribute, value<span style="color:#006600; font-weight:bold;">&#41;</span>
    spend = <span style="color:#9966CC; font-weight:bold;">case</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:size</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#ff3333; font-weight:bold;">:big</span> <span style="color:#9966CC; font-weight:bold;">then</span> <span style="color:#006666;">100000000</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#ff3333; font-weight:bold;">:small</span> <span style="color:#9966CC; font-weight:bold;">then</span> <span style="color:#006666;">100000</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    record.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span>attribute<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;must not exceed #{spend}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> value <span style="color:#006600; font-weight:bold;">&gt;</span> spend
  <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;">class</span> Film <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  validates <span style="color:#ff3333; font-weight:bold;">:title</span>, <span style="color:#ff3333; font-weight:bold;">:presence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:intense_film_title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
  validates <span style="color:#ff3333; font-weight:bold;">:budget</span>, <span style="color:#ff3333; font-weight:bold;">:spend</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:big</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># using custom options</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>All validations in Rails, along with other common model functionality have been extracted into ActiveModel, so you can also use validations and Validator classes without ActiveRecord e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> EmailValidator <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::EachValidator</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> validate_each<span style="color:#006600; font-weight:bold;">&#40;</span>record, attribute, value<span style="color:#006600; font-weight:bold;">&#41;</span>
    record.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span>attribute<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:message</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">&quot;is not an email&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span>
      value =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^@\s<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>@<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">-</span>a<span style="color:#006600; font-weight:bold;">-</span>z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>\.<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">2</span>,<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>i
  <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;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Validations</span>
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:email</span>
&nbsp;
  validates <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:presence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:length</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:maximum</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">100</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  validates <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:presence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Sexy Validations in Rails 3.0</title>
		<link>http://thelucid.com/2009/08/16/sexy-validations-in-rails-30/</link>
		<comments>http://thelucid.com/2009/08/16/sexy-validations-in-rails-30/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 00:54:25 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=513</guid>
		<description><![CDATA[Update: This patch has been applied but this information is out of date, please see: this new post. Having had a patch accepted in Rails, I now have the bug (not a bug&#8230; the bug for writing patches&#8230; anyway). I have just added this patch to allow for &#8220;sexy-migration-esque&#8221; validations using the new ActiveModel. Below [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> This patch has been applied but this information is out of date, please see: <a href="http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/">this new post</a>.</p>
<p>Having had <a href="https://rails.lighthouseapp.com/projects/8994/tickets/2936">a patch accepted</a> in Rails, I now have the bug (not a bug&#8230; the bug for writing patches&#8230; anyway).</p>
<p>I have just added <a href="https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3058-patch-sexy-validations#ticket-3058-2">this patch</a> to allow for &#8220;sexy-migration-esque&#8221; validations using the new ActiveModel. Below explains the gist of it:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">class</span> EmailValidator <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Validator</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> validate
      field = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:attr</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      record.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span>field<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;is not valid&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">unless</span> record.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#41;</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^@\s<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>@<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">-</span>a<span style="color:#006600; font-weight:bold;">-</span>z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>\.<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">2</span>,<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>i
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Register the custom validator in an initializer file.</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveModel::Validations</span>.<span style="color:#9900CC;">register_validator</span> <span style="color:#ff3333; font-weight:bold;">:email</span>, EmailValidator
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> Person <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Base</span>
    attr_accessor <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:email</span>
&nbsp;
    validates <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:presence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:uniqueness</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:length</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:maximum</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">100</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    validates <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:presence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>As with the previous patch I believe this adds even more flexibility which is what Rails 3 is all about. It also allows validators to be shared more easily.</p>
<p>Rails defaults can now also be overridden e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">class</span> RequiredValidator <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Validator</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> validate
      field = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:attr</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      record.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span>field<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;Required&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> record.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">blank</span>?
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#6666ff; font-weight:bold;">ActiveModel::Validations</span>.<span style="color:#9900CC;">register_validator</span> <span style="color:#ff3333; font-weight:bold;">:email</span>, RequiredValidator</pre></div></div>

<p>I would appreciate a <a href="https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3058-patch-sexy-validations#ticket-3058-2">+1 on the ticket</a> from anyone who feels this should be in Rails 3.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2009/08/16/sexy-validations-in-rails-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit testing by simplifying the problem: memoization</title>
		<link>http://thelucid.com/2008/12/18/unit-testing-by-simplifying-the-problem-memoization/</link>
		<comments>http://thelucid.com/2008/12/18/unit-testing-by-simplifying-the-problem-memoization/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 13:16:01 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[unit]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=500</guid>
		<description><![CDATA[I see unit testing as a way to test each possible snippet of functionality and route the code in question can take. With Ruby being such a dynamic language and allowing shortcuts to common problems, sometimes it can seem somewhat of a mystery, how to test these snippets of functionality. Using Memoization as an example: [...]]]></description>
			<content:encoded><![CDATA[<p>I see unit testing as a way to test each possible snippet of functionality and route the code in question can take. With Ruby being such a dynamic language and allowing shortcuts to common problems, sometimes it can seem somewhat of a mystery, how to test these snippets of functionality.</p>
<p>Using Memoization as an example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MyClass
  <span style="color:#9966CC; font-weight:bold;">def</span> lazy_initialized_value
    <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span> <span style="color:#006600; font-weight:bold;">||</span>= Expensive.<span style="color:#9900CC;">request</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>There are actually 3 separate snippets of functionality that need testing here, however it is not immediately obvious from the example. Lets be slightly more verbose about what is actually happening:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MyClass
  <span style="color:#9966CC; font-weight:bold;">def</span> lazy_initialized_value
    <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span> = Expensive.<span style="color:#9900CC;">request</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span>
    <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now it is much easier to see the 3 steps the code should take:</p>
<p>* Store result of expensive request in instance variable<br />
* Leave instance variable alone when it is already set<br />
* Return the value of the instance variable</p>
<p>Now we have this information, our tests become (using Mocha to mock external methods):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Expensive; <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#6666ff; font-weight:bold;">Tests::MyClass</span>
  <span style="color:#008000; font-style:italic;"># lazy_initialized_value</span>
  <span style="color:#008000; font-style:italic;"># ----------------------</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> LazyInitializedValueTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_respond
      assert_respond_to MyClass.<span style="color:#9900CC;">new</span>, <span style="color:#ff3333; font-weight:bold;">:lazy_initialized_value</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_store_result_of_expensive_request_in_instance_variable
      instance = MyClass.<span style="color:#9900CC;">new</span>
      Expensive.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:request</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">with</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">returns</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'expensive value'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      instance.<span style="color:#9900CC;">lazy_initialized_value</span>
      assert_equal <span style="color:#996600;">'expensive value'</span>, instance.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'@lazy_initialized_value'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_return_value_of_instance_varable
      instance = MyClass.<span style="color:#9900CC;">new</span>
      instance.<span style="color:#9900CC;">instance_variable_set</span> <span style="color:#996600;">'@lazy_initialized_value'</span>, <span style="color:#996600;">'the value'</span>
      Expensive.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:request</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      assert_equal <span style="color:#996600;">'the value'</span>, instance.<span style="color:#9900CC;">lazy_initialized_value</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_maintain_existing_instance_variable_value_when_already_set
      instance = MyClass.<span style="color:#9900CC;">new</span>
      instance.<span style="color:#9900CC;">instance_variable_set</span> <span style="color:#996600;">'@lazy_initialized_value'</span>, <span style="color:#996600;">'existing value'</span>
      Expensive.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:request</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      instance.<span style="color:#9900CC;">lazy_initialized_value</span>
      assert_equal <span style="color:#996600;">'existing value'</span>, instance.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'@lazy_initialized_value'</span><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>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now we have these tests in place, we can go back and refractor the code &#8217;til our heart&#8217;s content using all the tricks in the book but by simplifying the problem in the first place, it gives us a solid test suite and the confidence to make changes without breaking functionality.</p>
<p>If you were solving this problem test-first then you wouldn&#8217;t (but more likely, shouldn&#8217;t) have written the first example until re-factoring stage anyway, however when these shortcuts become engrained in your brain, it&#8217;s all too easy to forget what they are _actually_ doing.</p>
<p>So there we go, simplify the initial implementation, get a solid test suite in order, _then_ re-factor.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/12/18/unit-testing-by-simplifying-the-problem-memoization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails: Using Autotest with UnitRecord</title>
		<link>http://thelucid.com/2007/09/05/rails-using-autotest-with-unitrecord/</link>
		<comments>http://thelucid.com/2007/09/05/rails-using-autotest-with-unitrecord/#comments</comments>
		<pubDate>Thu, 06 Sep 2007 00:17:00 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[autotest]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[unit_record]]></category>

		<guid isPermaLink="false">http://d3754554-5787-434b-8741-474c805c4a4e</guid>
		<description><![CDATA[Myself and a colleague have just managed to waste away a good couple of hours trying to figure out Autotests strange &#8216;style&#8217; mechanism to add the ability to &#8220;test in the way Jay Fields explains&#8221;:http://blog.jayfields.com/2007/09/rails-how-we-test.html using &#8220;UnitRecord&#8221;:http://unit-test-ar.rubyforge.org/. You can grab our plugin to enable &#8220;UnitRecord&#8221;:http://unit-test-ar.rubyforge.org/ when using &#8220;Autotest&#8221;:http://rubyforge.org/projects/zentest below: &#8220;http://svn.soniciq.com/public/rails/plugins/iq_autotest&#8221;:http://svn.soniciq.com/public/rails/plugins/iq_autotest By default, running autotest in [...]]]></description>
			<content:encoded><![CDATA[<p>Myself and a colleague have just managed to waste away a good couple of hours trying to figure out Autotests strange &#8216;style&#8217; mechanism to add the ability to &#8220;test in the way Jay Fields explains&#8221;:http://blog.jayfields.com/2007/09/rails-how-we-test.html using &#8220;UnitRecord&#8221;:http://unit-test-ar.rubyforge.org/.</p>
<p>You can grab our plugin to enable &#8220;UnitRecord&#8221;:http://unit-test-ar.rubyforge.org/ when using &#8220;Autotest&#8221;:http://rubyforge.org/projects/zentest below:</p>
<p>&#8220;http://svn.soniciq.com/public/rails/plugins/iq_autotest&#8221;:http://svn.soniciq.com/public/rails/plugins/iq_autotest</p>
<p>By default, running <code>autotest</code> in the Rails directory will run the unit tests. To run the functional tests, do: <code>AUTOTEST='functional' autotest</code></p>
<p>I hope this saves some people some time!!</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2007/09/05/rails-using-autotest-with-unitrecord/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SonicIQ Hiring! &#8211; UK, Ruby on Rails Developer Required</title>
		<link>http://thelucid.com/2007/08/28/soniciq-hiring-uk-ruby-on-rails-developer-required/</link>
		<comments>http://thelucid.com/2007/08/28/soniciq-hiring-uk-ruby-on-rails-developer-required/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 04:49:00 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SonicIQ]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jobs]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://c7aaa47a-1bb0-428e-99ac-5852f8dc1bdf</guid>
		<description><![CDATA[We are looking for a Ruby on Rails, XHTML &#038; CSS Developer to join our team at &#8220;SonicIQ&#8221;:http://soniciq.com. Head over to &#8220;43folders job board to view our ad&#8221;:http://jobs.43folders.com/job/6a5255713e8351a5eb2efef7805b7629/?d=1. These are exiting times with projects like &#8220;Propel&#8217;r&#8221;:http://propelr.com in the pipeline, along with the ever-growing opportunities for new and interesting client projects. If you are a highly [...]]]></description>
			<content:encoded><![CDATA[<p>We are looking for a Ruby on Rails, XHTML &#038; CSS Developer to join our team at &#8220;SonicIQ&#8221;:http://soniciq.com. Head over to &#8220;43folders job board to view our ad&#8221;:http://jobs.43folders.com/job/6a5255713e8351a5eb2efef7805b7629/?d=1.</p>
<p>These are exiting times with projects like &#8220;Propel&#8217;r&#8221;:http://propelr.com in the pipeline, along with the ever-growing opportunities for new and interesting client projects.</p>
<p>If you are a highly motivated developer and can see yourself in a Ruby on Rails position in sunny (sometimes) Bournemouth, UK then &#8220;apply at 43folders&#8221;:http://jobs.43folders.com/job/6a5255713e8351a5eb2efef7805b7629/?d=1.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2007/08/28/soniciq-hiring-uk-ruby-on-rails-developer-required/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Rcov to measure the test coverage of Rails plugins</title>
		<link>http://thelucid.com/2007/08/24/using-rcov-to-measure-the-test-coverage-of-rails-plugins/</link>
		<comments>http://thelucid.com/2007/08/24/using-rcov-to-measure-the-test-coverage-of-rails-plugins/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 23:43:00 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[coverage]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[rcov]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://c533fc04-524b-4de6-bd09-fe3ed45a3a0f</guid>
		<description><![CDATA[To view the coverage of your plugins using Rcov, first install the rcov gem with sudo gem install rcov, then copy and paste the following onto the end of the Rakefile inside your plugin directory: require 'rcov/rcovtask' &#160; desc 'Measures test coverage using rcov' namespace :rcov do desc 'Output unit test coverage of plugin.' Rcov::RcovTask.new&#40;:unit&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>To view the coverage of your plugins using Rcov, first install the <code>rcov</code> gem with <code>sudo gem install rcov</code>, then copy and paste the following onto the end of the <code>Rakefile</code> inside your plugin directory:</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:#996600;">'rcov/rcovtask'</span>
&nbsp;
desc <span style="color:#996600;">'Measures test coverage using rcov'</span>
namespace <span style="color:#ff3333; font-weight:bold;">:rcov</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">'Output unit test coverage of plugin.'</span>
  <span style="color:#6666ff; font-weight:bold;">Rcov::RcovTask</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:unit</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>rcov<span style="color:#006600; font-weight:bold;">|</span>
    rcov.<span style="color:#9900CC;">pattern</span>    = <span style="color:#996600;">'test/unit/**/*_test.rb'</span>
    rcov.<span style="color:#9900CC;">output_dir</span> = <span style="color:#996600;">'rcov'</span>
    rcov.<span style="color:#9900CC;">verbose</span>    = <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">'Output functional test coverage of plugin.'</span>
  <span style="color:#6666ff; font-weight:bold;">Rcov::RcovTask</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:functional</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>rcov<span style="color:#006600; font-weight:bold;">|</span>
    rcov.<span style="color:#9900CC;">pattern</span>    = <span style="color:#996600;">'test/functional/**/*_test.rb'</span>
    rcov.<span style="color:#9900CC;">output_dir</span> = <span style="color:#996600;">'rcov'</span>
    rcov.<span style="color:#9900CC;">verbose</span>    = <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>You can now simply run <code>rake rcov</code> from inside your plugin directory which will generate an <code>rcov</code> directory with the results. Open <code>rcov/index.html</code> (if you are on OSX this will open automatically) in a browser to view the results.</p>
<p>Thanks to &#8220;Mike Clark&#8221;:http://clarkware.com/cgi/blosxom for his &#8220;Rcov rake task for Rails&#8221;:http://clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask which this task is based on.</p>
<p>*Update (11-11-08):* Changed code to use the RcovTask class.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2007/08/24/using-rcov-to-measure-the-test-coverage-of-rails-plugins/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
