I've been writing some tests like this:
def "analysis of a simple exception"() {
when:
def ea = analyzer.analyze(t)
then:
ea.exceptionInfos.size() == 1
def ei = ea.exceptionInfos[0]
ei.className == RuntimeException.name
ei.message == message
ei.propertyNames.empty == true
ei.stackTrace.empty == false
where:
message = "Hey! We've Got No Tomatoes"
t = new RuntimeException(message)
}
But I thought I could rewrite it as:
def "analysis of a simple exception"() {
when:
def ea = analyzer.analyze(t)
then:
ea.exceptionInfos.size() == 1
ea.exceptionInfos[0].with {
className == RuntimeException.name
message == message
propertyNames.empty == true
stackTrace.empty == false
}
where:
message = "Hey! We've Got No Tomatoes"
t = new RuntimeException(message)
}
However, I found that I had to directly add an assert to each line
inside the with {} closure.
Is there a magic way that Spock could automatically convert
expressions to inserts in such a block? Alternately, should there be
a method on Specification to provide similar behavior, i.e.
check ea.exceptionInfos[0], {
className == RuntimeException.name
...
}
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com