Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to match message of expected Exception #53

Open
robertfirek opened this issue Aug 9, 2014 · 3 comments
Open

Add possibility to match message of expected Exception #53

robertfirek opened this issue Aug 9, 2014 · 3 comments

Comments

@robertfirek
Copy link
Contributor

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).

RichardWarburton added a commit that referenced this issue Sep 8, 2014
Add possibility to match message of expected Exception (issue #53)
@TheRealJimShady
Copy link

TheRealJimShady commented Oct 12, 2017

...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
Copy link
Owner

If you look at the linked git commit there's an example of the specification:

6346bb8#diff-d51eaef31041834df2e1c4a9f425e4b8

@TheRealJimShady
Copy link

...problem was that my exception was extending Throwable rather than Exception, so IDE was complaining... Thank you for your help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants