Cucumber, JRuby and Ant

May 12, 2009

Here’s a little snippet from one of our ant files for running Cucumber as an Ant task, under JRuby.

	<target name="cucumber" description="Runs all the cucumber tests">
		<java classname="org.jruby.Main" fork="true" failonerror="true">
			<classpath>
				<fileset dir="lib/runtime">
					<include name="*.jar"/>
				</fileset>
				<pathelement path="lib/extras"/>
			</classpath>
			<arg value="-S"/>
			<arg value="lib/extras/bin/cucumber"/>
			<arg value="--format"/>
			<arg value="Sensis::JUnitFormatter"/>
			<arg value="features"/>
		</java>
	</target>

Note that since this target is called by our hudson job, it uses our custom JUnit formatter for the output so that we can point the report generator at the files.

We’re using the jruby-complete jar, installed in lib/runtime. We also have lib/extras added to the classpath, and this becomes the base for any extra gems that the project needs. Gems can be installed into the right place with the following target:

 <target name="install-gem">
    	<java classname="org.jruby.Main" fork="true" failonerror="true">
      		<classpath>
      			<fileset dir="lib/runtime">
      				<include name="*.jar"/>
      			</fileset>
      			<pathelement path="lib/extras"/>
      		</classpath>
      		<arg value="-S"/>
      		<arg value="gem"/>
      		<arg value="install"/>
      		<arg value="-i"/>
      		<arg value="./lib/extras"/>
      		<arg value="${gem.to.install}"/>
      		<arg value="--no-ri"/>
      		<arg value="--no-rdoc"/>
      		<arg value="--env-shebang"/>
    	</java>
</target>

The property “gem.to.install” can be set via the usual -Dproperty=value.

Advertisements

One Response to “Cucumber, JRuby and Ant”

  1. foo Says:

    Wow, this is really a cool idea


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: