<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.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>@Lathi.net: Testing Rails Helpers</title>
    <link>http://blog.lathi.net/articles/2006/03/31/testing-rails-helpers</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>On Life, Fatherhood, Christianity, and Computers</description>
    <item>
      <title>Testing Rails Helpers</title>
      <description>&lt;p&gt;I&amp;#8217;ve asked &lt;a href="http://www.lunchboxsoftware.com/"&gt;Scott&lt;/a&gt; four times now how write functional tests for helper methods.  He&amp;#8217;s replied the same all four times, and this time I&amp;#8217;m going to &amp;#8220;remember&amp;#8221; it&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="constant"&gt;File&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;dirname&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;__FILE__&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;+&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;/../test_helper&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;HelperTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Test&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Unit&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TestCase&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;ActionView&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Helpers&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TextHelper&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;ActionView&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Helpers&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TagHelper&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;ApplicationHelper&lt;/span&gt;
  &lt;span class="comment"&gt;# include whatever helpers you want to test here, sometimes you'll need&lt;/span&gt;
  &lt;span class="comment"&gt;# to include some of the Rails helpers, as I've done above.&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_some_helper&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;By including the &lt;code&gt;ApplicationHelper&lt;/code&gt; in your test class, you have all the methods defined on that class available as local functions.  If you have helpers in other classes, you&amp;#8217;d need to include those as well.&lt;/p&gt;</description>
      <pubDate>Fri, 31 Mar 2006 12:52:40 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:2b515da5-7b9d-4ab6-9027-2ba25874f4c7</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2006/03/31/testing-rails-helpers</link>
      <category>Test Driven Development</category>
      <category>Ruby on Rails</category>
    </item>
  </channel>
</rss>

