Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (20 sloc) 688 Bytes
package de.assertagile.demonstration.howtotest.spock
import spock.lang.Specification
class ExceptionTestingDemoSpec extends Specification {
def "testing exception behaviour with spock is great too"() {
when:
new File("some/place/no/file/can/be/found/at").append("text")
then:
thrown(FileNotFoundException)
}
def "you can also verify the exception since it is returned by thrown"() {
given:
String wrongPath = "some/place/no/file/can/be/found/at"
when:
new File(wrongPath).append("text")
then:
FileNotFoundException e = thrown()
and:
e.message ==~ /^${wrongPath}.+/
}
}