checking exceptions using data driven style?

33 views
Skip to first unread message

rakesh mailgroups

unread,
May 17, 2013, 6:46:06 AM5/17/13
to spockfr...@googlegroups.com
Hi,

I'm trying to do something like this:

    def "check for known error cases"() {

        expect:
        factory.create(incomingData)
        UnableToParseRecordException e = thrown()
        e.message == errorMessage

        where:
        incomingData | errorMessage
        null         | "null passed in"
        []              | "no fields found"
    }

but I'm getting errors that you can only check exceptions in then blocks. Any work arounds?

Thanks

Rakesh

Peter Niederwieser

unread,
May 19, 2013, 12:53:34 AM5/19/13
to spockfr...@googlegroups.com
As the error message indicates, you have to use `when-then` instead of `expect` to test for exceptions:

when:
factory.create(incomingData)

then:

UnableToParseRecordException e = thrown()
e.message == errorMessage

Cheers,
Peter

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

Reply all
Reply to author
Forward
0 new messages