Forgus / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

failed assertions in loops inside the "then" block will not be reported #288

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
If loops will be used in the "then" block then failed assertions will be not 
reported. The test passes.

Here is a code example:

class ExampleSpec extends Specification {

    def "correct - it fails"() {
        when:
        def result = 2 + 2
        then:
        result == 2
    }

    def "incorrect - doesn't fail"() {
        when:
        def result = 2 + 2
        then:
        result == 4
        for (int i = 0; i < 5; i++)
            result == 2
    }
}

The same happens when ...each{...} will be used.

Original issue reported on code.google.com by scho...@softcontract.de on 11 Dec 2012 at 9:06

GoogleCodeExporter commented 8 years ago
Sorry, I didn't provide any information about the versions I use:
spock-core-0.6-groovy-1.8.jar
groovy-all-1.8.7.jar

Original comment by scho...@softcontract.de on 11 Dec 2012 at 9:08

GoogleCodeExporter commented 8 years ago
Works as designed. Only top-level expressions are automatically considered 
assertions. You could either turn the loop into an expression by using such 
Groovy collection methods as `every()`, `times()`, etc, or use an explicit 
*assert* inside the loop.

Original comment by pnied...@gmail.com on 12 Dec 2012 at 1:22