-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add a context getter that returns with the type default value #97
Comments
Your point is valid IMO. Here's what I think:
I'd leave the current API as it is but add a set of new methods. s := ctx.MustString("ffdsfa") So, every method would start with word |
That's what I had in mind too. How will A few alternative ideas:
|
It would fail the test: |
speaking of defaults, why not leave it as it is right now? If we want to add a new set of methods for it, the last parameter in |
Leave what as it is? |
for now - yes. If there'll be more people complaining about it, we'll think about changing it. WDYT? |
Sorry, I'm a bit confused about what you are suggesting exactly. Are you suggesting to do nothing with this issue? Personally, I don't care much about user-defined defaults, I care more about not having to handle every error manually. |
What I meant is that we can go with the |
Sounds good to me. How will the context receive the |
the context is created at the very beginning https://github.com/go-bdd/gobdd/blob/master/gobdd.go#L255 so we can put it there in the |
I'm not 100% that's true. For subtests the framework creates a new So either each step receives a new context, with the correct This gives me an idea though: what if the context indeed holds the correct instance of Testify suites work this way. |
Is your feature request related to a problem? Please describe.
Currently context getters return with a value and an error. The error is nil, when the key can actually be found in the context. However, in most of the cases whether the value is there or not is irrelevant.
Furthermore, when a default is provided the error can just be ignored, since it will always be null.
Unfortunately, the error return value makes using the getters much harder.
Describe the solution you'd like
I'd like to see a set of getters which:
For example:
func GetStringWithDefault(key interface{}, default ...string) string
(Need a better name though)
Describe alternatives you've considered
Alternatively/in addition to the above, I could imagine a getter that panics/calls t.Fatal, for example:
func MustGetStrig(t testing.T, key interface{}, default ...string) string
(Again, name is a work in progress)
Additional context
Checking whether a key is present in the context or not can be a valid scenario, but the current implementation forces it onto the user and makes the test cases extremely verbose.
Consider the following (and let's say I do want the key to be checked):
The current implementation forces me to manually handle the missing key scenario. In most of the cases people probably want to do two things:
The framework should support these scenarios better IMHO.
The text was updated successfully, but these errors were encountered: