[suggestion] Pass subject as parameter to Assertion.Builder callbacks
See original GitHub issueWhen writing custom assertions, the only way to get the subject is directly from the Assertion
receiver’s subject
parameter. A more idiomatic, Kotlin-y way to access the subject would be having it passed as the sole argument to the callback, which can be accessed implicitly as the it
parameter, or be named as needed by the end-user.
The new signature would look something like:
// in strikt/api/Assertion.kt
fun assert(
description: String,
expected: Any?,
assert: AtomicAssertion<T>.(T) -> Unit
): Builder<T>
Example usage:
fun Assertion.Builder<LocalDate>.isStTibsDay() =
assert("is St. Tib's Day") {
when (MonthDay.from(it)) {
MonthDay.of(2, 29) -> pass()
else -> fail()
}
}
or
fun Assertion.Builder<LocalDate>.isStTibsDay() =
assert("is St. Tib's Day") { dateUnderTest ->
when (MonthDay.from(dateUnderTest)) {
MonthDay.of(2, 29) -> pass()
else -> fail()
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Proper way to verify parameters being passed to a Mock are ...
Is this the preferred way of making sure my mock is getting the expected parameters passed to it, or should I set a...
Read more >Validate method parameters using callbacks in PHPUnit
In this example we make sure the my_method() function was only called once and received value as the parameter. As we can see:...
Read more >5 Identity Assertion Providers - Oracle Help Center
Identity Assertion providers enable perimeter authentication and support single sign-on. ... Passing Tokens for Perimeter Authentication.
Read more >strikt.api
Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit or Spek.
Read more >Espresso basics - Android Developers
This document explains how to complete common automated testing tasks using the Espresso API. The Espresso API encourages test authors to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Implemented this on a branch. See f28f3f9. I think it simplifies some things e.g.
Assertion
and derived types no longer require a generic type.AssertionComposer
interface altogether.Implemented this. It affects
assert
,compose
,map
andpassesIf
.