robfletcher / strikt

An assertion library for Kotlin
https://strikt.io/
Apache License 2.0
549 stars 59 forks source link

Add propertiesAreEqualToIgnoring assertion #258

Closed Reevn closed 2 years ago

Reevn commented 2 years ago

Closes https://github.com/robfletcher/strikt/issues/167.

This PR adds a new version of Assertion.Builder<T>.propertiesAreEqualTo that takes a list of ignored properties in the form of KProperty. When comparing property by property, the ignored properties will be skipped.

Rationale

Usage example

data class SomeClass(id: String, name: String)

val subject = SomeClass("123", "Christian")
val other = SomeClass("123", "Rob")

// fails with existing propetiesAreEqualTo
expectThat(subject) propertiesAreEqualTo other

// passes with new propertiesAreEqualToIgnoring
expectThat(subject).propertiesAreEqualToIgnoring(other, SomeClass::name)

Happy to discuss and adjust the name of the function or the implementation.

robfletcher commented 2 years ago

Very nice! Thank you.