jtanistra / spock

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

Groovy 'star-dot' '(*.) operator doesn't work on properties of Spock doubles #360

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Seems that Groovy 'star-dot' operator doesn't like stubbed properties of Spock 
doubles. Instead of returning the stubbed value, it returns an object. See the 
attached test case (ready to run in Groovy console):

@Grapes([
    @Grab(group='org.spockframework', module='spock-core', version='0.7-groovy-2.0'),
    @Grab(group='cglib', module='cglib-nodep', version='3.1'),
])

class AmountHolderSpec extends spock.lang.Specification {
    def "star-dot operator doesn't work with Spock doubles"() {
        given:
        def holders = [
            Stub(AmountHolder) { it.amount >> 10.0 },
            Stub(AmountHolder) { it.amount >> 20.0 },        
        ]        

        expect:
        holders[0].amount == 10.0 // fine
        holders[1].amount == 20.0 // fine
        holders*.amount == [10.0, 20.0] // failure
    }
}

class AmountHolder {
    BigDecimal getAmount() {
        throw new IllegalArgumentException('should be stubbed')
    }
}

Original issue reported on code.google.com by mgrys...@gmail.com on 22 Apr 2014 at 12:14

GoogleCodeExporter commented 8 years ago
Workaround: use the literal getter:

holders*.getAmount() == [10.0, 20.0] // works

Original comment by mgrys...@gmail.com on 22 Apr 2014 at 12:17