-
Notifications
You must be signed in to change notification settings - Fork 0
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
attach remark to assertion #15
Comments
I also have this use case (atrium#627). However, I would propose a slightly different API: expect(proposeAFileName()).containsNot("?").because(
"? is not allowed in file names on Windows"
) or, in your case: expect(person) {
feature { f(it::children) }.all {
feature { f(it:.age) }.isGreaterOrEquals(18).because(
"the legal age of maturity in Switzerland is 18"
)
}
} I think my API is easier to write & read. I would suggest also adding “because” to the output. I like the “ℹ” in front of it. It’s better than the “🛈” I proposed. |
I agree it is more readable without the {}, the only problem is, it will not be evaluated in case of a failure because the previous statement already throws |
Assuming we would have a compiler plugin and rewrite the your |
uh, I always forget about that 🤦. The how-manyith time is it? This builder-like syntax tricks me every time! Another possibility would be a syntax like this: expect(proposeAFileName()).containsNot("?") {
because("? is not allowed in file names on Windows")
} This would be
I think this is pretty clear: The hint belongs to the |
What syntax do you propose for something like:
Where the remark should be for both |
I did not even know I assume that when using |
I removed The problem with
I am not sure how we should present that in reporting though |
We could also have both versions, one which comes after the assertion such as your |
However, I am not convinced that having a compiler plugin for Atrium is sensible. What’s your take: Is my proposal above (having a lambda-taking version of all assertions) a possibility we should consider?
Are you sure that having a remark for multiple assertions is a use case we should support? On the face of it, I feel like it causes difficulties is reporting. Is it worth it? Users could just duplicate messages if necessary. I am not sure that that would be so bad: expect(person) {
feature { f(it::children) }.all {
feature({ f(it:.age) }) {
isGreaterOrEquals(12).because(
"we use the definition that teens are at least 12 years old"
)
isLessThan(18).because(
"we use the definition that teens are young than 18 years"
)
}
}
} |
I am also not convinced yet, I just see more and more potential but not worth yet IMO.
That's true, we could at least start this way and see if we really have the need for the grouping 👍 The problem with
The case that we want to add a hint to an assertion in case of a failure is covered by #9 |
I am pretty sure that we should not. I currently see no good use case for differentiating between “remark” and “failure hint”. If I want something that only shows up in the code, I can use a comment. There is no need for an API, from my point of view. So from my point of view, we should have only one mechanism that always shows up, no matter whether the assertions succeeds or not. |
Back to the syntax: If we don’t want to use my (more involved) approach of feature { f(it:.age) }.isGreaterOrEquals(18) {
because("the legal age of maturity in Switzerland is 18")
} I think this would still be more intuitive than the because("the legal age of maturity in Switzerland is 18") {
feature { f(it:.age) }.isGreaterOrEquals(18)
} I think it reads more fluently and the style is more akin to what we are used from the API. If we assume that the remark should be printed below the assertion, this proposal breaks with atrium’s convention that reporting should reflect writing. I never cared for this convention at all, so I don’t care here either. If you deem it important, I think I’d vote for changing the reporting (i.e. print the reason before the assertion) instead of using the (in my opinion) more clumsy syntax. |
Good that you see it this way, I also think we should not have two different syntax. Attaching remarks might get useful once we have the html reporting. Let's move out discussion to #9. We have examples there (also real world examples). Maybe easier to see what fits and what not. I'll just copy your last comment over. We can come back to this once we have the html report (don't think this will happen near future though). |
I’d suggest closing the ticket until somebody comes around needing it. But I have no strong opinion on that, I just think that less open tickets is usually better. |
So back here again (see excursion in #15).
and with this syntax we can do the grouping if one wants:
Seeing the whole context:
I think it reads quite good. Regarding reporting: maybe it would even make sense to include the
vs
What do you think? |
Yep, I suggested that myself:
Regarding “above” or “below”: At least in my experience, the standard form of an english sentence containing “because” has “because” at the end. I fear that if we put it at the top, we might create an ambigous situation where it is not entirely clear what the “because” refers to. From the top of my head, I can think of this—bad—example:
No matter the position, I think we should always include the “because”. |
Sorry must have overlooked that, good that we came to the same conclusion 👍
that's true, so let's put it at the end including |
So—let’s do it? |
Yes, I'll create an issue and link it here |
@jGleitz I am not yet 100% sure how the reporting should look like. Following a few examples: single assertion
report:
multiple assertions:
report:
The indentation looks weird for a single assertion but makes sense for multiple assertions (please neglect that |
I think we should indent the ℹ:
True, there will be no syntactic way to differentiate between a reason for only the previous assertion and a reason for multiple previous assertions. However, I think this will not be too bad: I expect that in most cases, it will be easy to judge from the content which assertion(s) the reason belongs to. |
We usually don't indent, I should have added one more assertion to make that clear:
Would result in the following with indentation:
without indentation:
At least for the above example without indentation is better IMO. |
another example:
with indentation:
without:
alternatively indent ℹ️ as well:
|
Ah, I see, You are asking whether I think not. For the following reasons:
here, the indentation is not helpful at all, so I think we should omit it in the first place. In your last example above, it feels odd to me, that |
Good reasons, and to be fair, the last example is quite convoluted, I think the normal case will look perfect without indentation. Thanks for your feedback 👍 |
we already have because, closing |
Similar to #9 but this time we like to attach something to an assertion which should always show up.
Should look like the following in reporting:
Syntax and output to be discussed
The text was updated successfully, but these errors were encountered: