thanneeruvenu / spock

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

thrown() that takes an exception instance #275

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It would be nice to have a following shortcut:

then:
def ex = thrown(Exception)
ex == expectedException

//shortcut:
then:
thrown(expectedException)

Original issue reported on code.google.com by szcze...@gmail.com on 16 Oct 2012 at 9:35

GoogleCodeExporter commented 8 years ago
What's your use case? I don't recall ever having implemented `equals` for an 
exception type, and neither do the exception types in the JDK. 

Original comment by pnied...@gmail.com on 16 Oct 2012 at 9:49

GoogleCodeExporter commented 8 years ago
Or, I should say, I don't typically implement `equals` for exception types, 
even though I quite often make them hold state other than just a message.

Original comment by pnied...@gmail.com on 16 Oct 2012 at 9:52

GoogleCodeExporter commented 8 years ago
My use case is to save one line of test code. Here's my test:

        when:
        def results = new ResolverResults(resolvedConfiguration, fatalFailure)

        then:
        results.resolvedConfiguration

        when:
        results.resolutionResult
        then:
        def ex = thrown(ResolveException)
        ex == fatalFailure

Feel free to discard this request if you don't like it :)

Original comment by szcze...@gmail.com on 16 Oct 2012 at 10:11

GoogleCodeExporter commented 8 years ago
Oh, you want to check for identity, on purpose? I'm afraid people might think 
they can somehow compare exceptions for equality.

Original comment by pnied...@gmail.com on 16 Oct 2012 at 10:48

GoogleCodeExporter commented 8 years ago
I would expect it to compare for equality. Anyhow - up to you - feel free to 
discard :)

Original comment by szcze...@gmail.com on 16 Oct 2012 at 3:23

GoogleCodeExporter commented 8 years ago
I would expect it to compare for equality. Anyhow - up to you - feel free to 
discard :)

Original comment by szcze...@gmail.com on 16 Oct 2012 at 3:23

GoogleCodeExporter commented 8 years ago
Sure, but since exceptions almost never implement `equals()`, it boils down to 
an identity check.

Original comment by pnied...@gmail.com on 16 Oct 2012 at 4:24

GoogleCodeExporter commented 8 years ago
To be clear, my concern is that the feature suggests that exceptions can be 
sensibly compared for equality, when typically they cannot.

Original comment by pnied...@gmail.com on 16 Oct 2012 at 4:30