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

shouldThrowWithMessage #2847

Closed
nkiesel opened this issue Feb 24, 2022 · 2 comments
Closed

shouldThrowWithMessage #2847

nkiesel opened this issue Feb 24, 2022 · 2 comments
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. enhancement ✨ Suggestions for adding new features or improving existing ones. good-first-issue 👶 Suitable for newcomers looking to contribute to the project.
Milestone

Comments

@nkiesel
Copy link

nkiesel commented Feb 24, 2022

We often have tests where we expect a specific exception with a specific message to be thrown. We currently use

    inline fun <reified T : Throwable> shouldThrowWithMessage(message: String, block: () -> Any?) {
        shouldThrow<T>(block).message shouldBe message
    }

I wonder if there is a better way or if this could be added to the standard matchers.

@nkiesel nkiesel added the enhancement ✨ Suggestions for adding new features or improving existing ones. label Feb 24, 2022
@nkiesel nkiesel changed the title shouldThrowWithmessage shouldThrowWithMessage Feb 24, 2022
@sksamuel
Copy link
Member

Happy to add another one.
I sometimes do

shouldThrow { }.message.shouldBe("msg")

@sksamuel sksamuel added good-first-issue 👶 Suitable for newcomers looking to contribute to the project. assertions 🔍 Related to the assertion mechanisms within the testing framework. labels Mar 12, 2022
sksamuel pushed a commit that referenced this issue Mar 20, 2022
* Implement ShouldThrowWithMessage

* Fix typo

* Fix test
@sksamuel sksamuel added this to the 5.3 milestone Mar 20, 2022
@nkiesel
Copy link
Author

nkiesel commented Mar 20, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. enhancement ✨ Suggestions for adding new features or improving existing ones. good-first-issue 👶 Suitable for newcomers looking to contribute to the project.
Projects
None yet
Development

No branches or pull requests

2 participants