-
Notifications
You must be signed in to change notification settings - Fork 88
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
Consider renaming/unifying prop
/extracting
/suspendCall
#521
Comments
Just a comment on the proposal for using "have": a possible alternative to It would look like this: assertThat(someUser).having(User::name).isEqualTo("Alice")
assertThat(someUser).having("name", { it.name() }).isEqualTo("Alice") Then I'll try to open a PR so more code can be written against it to see what it feels like. |
Yeah I chose "has" because I thought Truth used it pervasively, but it seems like they use it in quite limited fashion. The ones I use constantly are Their use of the |
I've just realised, it's not going to be possible to unify If only you could have a suspend fun overriding a non-suspend fun (I understand why that's not possible, I'm just musing.) |
|
Would that be an ABI break? Might be worth doing it separately to this if it is. |
We're already renaming the functions and breaking everyone. The deprecation replace with for both |
D'oh! Obviously we are! |
It originally was but became more general shortly after, I agree with the sentiment of this issue.
that's an interesting connection. We do actually have a good number of 'has*' methods which may make this usage more natural. For reference:
there was a reason this wasn't done, but I forget why off the top of my head |
Another note: kotlin itself doesn't unify on a name for their similar concept (let vs map), so while I do strongly agree that |
Linking #522 (comment) as the same argument might be relevant here, a point against 'has' is that it may sound like an assertion itself instead of a middle step, ex someone might do:
not realizing it will never fail edit: This makes me like the 'having' suggestion above a bit more, I feel like it has less of that connotation |
Indeed Kotlin doesn't use the same name, although I also don't think that's a strong design decision on their part. One important difference is that |
Also there's a couple of other ways that ex: assertThat(users).extracting(User::name, User::age).containsExactly(
"Alice" to 22,
"Bob" to 19
) |
One thing worth exploring would be to add in addition to/replace assertThat(allUsers).eachHaving(User::name).isEqualTo(listOf("Alice", "Bob", "Eve"))
assertThat(allUsers).eachHaving("name") { it.name }.isEqualTo(listOf("Alice", "Bob", "Eve")) |
Since I haven't seen any other suggestions given and can't think of anything better, I think we should go with the |
I hadn't read this properly when you first posted it. I think this is a really good idea. When #524 is merged, I'll get another draft PR opened. |
Hi, I came across this when looking at mentions of Truth. I'll offer a few thoughts, but I'm not sure how relevant they'll end up being.
|
Thanks for the thoughts!
yep I was aware of that, I left out the distinction for simplicity because the function we are discussing here is used both for implementing your own assertions as well as something that can be used directly.
Yep, I've been trying to figure out for a while how to fill the same gap, as you point that that approach has pros and cons and and don't exactly love the cons of it. I do think the adjustments here do go in the right direction though I'm not sure yet if it covers all the same use-cases well enough.
The current proposal is to use the style: |
prop
isn't short forproperty
–at least not in the Kotlin-sense. ItsKFunction
and lambda-accepting overloads let it operate on more than just Kotlin properties. It may be short for "property" in the general sense, but that's then confusing against the Kotlin concept and abbreviations are generally frowned upon in API signatures.extracting
isprop
projected over a collection.suspendCall
is the lambda-acceptingprop
butsuspend
able.These are all the same thing, and it would be cool if they had a unified naming convention.
I don't have any perfect naming proposals yet but I've been sitting on filing this issue for months now so I'm firing it off in the hopes others can help.
I came up with two ideas:
Center around the verb "have":
Assert that some user has (a) name (that) is equal to "Alice":
Assert that all users each has (a) name (that) is equal to "Alice", "Bob", "Eve":
Is this
eachHave
? Tempted to bend grammar even if it is for consistency.Assert that some user has (a) DB name (that) is equal to "Alice":
Can we pull this off, where the signature matches? Can the main one be
inline
with some API changes maybe?Alternatively, lean into
map
whose semantics are hopefully known from its available onIterable
s,Flow
s, Rx, other languages, etc.Assert that some user map(ped to a) name (that) is equal to "Alice":
Assert that all users map(ped to their) name (that) is equal to "Alice", "Bob", "Eve":
Is this
eachHave
? Tempted to bend grammar even if it is for consistency.Assert that some user map(ped to a) DB name (that) is equal to "Alice":
Thoughts?
(Also whoops cmd+enter too soon)
The text was updated successfully, but these errors were encountered: