How things have changed

February 25, 2009 1 comment

Due to some changes in work life, I might not be following India’s tour of New Zealand as well as what I would have liked. Nonetheless, I am amused by the pre-series war of words – Indian players relate “scary tales” from past tours to NZ, and Indian fans raising anticipatory bail cries about “doctored wickets”. Typically, one would hear such stories when a non-subcontinent team visits India … how things have changed! :-)

Meanwhile, Mark Richardson gets a bunch of bull published, which manages the difficult feat of summarily insulting both camps.

Categories: cricket

Running cucumber on JRuby+Maven

October 29, 2008 7 comments

Cucumber is an interesting offshoot of the popular BDD tool Rspec developed by Aslak Hellesoy. Cucumber executes plain-text feature specifications against code implementing those features and verifies it. Take a look at the cucumber examples to understand what this means in practice.

This post explains how you can configure it to write specifications for a Java project using Maven and JRuby.

1. Add JRuby as a dependency in your POM:

<project>
    ...
   <dependencies>
       <dependency>
           <groupId>org.jruby</groupId>
           <artifactId>jruby-complete</artifactId>
           <version>1.1.4</version>
       </dependency>
   </dependencies>
   ...
</project>

2. Configure the exec-maven-plugin to run cucumber during integration-test phase.

<project>
...
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
            <execution>
                <id>run-cucumber</id>
                <phase>integration-test</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>org.jruby.Main</mainClass>
                    <arguments>
                        <argument>-S</argument>
                        <argument>rake</argument>
                        <argument>features</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
...
</project>

3. Configure a profile to install cucumber if it is not already locally available:

<project>
...
    <profiles>
        <profile>
            <id>first.time</id>
            <activation>
                <file>
                    <missing>${user.home}/.jruby/lib/ruby/gems/1.8/gems/cucumber-0.1.8</missing>
                </file>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>install-diff-lcs-gem</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>org.jruby.Main</mainClass>
                                    <arguments>
                                        <argument>-S</argument>
                                        <argument>gem</argument>
                                        <argument>install</argument>
                                        <argument>diff-lcs</argument>
                                        <argument>--no-ri</argument>
                                        <argument>--no-rdoc</argument>
                                        <argument>--no-test</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-hoe-gem</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>org.jruby.Main</mainClass>
                                    <arguments>
                                        <argument>-S</argument>
                                        <argument>gem</argument>
                                        <argument>install</argument>
                                        <argument>hoe</argument>
                                        <argument>--no-ri</argument>
                                        <argument>--no-rdoc</argument>
                                        <argument>--no-test</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-cucumber-gem</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>org.jruby.Main</mainClass>
                                    <arguments>
                                        <argument>-S</argument>
                                        <argument>gem</argument>
                                        <argument>install</argument>
                                        <argument>cucumber</argument>
                                        <argument>--no-ri</argument>
                                        <argument>--no-rdoc</argument>
                                        <argument>--no-test</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
...
</project>

4. Create a file named Rakefile as a sibling of your pom.xml, with the following contents:

require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
  t.cucumber_opts = "--format pretty"
end

5. Running

mvn integration-test

should run cucumber now on your project. Cucumber looks for feature specifications to run in the features directory.

Please see this maven project for a test project configured with cucumber.

Categories: jruby, maven, ruby, tech

Finally, a gold!

August 11, 2008 Leave a comment

Abhinav Bindra wins 10m air rifle gold at the Beijing Olympics! Honestly, I never expected to see this in my lifetime. Congrats, Abhinav!

Categories: sports

The Haskell School Of Expression: Getting Started on Ubuntu

May 26, 2008 8 comments

PC sent me a copy of Hudak’s The Haskell School of Expression for my birthday. I was trying to get started with some of the code in the book and could not find a good writeup on it. Here is how I got it going on my Ubuntu Gutsy laptop.

First, install GHC and HGL as:

sudo apt-get install ghc6
sudo apt-get install libghc6-hgl-dev

Then, copy the following code to a file simple.hs somewhere on the disk. This code is from Chapter 3 of the book.

import Graphics.SOE
main0
   = runGraphics $
     do w <- openWindow "My First Graphics Program" (300, 300)
        drawInWindow w (text (100, 200) "HelloGraphicsWorld")
        k <- getKey w
        closeWindow w

Launch GHC interpreter and load the code into it.

$ ghci
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6.1, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type : ? for help.

Loading package base ... linking ... done.
Prelude> :l /path/to/simple.hs
[1 of 1] Compiling Main             ( /path/to/simple.hs, interpreted )
Ok, modules loaded: Main.

Now, run the application as:

*Main> main0
Loading package X11-1.2.1 ... linking ... done.
Loading package HGL-3.1.1 ... linking ... done.
*Main>

If everything is set up properly, this should show a GUI window with the text ‘HelloGraphicsWorld’ written on it. Pressing any key should dismiss this window.

Categories: tech

Furniture charity

May 9, 2008 Leave a comment

Here is an interesting article (via HN) on how IKEA cons the taxman by posing as a charity. I started reading the book Perfectly Legal, but discontinued after few pages. The IKEA story reminded me to pick it up again – maybe soon after I am done with my current reading list.

Categories: links

Forcing NetBeans to use Metal LAF on Ubuntu

April 30, 2008 3 comments

I just installed NetBeans 6.1 on my Ubuntu Gutsy running Sun’s Java 6. The default L&F used is GTK. I personally prefer Metal with Ocean theme. Here is how you get those:

  1. Edit NETBEANS_HOME/etc/netbeans.conf
  2. Add --laf javax.swing.plaf.metal.MetalLookAndFeel -J-Dswing.aatext=true -J-Dswing.metalTheme=ocean to netbeans_default_options variable

Thats it!

Categories: software, tech

Role models, my foot!

March 5, 2008 Leave a comment

From the Sydney Morning Herald

One spectator sitting in the Bill O’Reilly stand, Craig Woodbury, said Harbhajan also spat towards the crowd after they called him “a wanker”. “He definitely made the monkey gestures and he spat towards us,” Woodbury said. “It was a bit disgraceful really, especially after what happened here in the Test match [with Symonds].

“There are a lot of young people sitting here and it was inappropriate. He is a role model to a lot of people. If he wants respect he has to treat others with respect.

“He is always going to cop it from the crowd but he is a professional sportsman and he has got to expect that.”

Am I the only one amused by Craig’s delusions? The older ones accompanying the ‘young people’ repeatedly abuse a visitor – settings up perfect role models on how to treat visitors.

Categories: cricket Tags:
Follow

Get every new post delivered to your Inbox.