<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - Autotest mapping for Rails test conventions Changes</title>
  <id>tag:opensoul.org,2010:/2008/8/22/autotest-mapping-for-rails-test-conventions/changes</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://opensoul.org/2008/8/22/autotest-mapping-for-rails-test-conventions/changes.xml" rel="self" type="application/atom+xml"/>
  <link href="/2008/8/22/autotest-mapping-for-rails-test-conventions" rel="alternate" type="text/html"/>
  <updated>2008-08-22T03:59:01Z</updated>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2008-08-22:476:2</id>
    <published>2008-08-22T11:00:00Z</published>
    <updated>2008-08-22T03:59:01Z</updated>
    <link href="http://opensoul.org/2008/8/22/autotest-mapping-for-rails-test-conventions" rel="alternate" type="text/html"/>
    <title>Autotest mapping for Rails test conventions</title>
<content type="html">&lt;p&gt;A while ago I posted a configuration for getting &lt;a href=&quot;http://opensoul.org/2007/12/6/autotest-without-rails&quot;&gt;autotest to work with &lt;code&gt;Test::Unit&lt;/code&gt; outside of Rails&lt;/a&gt;. Ryan Davis, author of &lt;a href=&quot;http://www.zenspider.com/ZSS/Products/ZenTest/&quot;&gt;autotest&lt;/a&gt;, commented on that post saying that it should &#8220;Just Work&#8482;&#8221; without any custom configuration. I was perplexed because I&#8217;ve never been able to get it to work on my gems and Rails plugins.&lt;/p&gt;


	&lt;p&gt;I finally took time to look into the issue, and realized it&#8217;s because I always use the Rails naming conventions for my test files. I name them &lt;code&gt;foo_test.rb&lt;/code&gt;, instead of &lt;code&gt;test_foo.rb&lt;/code&gt;, which is what Autotest looks for.&lt;/p&gt;


	&lt;p&gt;That&#8217;s easily solvable.  Here&#8217;s an Autotest configuration, tested with ZenTest 3.10.0, that should make it work for either naming convention.  You can throw this in your &lt;code&gt;~/.autotest&lt;/code&gt; file, or in a &lt;code&gt;.autotest&lt;/code&gt; file inside your project.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;Autotest.add_hook :initialize do |at|
  at.clear_mappings

  at.add_mapping %r%/^lib/(.*)\.rb$% do |_, m|
    possible = File.basename(m[1])
    files_matching %r%^test/.*(#{possible}_test|test_#{possible})\.rb$%
  end

  at.add_mapping(%r%^test/.*\.rb$%) {|filename, _| filename }
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Happy autotesting.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2008-08-22:475:1</id>
    <updated>2008-08-22T03:56:57Z</updated>
    <link href="http://opensoul.org/2010/1/18/autotest-mapping-for-rails-test-conventions" rel="alternate" type="text/html"/>
    <title>Autotest mapping for Rails test conventions</title>
<content type="html">&lt;p&gt;A while ago I posted a configuration for getting &lt;a href=&quot;http://opensoul.org/2007/12/6/autotest-without-rails&quot;&gt;autotest to work with &lt;code&gt;Test::Unit&lt;/code&gt; outside of Rails&lt;/a&gt;. Ryan Davis, author of &lt;a href=&quot;http://www.zenspider.com/ZSS/Products/ZenTest/&quot;&gt;autotest&lt;/a&gt;, commented on that post saying that it should &#8220;Just Work&#8482;&#8221; without any custom configuration. I was perplexed because I&#8217;ve never been able to get it to work on my gems and Rails plugins.&lt;/p&gt;


	&lt;p&gt;I finally took time to look into the issue, and realized it&#8217;s because I always use the Rails naming conventions for my test files. I name them &lt;code&gt;foo_test.rb&lt;/code&gt;, instead of &lt;code&gt;test_foo.rb&lt;/code&gt;, which is what Autotest looks for.&lt;/p&gt;


	&lt;p&gt;That&#8217;s easily solvable.  Here&#8217;s an Autotest configuration, tested on ZenTest 3.10.0, that should make it work for either naming convention.  You can throw this in your &lt;code&gt;~/.autotest&lt;/code&gt; file, or in a &lt;code&gt;.autotest&lt;/code&gt; file inside your project.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;Autotest.add_hook :initialize do |at|
  at.clear_mappings

  at.add_mapping %r%/^lib/(.*)\.rb$% do |_, m|
    possible = File.basename(m[1])
    files_matching %r%^test/.*(#{possible}_test|test_#{possible})\.rb$%
  end

  at.add_mapping(%r%^test/.*\.rb$%) {|filename, _| filename }
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Happy autotesting.&lt;/p&gt;</content>  </entry>
</feed>
