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

containExactly* assertions don't respect given verifier #3970

Open
AlexLamaison-UnlikelyAI opened this issue Apr 15, 2024 · 4 comments
Open

Comments

@AlexLamaison-UnlikelyAI

Which version of Kotest are you using

Using Kotest 5.8.0.

containExactly and containExactlyInAnyOrder takes a verifier parameter, but doesn't respect it in the matching logic. For example, the first two of these tests fail when they should pass:

class ContainIgnoringFieldsTest {

  data class Foo(val a: Int, val b: String)

  @Test
  fun testAnyOrder() {
    listOf(Foo(1, "a"), Foo(2, "b")) should
        containExactlyInAnyOrder(
            listOf(Foo(3, "a"), Foo(4, "b")), Equality.byReflectionIgnoringFields(Foo::a))
  }

  @Test
  fun test() {
    listOf(Foo(1, "a"), Foo(2, "b")) should
        containExactly(
            listOf(Foo(3, "a"), Foo(4, "b")), Equality.byReflectionIgnoringFields(Foo::a))
  }

  @Test
  fun testAll() {
    listOf(Foo(1, "a"), Foo(2, "b")) should
        containAll(listOf(Foo(3, "a"), Foo(4, "b")), Equality.byReflectionIgnoringFields(Foo::a))
  }
}
@AlexCue987
Copy link
Contributor

yes - I've noticed that too:
#3840

as a result of the discussion there, we should take out custom verifier.
What do you think?

@AlexLamaison-UnlikelyAI
Copy link
Author

It would be better to remove the custom verifier than to leave things as they are. But it would be really nice if there was a way to support custom verification with these assertions. We use custom verifiers a lot because our domain objects contain randomly generated IDs and we want to exclude those for testing

@AlexCue987
Copy link
Contributor

It would be better to remove the custom verifier than to leave things as they are. But it would be really nice if there was a way to support custom verification with these assertions. We use custom verifiers a lot because our domain objects contain randomly generated IDs and we want to exclude those for testing

Makes sense. I'm working on a fix, keeping the signature as is.

@AlexCue987
Copy link
Contributor

the fix only for containExactlyInAnyOrder - the other matcher containExactly clearly has issues, will be fixed separately
#3976

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

No branches or pull requests

2 participants