/spock-example

Spock example specifications along with ready-to-go Ant, Gradle, and Maven builds

Primary LanguageGroovyApache License 2.0Apache-2.0

Deltamethod Spock Workshop Materials
====================================

THIS IS BASED ON: https://github.com/spockframework/spock-example

The purpose of this project is to help you get started with Spock. The project includes several example specifications and build scripts for Ant, Gradle, and Maven. It also makes it easy to create an Eclipse or IDEA project, allowing you to run the example specs from within your IDE.
All three builds (Ant, Gradle, Maven) will automatically download all required dependencies, compile the project, and finally run the example specs. The Gradle build goes one step further by bootstrapping itself, alleviating the need to have a build tool preinstalled.

Prerequisites
-------------
- JDK 8 
- Maven 3 

Agenda
------

### Groovy Goodness

#### Basic list handling
list = ['a','b','c','d']
print list
assert list==['a','b','c']
assert list==['a','b','c']+['d']


#### Map function
ArrayList<Integer> list = [1,2,3,4].collect { it*2 }
print list
assert list==[2,4,6,8]

#### Slice collection with subscript operator
range = 0..2
print range
assert list[range]==[2,4,6]
print list[0]

#### *. Operator
print(['a', 'few', 'words']*.size())

#### Slice collection by lambda
def words = ['ant', 'buffalo', 'cat', 'dinosaur']
assert words.findAll{ w -> w.size() > 4 } == ['buffalo', 'dinosaur']

#### Maps
map = ['a':1,'b':2]
print(map['a'])

#### Functions and fun with closures
def greaterThen(number) {
	{x -> x > number}
}
predicate = greaterThen(3)
list = [1,2,3,4,5].findAll(predicate)
print(list)

#### Json support
import groovy.json.*
jsonText = new JsonBuilder( [ ["x":1,"y":2], ["x":3,"y":5] ]).toPrettyString()
print(jsonText)
parsedJson = new JsonSlurper().parseText(jsonText)
print(parsedJson[0].x)
assert parsedJson*.x==[1,3]


### TDD vs BDD

### Spock Basics


Maven commands
-------------------
mvn clean test - compiles and runs the tests
mvn gplus:shell - opens a groovy shell console
mvn gplus:console - opens a groovy UI console

Further Resources
-----------------
Spock homepage        http://spockframework.org
Spock web console     http://meet.spockframework.org
Main documentation    http://wiki.spockframework.org/SpockBasics
User discussion group http://forum.spockframework.org
Dev discussion group  http://dev.forum.spockframework.org
Issue tracker         http://issues.spockframework.org
Build server          http://builds.spockframework.org
Maven repository      http://m2repo.spockframework.org (releases are also available from Maven Central)
Spock blog            http://blog.spockframework.org
Spock on Twitter      http://twitter.com/pniederw