<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>something learned comments on A Rails tale of caution: functional tests hanging with controllers in subdirectories</title>
    <link>http://somethinglearned.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>something learned comments</description>
    <item>
      <title>"A Rails tale of caution: functional tests hanging with controllers in subdirectories" by trevor</title>
      <description>&lt;p&gt;This afternoon I was hit by a real headscratcher &amp;#8211; documented here for future googlers looking for information on: functional tests hanging controllers subdirectories :-)&lt;/p&gt;


	&lt;p&gt;I added in some tests for controllers that were in a subdirectory (as in &amp;#8220;&lt;code&gt;./script/generate controller boo/hoo&lt;/code&gt;&amp;#8220;) and suddenly rake started hanging.&lt;/p&gt;


	&lt;p&gt;I could run individual functional tests just fine but as a suite &amp;#8211; forget it.&lt;/p&gt;


	&lt;p&gt;The source of the problem turned out to be twofold:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;in test_helper.rb we alias the &lt;code&gt;get&lt;/code&gt; and &lt;code&gt;post&lt;/code&gt; test methods so that we can optionally capture all of our output and run it through a validator.&lt;/li&gt;
		&lt;li&gt;the require line that ./script/generate creates for loading test_helper.rb in your functional tests is &lt;em&gt;relative&lt;/em&gt; to the current file&amp;#8217;s directory.  For functional tests in subdirectories you get a &lt;code&gt;require&lt;/code&gt; argument ending with &amp;#8221;/../../test_helper&amp;#8221; rather than the one ending with &amp;#8221;/../test_helper&amp;#8221;  as you do in top-level functional tests.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Even though those two different require lines point to the same file, from &lt;em&gt;require&amp;#8217;s&lt;/em&gt; perspective they are different &amp;#8211; so the file is loaded twice.&lt;/p&gt;


	&lt;p&gt;And that&amp;#8217;s a big no-no if you are doing a simple method alias &lt;strong&gt;without checks against doing it twice&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;The bulletproof solution is to have tests use &lt;code&gt;File.expand_path()&lt;/code&gt; on the argument to &lt;code&gt;require&lt;/code&gt;.  But if the generators keep spitting it out as they do now it&amp;#8217;s one of those &amp;#8220;pushing water uphill&amp;#8221; situations. I smell a patch.&lt;/p&gt;


	&lt;p&gt;For now, I&amp;#8217;m just wrapping my &lt;code&gt;alias&lt;/code&gt; calls with a check of &lt;code&gt;self.instance_methods&lt;/code&gt; to make sure the alias hasn&amp;#8217;t already been done.&lt;/p&gt;

</description>
      <pubDate>Tue, 30 May 2006 19:27:05 EDT</pubDate>
      <guid>&lt;a href="/articles/2006/05/30/a-rails-tale-of-caution-functional-tests-hanging-with-controllers-in-subdirectories"&gt;A Rails tale of caution: functional tests hanging with controllers in subdirectories&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2006/05/30/a-rails-tale-of-caution-functional-tests-hanging-with-controllers-in-subdirectories"&gt;A Rails tale of caution: functional tests hanging with controllers in subdirectories&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
