Archive

Archive for the ‘tech’ Category

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.

Advertisements
Categories: jruby, maven, ruby, tech

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

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

Want a good Lisp tutorial?

September 21, 2007 Leave a comment

Here is a great Lisp tutorial.

I first heard of Lisp in my programming languages class, but never paid much attention to it. Well, you could still pass that exam if you never learned a thing about Lisp (or any of the programming languages “taught” there), so I never bothered. Later when I started reading blogs and technical articles, I started hearing more about Lisp.

My first attempt at learning Lisp was from David S. Touretzky’s online book Common Lisp: A Gentle Introduction to Symbolic Computation. The book did not interest me and I never completed it. Later that year, I spotted Stephen Slade’s Object-Oriented Common LISP at Gangaram’s and bought it. That book went way above my head and I still did not get Lisp.

It was in late 2004 that I heard of Peter Seibel’s Practical Common Lisp. Peter was in the process of writing the books and he had put the content on the web. I started reading the online copy of the book but without much hope. I was pleasantly surprised! The book was actually a very good read and all those parenthesis started to make sense finally. Later when I ran into difficulties with a few examples in the book, I wrote to Peter. He was kind enough to reply and make minor fixes to the code in the book.

I still haven’t programmed much in Lisp besides a few toy programs. But I understand why people rave so much about Lisp – and I am grateful to Peter Seibel for opening my eyes. So when he made this request, I thought I owed it to him.

PS: Someone, I can’t remember who, borrowed the Slade book from me in 2004 and never returned it. If anyone reading this have it, please drop me a note. đŸ™‚

Categories: books, tech

Formatting source in blogs hosted on WordPress

September 6, 2007 3 comments

I sometimes post snippets of code on this blog. I have been searching for a way to provide proper syntax highlighting for the code I post here. There are many wordpress plugins which provide proper syntax highlighting, but since I use the hosted WordPress service, I cannot use any of those. GNU Sourcehighlight is the standard program people use of generating source highlighting, but for some strange reason I could not get that to compile on my iBook.

While looking for alternatives on the web, I noticed a package called Highlight. Highlight can generate syntax highlighted HTML files from program source files. It supports over 120 programming languages! I tried it few months ago, but soon ran into a limitation. Highlight output uses CSS classes and style definitions; to make it convenient to post code here, I needed a package that generated inline CSS styles.

I wrote to André Simon, the author of Highlight, requesting this feature. Today I got an email from André informing me that the new 2.6.3 release of Highlight has an option to generate inline css! I tried it out and it works well.

$  highlight -i HelloWorld.java -o HelloWorld.html --inline-css

And here is the snippet Highlight generated for me:

public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("Hello, World");
    }
}

Thanks and congratulations to André Simon!

Categories: blog, tech, wordpress

Yet Another Certification

July 4, 2007 Leave a comment

This time from Raganwald. Of course, we might soon see training centers in Hyderabad. đŸ™‚

Categories: links, software, tech

StandoutJobs.com

June 11, 2007 Leave a comment

StandoutJobs.com posts their recruitment advertisement …. on youtube!

Neat! đŸ™‚

Categories: software, tech