-
Notifications
You must be signed in to change notification settings - Fork 468
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
Allow additional parameters in feature methods #566
Allow additional parameters in feature methods #566
Conversation
@@ -16,8 +16,10 @@ | |||
|
|||
package org.spockframework.compiler; | |||
|
|||
import java.io.PrintWriter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is PrintWriter
used in the current version of your PR?
This PR looks like a building block for some bigger task (like externalization of data providers). It would be probably good to describe (at least in the PR itself description for a while) the idea of its practical usage. |
As I detailed my arguments in #525 (comment) already, since parameters were thought to be interchangeable (there were even wrong tests, asserting it), but weren't in reality ( |
50dd091
to
475b564
Compare
@paplorinc About order: Main idea is to allow random parameter order and map parameters by name only. For example test1 and test2 are same and both will pass:
@szpak Fixed, PR was updated. |
@Fuud, I understood what the intention was, but it's the exact thing I prohibited in my PR, because I consider it confusing. |
@paplorinc |
Please take a look at https://github.com/spockframework/spock/pull/525/files#diff-eb35d0e75f7f2a418c977d88fde43275R97, where I have data provider parameters and type specifying parameters mixed up. Wouldn't you find it confusing, if one data provider param would be at the beginning and the other at the end - especially if some parameters were optional? I simply don't see any value in having multiple sorting criteria for the same thing (i.e. what's the value in having |
May be something like this (better to place source value at the first place):
My PR forbids optional parameters. All parameters should be set before method is invoked (it can be done by data-provider or by interceptor).
No. May be in this case it is confusing - it is just because this test tests strange thing. With dependency injection I can imagine tests like this:
|
Sorry, I really don't know what the advantage of
vs
is.
Then it conflicts with my PR
DI would still work with a more consistent parameter order also (i.e. the same as its usage) |
Yes. But if you want default values for parameters, you can write interceptor that provide null for all undefined parameters. Regarding your usecase, you can move declarations to method body from parameter list:
|
With this PR it will be possible to declare additional parameters (that is not specified in where block) in feature methods. Values can be set via interceptors.
Main usage scenario of this PR is to allow some kind of dependency injection: some parameters are set from
where
block and others set by interceptor (for example Spring beans can be injected or other contexts)Additionally this PR allows to omit some of data variables from parameters list (it is usefull with #526 - intermediate parameters can be dropped)
This change is