skinny85 / specnaz

Library for writing beautiful, RSpec/Jasmine/Mocha/Jest-style specifications in Java, Kotlin and Groovy
Other
34 stars 8 forks source link

Added new type of test case: shouldThrowWithMessage #4

Closed rlbisbe closed 6 years ago

skinny85 commented 7 years ago

Hey Roberto,

firstly, thanks a ton for the contribution!

In general, it looks good. One idea that I had that I wanted to run past you is changing the API slightly to allow more assertions on the exception from shouldThrow than the message.

My idea was to shouldThrow return a mutable object (let's call it ExceptionAssertion). It would have a bunch of methods that all return this and each add another condition that the thrown Exception has to satisfy. In code:

it.shouldThrow(NumberFormatException.class, "when trying to parse a long from the string 'long'", () -> {
    new Long("long");
}).withMessage("For input string: \"long\"");

This allows you to easily add other Exception assertions to the ExceptionAssertion class without adding more methods to the main SpecBuilder interface. Some possible examples, inspired by AssertJ's Exception assertions:

etc. etc.

Thoughts on this idea?

skinny85 commented 6 years ago

Hey Roberto,

I've submitted a new PR with the changes we talked about above (unfortunately, I can't update your PR). Can we move the discussion there? #6

Thanks, Adam

skinny85 commented 6 years ago

I'm closing this one in favor of #6 which was merged. Thanks again!