<?xml version="1.0" encoding="UTF-8"?>
<snippet>
  <account-id type="integer">2</account-id>
  <body>First install the RSpec and ZenTest gem:

&lt;code&gt;
$ sudo gem install rspec zentest
&lt;/code&gt;

Next create the spec folder:
&lt;code&gt;
$ cd project_folder
$ mkdir spec
&lt;/code&gt;

Save the following to *spec/helper.rb*:

&lt;code&gt;
$LOAD_PATH.unshift File.dirname(__FILE__) + '/..'

require 'rubygems'
require 'spec'
#require 'spec/rake/spectask' not needed, because ZenTest supports rspec now
&lt;/code&gt;

Now create *spec/transcoder_spec.rb*, and add the following test to it:

&lt;code&gt;
require File.dirname(__FILE__) + '/helper'
require File.dirname(__FILE__) + '/../transcoder.rb'

context &quot;Transcoder&quot; do
  setup do
    # Setup your stuff here
  end
  
  it &quot;should support 3gp format&quot; do
    Transcoder.convert(&quot;me_and_you.3gp&quot;).should == true
  end
end
&lt;/code&gt;

Let's not forget the class we're testing, put this code in *lib/transcoder.rb*:
&lt;code&gt;
class Transcoder
  def initialize
  end
  
  def self.convert(file)
    return true
  end
end
&lt;/code&gt;

Note that autotest automatically looks for your code in the lib folder.

Now run the test with the zentest command:
&lt;code&gt;
autotest
&lt;/code&gt;

Change your files and autotest will run the test again. 

Tip: Read &quot;Getting started with Autotest - Continuous Testing&quot;:http://ph7spot.com/articles/getting_started_with_autotest and &quot;Setting up autotest to use Growl on OSX&quot;:http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl for more information on how to increase your productivity.</body>
  <comments-count type="integer">0</comments-count>
  <created-at type="datetime">2008-02-11T17:23:49+02:00</created-at>
  <id type="integer">134</id>
  <language-id type="integer">124</language-id>
  <rendered-body>&lt;p&gt;First install the RSpec and ZenTest gem:&lt;/p&gt;


	&lt;p&gt;&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; $ sudo gem install rspec zentest
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Next create the spec folder:
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; $ cd project_folder
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; $ mkdir spec
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Save the following to &lt;strong&gt;spec/helper.rb&lt;/strong&gt;:&lt;/p&gt;


	&lt;p&gt;&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;$&lt;/span&gt;LOAD_PATH&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;unshift&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;File&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;dirname&lt;/span&gt;(&lt;span class=&quot;Variable&quot;&gt;__FILE__&lt;/span&gt;) &lt;span class=&quot;Operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;/..&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;rubygems&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;spec&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt; &lt;span class=&quot;LineComment&quot;&gt;&lt;span class=&quot;LineComment&quot;&gt;#&lt;/span&gt;require 'spec/rake/spectask' not needed, because ZenTest supports rspec now&lt;/span&gt;
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Now create &lt;strong&gt;spec/transcoder_spec.rb&lt;/strong&gt;, and add the following test to it:&lt;/p&gt;


	&lt;p&gt;&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;File&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;dirname&lt;/span&gt;(&lt;span class=&quot;Variable&quot;&gt;__FILE__&lt;/span&gt;) &lt;span class=&quot;Operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;/helper&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;File&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;dirname&lt;/span&gt;(&lt;span class=&quot;Variable&quot;&gt;__FILE__&lt;/span&gt;) &lt;span class=&quot;Operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;/../transcoder.rb&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt; context &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;Transcoder&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;   setup &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt; &lt;span class=&quot;LineComment&quot;&gt;    &lt;span class=&quot;LineComment&quot;&gt;#&lt;/span&gt; Setup your stuff here&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt;   &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt;   
&lt;span class=&quot;line-numbers&quot;&gt;   9 &lt;/span&gt;   it &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;should support 3gp format&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;  10 &lt;/span&gt;     &lt;span class=&quot;LibraryClassType&quot;&gt;Transcoder&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;convert&lt;/span&gt;(&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;me_and_you.3gp&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;).&lt;span class=&quot;FunctionName&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;Operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;BuiltInConstant&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;  11 &lt;/span&gt;   &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;  12 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s not forget the class we&amp;#8217;re testing, put this code in &lt;strong&gt;lib/transcoder.rb&lt;/strong&gt;:
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;TypeName&quot;&gt;Transcoder&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt;   &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;FunctionName&quot;&gt;initialize&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt;   &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt;   
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;   &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;FunctionName&quot;&gt;self.convert&lt;/span&gt;(&lt;span class=&quot;FunctionArgument&quot;&gt;file&lt;/span&gt;)
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;BuiltInConstant&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt;   &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Note that autotest automatically looks for your code in the lib folder.&lt;/p&gt;


	&lt;p&gt;Now run the test with the zentest command:
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; autotest
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Change your files and autotest will run the test again.&lt;/p&gt;


	&lt;p&gt;Tip: Read &lt;a href=&quot;http://ph7spot.com/articles/getting_started_with_autotest&quot;&gt;Getting started with Autotest &amp;#8211; Continuous Testing&lt;/a&gt; and &lt;a href=&quot;http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl&quot;&gt;Setting up autotest to use Growl on  OSX &lt;/a&gt; for more information on how to increase your productivity.&lt;/p&gt;</rendered-body>
  <title>How to use RSpec and ZenTest in a standalone Ruby project</title>
  <updated-at type="datetime">2008-07-08T22:02:25+03:00</updated-at>
</snippet>
