Parameterized specs with Jasmine

Spock’s where block makes testing similar conditions for a bunch of inputs very straightforward. Recently I was working on the Groovy language definition for the Prism syntax highlighter and wanted something similar.

I used Jasmine to test-drive my code and wanted to be able to make some very similar assertions about how the highlighting operated. For example, a particular code block should contain particular characters highlighted as operator tokens. The assertions for each of Groovy’s (many) operator types would look extremely similar with the only variance being the id of the code block and the expected operator tokens. Using Spock this would be a classic case for writing a single specification method and applying a where block.

Read More

Using SASS and Compass with Gradle

I recently started helping with the Ratpack website. It is (or will be) a Ratpack app & built with Gradle. I started prototyping with a simple webapp created with Yeoman and using SASS and Compass for authoring CSS. When I migrated the work-in-progress into the ratpack-site application I initially used Ted Naleid’s method of calling Yeoman’s Grunt tasks from Gradle. Unfortunately this meant there were rather a lot of build dependencies. In order to build the app you would need Node.js, Ruby and the Compass gem installed. Peter Ledbrook pointed out this could frustrate potential contributors & Marcin Erdmann proved an example of what he meant. Clearly I needed to simplify.

Read More

Groovy gotcha: for loops and closure scope

You probably know that Groovy closures retain information about the scope in which they were created. The closure body can refer to values that were in scope where the closure was declared. There is a gotcha here that has bitten me a few times, though. That’s when closures are created in a for loop.

Read More

Stateful interactions in Spock

The Java mocking library jMock has a nice feature for dealing with verifying mock interactions in stateful circumstances. I first came across it when reading Growing Object-Oriented Software Guided By Tests (GOOS) by Steve Freeman & Nat Pryce.

I was curious as to whether I could implement something similar with Spock. There’s no syntactic support right now (although there is an open issue) but it’s not that complex to achieve something adequate.

Read More

Grails builds on Travis CI

Travis CI is a cloud based continuous integration service. It’s a great way to automate test runs for projects hosted on GitHub. Since the Grails wrapper was added to Grails in version 2.1 you can use Travis to build Grails apps.

Read More

Groovy & the public keyword

One of the first things you learn in Groovy is that unlike Java public is the default scope for properties and methods declared on classes. Most developers get into the habit of simply omitting the public keyword everywhere. But, is there any situation where it’s the right thing to use? Actually, yes.

Read More