Wednesday 17 July 2013

Setting up Grails-guard

I'm currently working on a project using Grails. Earlier this week I found myself losing my concentration whenever I fired up the integration tests simply because it took too much time to execute them. By the time they were finished my mind had drifted off somewhere else. Clearly I had an itch!

On my last project where Rails was used, Spork and Guard was utilized to keep the Rails environment running and re-executing the tests. That allowed me to enjoy fast running tests whenever code had changed. Was there any alternative to this in Grails? Someone recommended Infinitest, but that seemed only to cover the unit tests. I did however find an alternative called Grails-Guard that runs the integration test whenever there are changes to the code. This way the roundtrip time is a fraction of what I started with. For the record, I've only set this up using the command line, but it should be fairly straight forward using IntelliJ or some other IDE as well. Oh, and by the way, Grails-Guard only supports Grails 2.0.0 and above.

Firstly you need to include Grails-Guard in your project. The latest version when this post was written was 1.0.7. We use BuildConfig.groovy to handle dependencies in the project, so I simply added this line to the file inside the plugin block.

Then you need to ensure that the test-app have an active spring reloading agent, and secondly that the testing is run using guard mode instead of integration mode. This can be done using this command:

This command will scan the integration test directory and re-run all the integration tests when changes occur in the code. Let's create an alias for this so we don’t have to write this line every time. Go to the root of your home directory and add this to your .bashrc, .zshrc or whichever shell you prefer:

If you want to run a single file, or only files in a given package structure this can easily be done by specifying the file names separated by spaces, or the package structure. Open up a new terminal window and type something like this:

The grails environment should start, run the tests and wait for changes. Whenever you save a groovy file within your application that should results in a recompile and the test should re-execute automatically. The reason I'm using g-guard as my alias instead of just guard is that I already have guard (the ruby gem) assigned to that alias.

My itch is gone!

Wednesday 3 July 2013

In the beginning there was a blog

Back in 2007 I decided I was gonna start blogging, and went all in creating a tech blog, a personal blog and a travel blog all at once. The tech blog survived for a few month allowing three blogpost. The personal blog did a little better in terms of the number of blogposts, but it seemed my life was just a bit too boring for the average user to read it. I suspect it never became a success due to a lack of fashion and makeup content. My last blog, the travel blog actually was a bit of a success as I travelled for seven months the following year and quite a few people was reading it. Needless to say however, new updates for the blog stopped coming once I got home and started working again. Eventually, all my blogs were taken down.

Now however, I decided to lower the bar just a few inches. Not in terms of content, but in terms of how much each post needs to contain and what can be blogged about. If anyone by any chance reads this sometime in the distant future, this was where the tech blog was supposed to be resurrected from the dead.