Skip to Content
Spock: Up and Running
book

Spock: Up and Running

by Rob Fletcher
May 2017
Intermediate to advanced
370 pages
8h 6m
English
O'Reilly Media, Inc.
Content preview from Spock: Up and Running

Appendix A. Groovy Primer

This appendix is a crash course in the features of the Groovy programming language that you need to know in order to write Spock specifications effectively. It is not meant to be an exhaustive language reference. Partly because there are some language features—metaprogramming, for example—that are very complex but of limited use in understanding the examples in this book, but mostly because there is already a plethora of books on Groovy written by much smarter people than me.

History

Groovy was started in 2003 by James Strachan. Version 1.0 was released on 2007, and version 2.0 in 2012. In 2015, Groovy became a project of the Apache foundation. As of this writing, the current version is 2.4.8.

The language is syntactically derived from Java. In fact most pre–Java 8 Java code is also valid Groovy code. However, Groovy also takes a lot of inspiration from Ruby and Smalltalk.

From its inception, Groovy was a dynamic language. Method calls and property references are dispatched at runtime and can be intercepted by a type’s “metaclass” in order to extend the functionality of a class.

Groovy 2.0 added optional compile-time type checking and static compilation.

Syntactic and Semantic Differences to Java

There are some obvious syntactic differences that are noticeable the first time you look at Groovy code.

Semicolons

Groovy does not require a semicolon at the end of each statement. In fact, it is considered nonidiomatic to use semicolons. The only time semicolons ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java Testing with Spock

Java Testing with Spock

Konstantinos Kapelonis
Programming Groovy 2

Programming Groovy 2

Venkat Subramaniam
Test-Driven React

Test-Driven React

Trevor Burnham

Publisher Resources

ISBN: 9781491923283Errata Page