jtanistra / spock

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

slightly unexpected behavior of thrown() #216

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This might be the limitation I'm not aware of but I thought I would share :)

given:
def exc = new GradleException("Hey!")
parserMock.parse("foo") >> { throw exc }

when:
usesParser.parse("foo")

then:
thrown() == ext //does not work
thrown(GradleException) == ext //does not work

def e = thrown(GradleException)
e == exc //works

Original issue reported on code.google.com by szcze...@gmail.com on 9 Nov 2011 at 10:19

GoogleCodeExporter commented 8 years ago
Works as designed. Allowing "thrown()" inside an expression would be 
problematic in terms of semantics and implementation. Don't you get an error 
saying this isn't allowed?

Original comment by pnied...@gmail.com on 10 Nov 2011 at 4:50

GoogleCodeExporter commented 8 years ago
Ok I see. No problem.

>Don't you get an error saying this isn't allowed?

Not really, I get the exact exception the code is throwing. So this might be 
something worth improving.

Original comment by szcze...@gmail.com on 10 Nov 2011 at 1:03

GoogleCodeExporter commented 8 years ago
Using thrown() in a way/position where it is not allowed now results in a 
compilation error with a decent message.

Original comment by pnied...@gmail.com on 22 Jul 2012 at 5:26