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

support the usage of third party expectation libraries - ease the migration to Atrium #1702

Closed
robstoll opened this issue Feb 4, 2024 · 0 comments · Fixed by #1704
Closed
Assignees
Milestone

Comments

@robstoll
Copy link
Owner

robstoll commented Feb 4, 2024

Platform (all, jvm, js): all
Extension (none, kotlin 1.3): none

Code related feature

Say you have used assertJ in your project and would like to migrate to Atrium. To allow that one can migrate step by step to Atrium it would be nice if someone could write:

expect(person) {
  feature(Person::age).toBeGreaterThan(40)
  toHoldThirdPartyExpectation("to have", "grandsons") { subject ->
    assertThat(subject).hasGrandsons()
  }
}

And then in reporting we would see something along the lines of (imagine we would show all expectations):

I expected subject: Person(..., children=...)
* -> age: 56
    to be greater than: 40
* to have: grandsons
   !! expectation failed, thrown exception:
     ℹ Properties of the unexpected org.opentest4j.AssertionFailedError
      » message: "expected: 2
 but was: 1"        <1234789>
      » stacktrace: 
        ⚬ org.atriumlib.ToHoldThirdPartyExpecationTest$1$7$1.invoke(ToHoldThirdPartyExpecationTest.kt:67)
        ⚬ org.atriumlib.ToHoldThirdPartyExpecationTest$1$7$1.invoke(ToHoldThirdPartyExpecationTest.kt:22)
        ⚬ org.atriumlib.ToHoldThirdPartyExpecationTest$1$7.invoke(ToHoldThirdPartyExpecationTest.kt:280)
        ⚬ org.atriumlib.ToHoldThirdPartyExpecationTest$1$7.invoke(ToHoldThirdPartyExpecationTest.kt:22)

One can currently achieve more or less the same using subject-changer but it requires already quite a bit of knowledge of _logic-level API

        expect(person) {
            _logic.changeSubject.reportBuilder()
                .withDescriptionAndRepresentation(
                    "to have",
                    "grandsons",
                ).withTransformation {
                    Some { 1 }
                }
                .withDefaultFailureHandler()
                .build()
                .transformAndAppend {
                    notToThrow()
                        // dummy expectation, we need one as not defining one would throw as well
                        // but this shows up in case of an error which isn't nice at all
                        .toBeAnInstanceOf<Any>()

                }
        }

And it would show up differently in reporting

@robstoll robstoll added this to the 1.2.0 milestone Feb 4, 2024
@robstoll robstoll self-assigned this Feb 4, 2024
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

Successfully merging a pull request may close this issue.

1 participant