Add possibility to match message of expected Exception
Opened this issue · 3 comments
robertfirek commented
Currently when we expect some exception we can just check class of expected Exception. It would be useful if some matcher could match on exception's message (maybe event fields of Exception).
TheRealJimShady commented
...how do I use this in the case that the method I'm calling throws
and exception. Obviously in this case it has to be wrapped in a try/catch in the test body. Here's an example I've come up with.
it.should("throw an error when you ask for a coffee type that doesn't exist.", expect -> {
expect.exception(NoSuchCoffeeException.class, () -> {
coffeeMaker.makeCoffee("welsh", false, 37);
});
});
...method signature....
public Coffee makeCoffee(String type, boolean milk, int sugars) throws NoSuchCoffeeException {
RichardWarburton commented
If you look at the linked git commit there's an example of the specification:
TheRealJimShady commented
...problem was that my exception was extending Throwable
rather than Exception
, so IDE was complaining... Thank you for your help :)