Ketan's Musings

Where he blogs about his eclipse musings

Cucumber On JRuby inside Eclipse

with one comment

Fredrick recently asked on the swtbot newsgroup:

My goal is to be able to write some user acceptance tests (using Cucumber) to be able to tests some of my Eclipse plug-ins.

Cucumber is a BDD framework written in (J)ruby. It executes plain text files as functional tests. As a first step, the goal was to be able to print a simple ‘hello world’:

This required being able to bundle jruby with the necessary gems, the jruby jar is already OSGi-fied, so creating a manifest was not required.

First drop in the jruby-complete.jar that we just created inside the target eclipse’s plugins directory.

Then create an eclipse application with the following in it:

public class CucumberRunner implements IApplication {

    public Object start(IApplicationContext context) throws Exception {
        Bundle bundle = Platform.getBundle("org.jruby.jruby");

        URL jrubyHome = FileLocator.toFileURL(bundle.getEntry("/META-INF/jruby.home"));

        RubyInstanceConfig config = new RubyInstanceConfig();
        config.setJRubyHome(jrubyHome.toString());
        Ruby runtime = JavaEmbedUtils.initialize(new ArrayList(), config);
        RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
        evaler.eval(runtime, "p 'Hello, Eclipse World'");
        JavaEmbedUtils.terminate(runtime);

        return EXIT_OK;
    }

    public void stop() {
        // do nothing
    }
}
Hello, Eclipse World

Hello, Eclipse World

Now all we needed was to be able to execute the cucumber executable instead of printing hello world :)

Import the cucumber plugin with a sample calculator to execute it:

Cucumber Output

Cucumber Output

Written by Ketan

April 10th, 2009 at 9:25 am

One Response to 'Cucumber On JRuby inside Eclipse'

Subscribe to comments with RSS or TrackBack to 'Cucumber On JRuby inside Eclipse'.

  1. Ketan,

    You’re my god ! ;)

    I know now what I’m going to do this afternoon :)

    Frederick Ros

    10 Apr 09 at 2:07 pm

Leave a Reply

IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

What is 15 + 15 ?
Please leave these two fields as-is: