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

introduce its as convenience feature extractor at the cost of poorer reporting #837

Closed
robstoll opened this issue Mar 16, 2021 · 1 comment · Fixed by #838
Closed

introduce its as convenience feature extractor at the cost of poorer reporting #837

robstoll opened this issue Mar 16, 2021 · 1 comment · Fixed by #838
Assignees
Milestone

Comments

@robstoll
Copy link
Owner

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

Code related feature

See also #790 as one of the motivations behind this.
tl;dr: with the assumption that most users weight readability of code higher than readability of the report, I decided to introduce its.

Unfortunately, Kotlin 1.4 (and most likely 1.5 as well) still suffer from, well.. how to say this, not as good type inference capabilities as I thought it would be. There are still a lot of bugs when it comes to overload resolution and it gets worse if a) lambdas are involved, b) KFunction are involved.
Hence, the current approach with KFunction will not play out that well as foreseen. its shall be a better fit for most users as I guess most users don't really care that much about reporting and prefer if the code is more readable more intuitive to write.
And I hope, depending on Kotlin's stability of IR in 1.5 that we can maybe improve the reporting in the future.

So, instead of

expect(myPerson)
  .feature({ f(it::isStudent) }) { toBe(true) }
  .feature { f(it::fullName) }
    .startsWith("rob") 

one shall be able to write:

expect(myPerson)
  .its({ isStudent }) { toBe(true) }
  .its { fullName }
    .startsWith("rob")

For the moment we will not be able to output the isStudent and fullName in the reporting and instead of feature instead (maybe, depending on how much impact it has, we will output feature 1, feature 2 etc.)

@robstoll robstoll added this to the 0.16.0 milestone Mar 16, 2021
@robstoll robstoll self-assigned this Mar 16, 2021
@robstoll
Copy link
Owner Author

I decided to include a link to the line number where the feature is defined instead of feature (feature 1 etc.). The report then looks as follows:

expected that subject: "a"        <112394081>
    ◆ ▶ its.definedIn(DummySpec.kt:36): 1        (kotlin.Int <1798371814>)
        ◾ equals: 2        (kotlin.Int <1943296756>)

Where intellij turns DummySpec.kt:36 into a clickable link.

@robstoll robstoll linked a pull request Mar 18, 2021 that will close this issue
robstoll added a commit that referenced this issue Mar 18, 2021
introduce its as convenience feature extractor function
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