Spock 0.5 released

238 views
Skip to first unread message

Peter Niederwieser

unread,
Dec 10, 2010, 8:50:54 PM12/10/10
to Spock Framework - User
Dear Spock community,

I'm happy to announce that Spock 0.5 has been released!

What's New
==========

1. Comprehensive support for Hamcrest matchers
----------------------------------------------

Hamcrest matchers are now deeply integrated with Spock's condition
mechanism, allowing you to write code like:

expect:
myPi closeTo(Math.PI, 0.01)

View/run the full example in Spock Web Console: http://meet.spockframework.org/?id=22001

2. Optimization of spec run order
---------------------------------

If enabled, recently failed spec classes/methods will be run first to
provide faster feedback.

3. New built-in extensions
-------------------------

@spock.lang.AutoCleanup
@spock.util.mop.Use
@spock.util.mop.ConfineMetaClassChanges

See the JavaDoc for more information.

4. Better integration with Grails, Maven, and Ant
-------------------------------------------------

Among other things, the Grails plugin is now packaged differently to
solve installation problems.

5. Support for Groovy 1.8
-------------------------

There is now a Spock distribution for Groovy 1.8 (beta-2 and
later).

6. Diff view in Eclipse and IDEA
--------------------------------

Say you have a failing object comparison like:

expect: ["fred", "chris", "tom"] == ["fred", "chriz", "tom"]

Click the first line (Eclipse) or link (IDEA) in the failure output to
open a diff view comparing the two objects. This works for arbitrary
types of objects. Kudos to FEST-Assert (http://fest.easytesting.org/)
for the idea!

7. Better Eclipse and IDEA integration
--------------------------------------

As always, we have worked with the folks behind Groovy-Eclipse and
IDEA to provide the best possible IDE experience.

8. Other improvements and fixes
-------------------------------

Here is the full list of closed issues:
http://issues.spockframework.org/list?can=1&q=label%3AMilestone-0.5

How To Get It
=============

Spock 0.5 comes in three distributions for Groovy 1.6, 1.7, and 1.8,
respectively. All Jars are available from Maven Central:
http://repo1.maven.org/maven2/org/spockframework

The Spock Grails plugin comes in two distributions for Grails 1.2 and
1.3, respectively. See http://grails.org/plugin/spock for more
information.

The Spock Example project can be downloaded from http://downloads.spockframework.org

And last but not least, Spock Web Console has been updated too:
http://meet.spockframework.org

Acknowledgments
===============

Thanks to everyone who provided ideas, feedback, patches, or helped to
promote Spock. Please keep supporting us!

What's Up Next
==============

0.6 will be a smaller and quicker release. Main goal is to write a
comprehensive Spock manual.

Have fun with Spock!
Peter




Hamlet D'Arcy

unread,
Dec 11, 2010, 1:46:54 AM12/11/10
to spockfr...@googlegroups.com
Awesome! Congrats to the team.

> --
> You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
> To post to this group, send email to spockfr...@googlegroups.com.
> To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
>
>

--
Hamlet D'Arcy
haml...@gmail.com

Ale Sarco

unread,
Dec 13, 2010, 1:04:38 PM12/13/10
to Spock Framework - User
In Spock 0.4 I could do something like this:

then: "I should receive and XML with an OK notification"
res.status == 200
res.data.text() == "OK"

and: "The userTemplate should have been updated"
res = settingsService.get(path: "templates", query:
[X_Security_Token: token.value])
res.status == 200
def newTemplate = res.data.userTemplate.find {it.@id ==
newUserTemplateId}
println "Retrieved template id is $newUserTemplateId"
newTemplate.@id == newUserTemplateId
newTemplate.label == "An updated user template"

But Spock 0.5 complains that "Groovy:Expected a condition, but found
an assignment. Did you intend to write '==' ?" on the first line of
the and: block.
Docs says that variables can be defined in when: blocks, and this
worked perfect in Spock 0.4
If this is no longer possible by design, how should I refactor my
test?
> 1.3, respectively. Seehttp://grails.org/plugin/spockfor more
> information.
>
> The Spock Example project can be downloaded fromhttp://downloads.spockframework.org

Peter Niederwieser

unread,
Dec 13, 2010, 1:36:08 PM12/13/10
to spockfr...@googlegroups.com
On 13.12.2010, at 19:04, Ale Sarco wrote:
> But Spock 0.5 complains that "Groovy:Expected a condition, but found
> an assignment. Did you intend to write '==' ?" on the first line of
> the and: block.
> Docs says that variables can be defined in when: blocks, and this
> worked perfect in Spock 0.4

The problem is in this line:

then:


res = settingsService.get(path: "templates", query: [X_Security_Token: token.value])

This code doesn't declare a new variable, but reassigns an existing one. It is evaluated as a condition and will fail if the assigned value is false according to Groovy truth. This behavior is almost never desirable, and can give rise to nasty bugs. For example, if you write "x = y" when you really meant "x == y", the condition will almost always be true, and will lead you to believe that x and y are equal even when they aren't.

> If this is no longer possible by design, how should I refactor my test?

The solution is to introduce another variable:

then:
def newRes = ...

Hope this helps.

Cheers,
Peter

Ale Sarco

unread,
Dec 14, 2010, 6:41:51 AM12/14/10
to Spock Framework - User
Hi Peter, thanks for your answer.
Yeah, it helps, partially.

Maybe I'm not using the best practices, since I'm quite new to Groovy
and Spock.
My case is like this, I want to test some REST calls. These REST
service allows me to create, update and delete templates. So I have a
specification to excersice this.

The first method will create a template, then check that the template
has been created, and saves the template id in a variable.
Second method will update the template, then check that the template
has been updated.
Third one will delete the template, then check that it has been
actually deleted.

So, I used to save the templateId in a class variable (annotated with
@Shared) and use it in all my test (so I always work with the same
template)

@Shared newUserTemplateId = 0

def "Create a new user template"() {
when: "I create a new userTemplate with the REST service"
def res = settingsService.post(
path: "userTemplate",
query: [X_Security_Token: token.value,
data_xml: """<?xml version="1.0" encoding="UTF-8" standalone="no"?
><blah/>"""]
)
then: "I should receive an XML with the userTemplateId"
res.status == 200
res.data.toInteger() > 0
newUserTemplateId = res.data.text()
println "The new templateId is $newUserTemplateId"
}

If I cannot assign the newUserTemplateId variable in the then: block,
where then? I cannot do it at the end of the when: block because I
still don't know if the call was successful. It would work in the
cleanup: block, but is that the right place?

Thanks,
Alex.

Peter Niederwieser

unread,
Dec 14, 2010, 9:19:25 AM12/14/10
to spockfr...@googlegroups.com
Interesting use case. One thing you can do is to introduce a helper method:

void storeTemplateId(res) {
  newUserTemplateId = res.data.text()
}

This helper method can then be called from then-blocks. Note: It's important that the helper method has return type void.

By the way: If your methods are dependent, it can help to annotate the class with @Stepwise. See the JavaDoc for more information.

Cheers,
Peter

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.


----------------------------------------------------------------
Peter Niederwieser
Twitter: pniederw









Reply all
Reply to author
Forward
0 new messages