cuke4duke support has been dropped in favor of work on cucumber-jvm. Which is all well and good, except that cucumber-jvm isn’t fully baked yet. It’s not quite there regarding features, but it’s getting there fast.

Unfortunately, that means for those that are still using cuke4duke, you’ve got problems to deal with. The voodoo magic that is cuke4duke does not install gems very well. I don’t know precisely why this is, but it ends up with many problems. Things that will install just fine using a jruby command line, or in native ruby barf a horrible death. Often regarding some YAML::Syck thing.

ERROR:  While executing gem ... (ArgumentError)
      undefined class/module YAML::Syck::DefaultKey

Really sucks and makes it difficult to actually use cuke4duke unless you’ve already got all the gems you need installed.

After much investigation, I discovered that cuke4duke uses a GEM_HOME of ~/.m2/repository/.jruby . So a simple command can get the gems you want installed into that folder:

java -jar jruby-complete-1.6.4.jar -S gem install json --version=1.5.4 --no-rdoc --no-ri -i /home/dkowis/.m2/repository/.jruby

Unfortunately, if there’s another “gem” command in your path, it will use that instead of the one in your jar file, so you have to munge your path as well to prevent it from doing so.

Finally, I needed a way to get this into our project’s Maven POM so that we could easily set up other peoples boxes and the configuration isn’t lost in some terribly manual process of running that command over and over.

This is the solution I came up with:

        <profile>
            <id>install-gems</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <phase>generate-test-resources</phase>
                                <configuration>
                                    <target>
                                        <property file="gems.properties"/>
                                        <macrodef name="install-gem">
                                            <attribute name="gem"/>
                                            <attribute name="version"/>
                                            <sequential>
                                                <java jar="${maven.dependency.org.jruby.jruby-complete.jar.path}"
                                                      fork="true"
                                                      failonerror="true"
                                                      maxmemory="64m"
                                                      newenvironment="true">
                                                    <arg value="-S"/>
                                                    <arg value="gem"/>
                                                    <arg value="install"/>
                                                    <arg value="@{gem}"/>
                                                    <arg value="--version=@{version}"/>
                                                    <arg value="-i"/>
                                                    <arg value="${user.home}/.m2/repository/.jruby"/>
                                                    <env key="PATH" path="${java.home}/bin"/>
                                                </java>
                                            </sequential>
                                        </macrodef>
                                        <install-gem gem="json" version="1.5.4"/> <!-- needed to get json to behave with jruby -->
                                        <install-gem gem="cucumber" version="1.0.3"/>
                                        <install-gem gem="cuke4duke" version="${gem.cuke4duke.version}"/>
                                        <install-gem gem="nokogiri" version="${gem.nokogiri.version}"/>
                                        <install-gem gem="rspec" version="${gem.rspec.version}"/>
                                        <install-gem gem="rest-client" version="${gem.restclient.version}"/>
                                        <install-gem gem="jruby-openssl" version="${gem.jrubyopenssl.version}"/>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

One can then run the command ‘mvn test -Pinstall-gems’ and the gems will be installed as part of the test-resource-generation phase. This only has to be done once whenever new gems are added, or on initial setup. Once it’s done, you’re good to go with the normal cuke4duke workflow.

Hopefully this will save other people some time :)

 Leave a Reply

(required)

(required)

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>

   
© 2011 Shlrm.org Blag Suffusion theme by Sayontan Sinha