-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
Default Formatter Implementation - followup #98
Conversation
I don't think what i came with is good:
I don't think we can do something better regarding formatters and reporters without breaking some public API though. |
Another thing: the But that doesn't always apply: for example the "NotEmpty" or "Item" assertions/helpers cannot really return an expected value. So either the
|
Or then
probably way simpler 😄 but doesn't work for "expected length" |
@gavv gentle ping ^^ |
@leryan Thanks a lot for PR, much appreciated! I was hoping to review it on this week, but it seems I'll have a chance only on the next one, sorry. |
no worries, i'll have plenty of time in the next months to come, no pressure anyway 😊 |
Sorry again for late reply and thanks for looking into this! I think I got your point. In current PR, we have Formatter which does two things: defines how to handle various control flow events (assertion started, ended, succeeded, failed), and also defines how to format failure into a string. And it doesn't look good to mix these two responsibilities. On the other hand, we have Reporter, which is basically anything with Errorf(). And we also have LoggerReporter which is anything with Errorf() and Logf(). And LoggerReporter is a subset if testing.T and you can pass it to httpexpect, or use custom implementation. To avoid mixing responsibilities in Formatter, you're suggesting to move the first of them (handling flow events) to Reporter. However, it will break API and will remove the nice feature when you can say "I don't care on all these reporters, loggers, and formatters" and just pass testing.T as reporter and skip any other configuration. So maybe divide responsibilities in other way? For example, we can split Formatter into two entities:
What do you think?
I think this is OK since it actually reflects what we want. Request refers to context because it's part of the hierarchy. Context refers to request because it refers to all important members of the hierarchy (request, response, failure).
Even if we break API in other places, I'd like to keep as much compatibility as possible. In this specific case, all these NewFoo() methods allow to construct a "standalone" (i.e. without using Expect and Config structs) value and do some assertions. I think each NewFoo() constructor can keep its signature and just construct a new Context from scratch using provided Reporter. On the other hand, when you call Expect.Foo(), like Expect.Array(), the returned object should inherit Context from Expect. To achieve this, we will likely need two constructors: exported NewFoo(Reporter) that creates new context and unexported newFoo(Context) which inherits context from parent.
I'd prefer the first approach: just add flags defining the kind of failure (does it have two values, expected and actual, or only one value, etc.), and maybe some other hints how to format it. Why: 1) Failure is a kind of DTO object, so it would be nice to keep things simple and make it "plain" struct; 2) This approach will allow us to easily add more formatting hints (flags) in future, if we need them. |
Great! I didn't take the time to formulate correctly what i thought but yeah this is totally the idea.
👍
👍 Thanks for your feedback, i'll work on this very soon :) |
Yeah, I'm also fine with both. Let's go with a single pr then.
Done! (I've rebased context on master and force-pushed it) |
@fpeterschmitt thanks for your work on this. I'm trying to implement a new formatter (using your fork / branch,) but httpexpect.Failure properties are not exposed. That means I'm stuck with the default message formats for now. |
Seems legit 😅 I just pushed the changes, it should be all you need :) |
150030a
to
0ed79d2
Compare
@fpeterschmitt awesome, that works. thanks! btw, any idea of when your changes will make their way into the main branch? |
@Heidern as i am not the maintainer of However, the PR isn't ready, as the default formatter should be at least equivalent to the current display way. I do not have time currently to continue working on this PR sadly :'( |
18cbb6e
to
602eda4
Compare
Hi, I've finished this changeset in #150. @fpeterschmitt @goku321 thanks a lot for you work and constructive discussion!! I've squashed your commits into two (d8cbc2f and 2f0d687) and added third commit with remaining changes (8ff7295). I created new PR #150 with those commit and will close previous PRs. Some things that I've changed:
|
Closing with respect to #150. |
Based on #78
*Context
everywhere instead ofReporter
. However this introduces breaking changes.@gavv @goku321