title: Running Ruby tests (Rspec and Cucumber) through Ant
body: <p>I'm currently looking at TeamCity and how to get our Ruby tests running. I can run the tests just fine when using the Command line or Rake builders. The question I'm trying to solve right now is two fold:</p>
  
  <p>In one of my previous jobs, we also relied on TeamCity to run our .NET tests. We used Nant for this and we had means of tracking the amount of queries that were ran during tests as well as the average execution time for these queries.</p>
  
  <p>I'm trying to do the same right now with my Ruby project. So the first logical step I want to tackle is, <strong>How do I run for example <em>RSpec</em> or <em>Cucumber</em> tests using Ant?</strong>
  I tried looking at Ant itself and grasp it a little bit, but all the examples I find are for jRuby, which we don't use. We rely on RVM and a normal Ruby installation.</p>
  
  <p>The second part of the question is, <strong>How can I track the amount of queries ran and their execution time?</strong> I'm guessing there is probably a gem for it or some sort of global variable to track. Would love to output this information back to TeamCity somehow.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok, so I managed to get things running with Ant for my TeamCity server.
  This is the XML i'm using atm:</p>
  
  <pre><code>   &lt;?xml version="1.0"?&gt;
     &lt;project name="rubycas" default="init"&gt;
         &lt;description&gt;
             This buildfile is used to build the RubyCAS project under TeamCity and run the required tasks to validated
             whether the project is stable and fully functional.
         &lt;/description&gt;
         &lt;property name="test_type" value="cucumber" /&gt;
  
         &lt;target name="init"&gt;
            &lt;echo message="##teamcity[testStarted name='Rubycas']" /&gt;
  
            &lt;condition property="cucumberBool"&gt;
                 &lt;equals arg1="${test_type}" arg2="cucumber" /&gt;
            &lt;/condition&gt;
  
            &lt;condition property="rspecBool"&gt;
                 &lt;equals arg1="${test_type}" arg2="rspec" /&gt;
             &lt;/condition&gt;
         &lt;/target&gt;
  
         &lt;target name="rspec" if="rspecBool" depends="init"&gt;
             &lt;exec executable="rspec" outputproperty="result"&gt;
                 &lt;arg value="--require teamcity/spec/runner/formatter/teamcity/formatter" /&gt;             &lt;arg value="--format Spec::Runner::Formatter::TeamcityFormatter" /&gt;
             &lt;/exec&gt;
             &lt;echo message="${result}" /&gt;
         &lt;/target&gt;
  
         &lt;target name="cucumber" if="cucumberBool" depends="init"&gt;
             &lt;exec executable="cucumber" outputproperty="result"&gt;
                 &lt;arg value="--format junit" /&gt;
                 &lt;arg value="--out results" /&gt;
                 &lt;arg value="features" /&gt;
             &lt;/exec&gt;
             &lt;echo message="${result}" /&gt;
         &lt;/target&gt;
     &lt;/project&gt;
  </code></pre>
  
  <p>Problem now is, I cannot get the output from RSpec into TeamCity to recognize the tests.</p>