Cool tests in the Java Maven platform now possible with rspec-maven-plugin

I don’t like Maven at all but sometimes depending of the project and the people you need to use this. After playing with RSpec I stop considering any Java language framework acceptable for testing so for this project I’m working on right now I needed to find a solution that could integrate RSpec with Maven.

After googling I found this post from Bob McWhirter where he presented a official rspec-maven-plugin. I tried to use it but it wasn’t working so I forked it, fixed it and changed some things.

The forked version of rspec-maven-plugin is at GitHub and to use it you should:

install the plugin in the local repository (this is necessary only one time):

git clone git://github.com/dcrec1/rspec-maven-plugin.git
cd rspec-maven-plugin
mvn install

configure your project’s pom.xml adding this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>rspec-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>test</id>
            <phase>test</phase>
            <goals>
                <goal>spec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

set the JRUBY_HOME system variable, for example:

export JRUBY_HOME=/opt/jruby-1.1.6/

The plugin will run in the test phase of the Maven build cycle.

Happy testing!

12 thoughts on “Cool tests in the Java Maven platform now possible with rspec-maven-plugin

  1. Hello,

    I got following error when executing this on win 7.
    Is this pluging not supporting win os, or what could be the problem?
    Have not tried on linux.

    regards, Matti

    [INFO] — rspec-maven-plugin:1.0-beta-6:spec (test) @ vse_mppscripts —
    [INFO] Running RSpec tests from D:\subversion\vse\vse_mppscripts\test\
    [ERROR] error emitting .sh
    java.lang.NullPointerException
    at org.codehaus.mojo.rspec.ShellScriptFactory.getScript(ShellScriptFactory.java:26)
    at org.codehaus.mojo.rspec.AbstractScriptFactory.emit(AbstractScriptFactory.java:44)
    at org.codehaus.mojo.rspec.RspecRunnerMojo.execute(RspecRunnerMojo.java:120)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)

  2. I got the NPE also. It is caused by a bug in the rspec-maven-plugin. It expects that there is always at least one systemproperty setting in the configuration. Workaround:


    org.codehaus.mojo
    rspec-maven-plugin


    ${env.JRUBY_HOME}

    ${basedir}/src/test/specs

    ${basedir}/target

    true

  3. Darn, my response was broken by apparently the blogging tool used by this site. Anyway, to fix the NPE add a configuration under rspec-maven-plugin, put systemproperties under it and put any value there.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">