Forgus / spock

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

one-liner exception expectation + stimulus #249

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please consider the following (if possible technically :)

Instead of:

        when:
        consumer.connectStreams((Process) null, "foo")
        then:
        thrown(IllegalArgumentException)

        when:
        consumer.connectStreams(Mock(Process), null)
        then:
        thrown(IllegalArgumentException)

I can do:

expect:
thrown(IllegalArgumentException) when { consumer.connectStreams((Process) null, 
"foo") }
thrown(IllegalArgumentException) when { consumer.connectStreams((Process) null, 
"foo") }

Unless there's already a cool way to achieve something like that in spock?

Cheers :)

Original issue reported on code.google.com by szcze...@gmail.com on 28 Apr 2012 at 11:01

GoogleCodeExporter commented 8 years ago
Thanks for the input. What advantage(s) does the proposed notation have?

Original comment by pnied...@gmail.com on 12 May 2012 at 11:19

GoogleCodeExporter commented 8 years ago
Less code to express the intention.

Feel free to skip it - It was just some quick idea.

Original comment by szcze...@gmail.com on 13 May 2012 at 4:44

GoogleCodeExporter commented 8 years ago
The proposed syntax reads nicely (and requires less lines), but I'm not keen to 
introduce a `when` method. Anyway, thanks for the proposal!

Original comment by pnied...@gmail.com on 20 May 2012 at 1:00

GoogleCodeExporter commented 8 years ago
Hey again :)

This popped up again in my code. Here's the test: 
https://github.com/gradle/gradle/blob/master/subprojects/core-impl/src/test/groo
vy/org/gradle/api/internal/artifacts/ivyservice/ErrorHandlingArtifactDependencyR
esolverTest.groovy#L66

I'm not pushing for this feature at all (keep it closed). Just mentioning it 
for the reference :)

Original comment by szcze...@gmail.com on 17 Oct 2012 at 2:08