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

beOneOf doesn't tell you what value it was. #2624

Closed
Tracked by #2226
busches opened this issue Nov 5, 2021 · 2 comments
Closed
Tracked by #2226

beOneOf doesn't tell you what value it was. #2624

busches opened this issue Nov 5, 2021 · 2 comments
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. enhancement ✨ Suggestions for adding new features or improving existing ones.
Milestone

Comments

@busches
Copy link
Contributor

busches commented Nov 5, 2021

When using beOneOf, it doesn't tell you what it was if it's (not) in the collection.

Example:
1 shouldBeOneOf listOf(2, 3)

Error:
Collection should contain the instance of value, but doesn't.

Suggested output:
<Value> was expected to be in the collection of <Collection>, but wasn't.
<Value> was not expected to be in the collection of <Collection>, but was.

Tested against 4.6.3, but from looking at master, looks like it hasn't been changed in 5.x -

fun <T> beOneOf(collection: Collection<T>) = object : Matcher<T> {
override fun test(value: T): MatcherResult {
if (collection.isEmpty()) throwEmptyCollectionError()
val match = collection.any { it === value }
return MatcherResult(
match,
{ "Collection should contain the instance of value, but doesn't." },
{
"Collection should not contain the instance of value, but does."
})
}
}

@busches busches added the enhancement ✨ Suggestions for adding new features or improving existing ones. label Nov 5, 2021
@busches
Copy link
Contributor Author

busches commented Nov 5, 2021

Well, I think this is more my mistake as I wanted to use beIn at the end, which does have the nice error messages. I'll leave it up to you if you still think this makes sense.

@sksamuel sksamuel added this to the 5.0 milestone Nov 11, 2021
@sksamuel sksamuel added the assertions 🔍 Related to the assertion mechanisms within the testing framework. label Nov 11, 2021
@sksamuel
Copy link
Member

Thanks for the idea. Updated in main branch.

@sksamuel sksamuel mentioned this issue Nov 11, 2021
71 tasks
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.
Projects
None yet
Development

No branches or pull requests

2 participants