-
Notifications
You must be signed in to change notification settings - Fork 466
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
Rework data variable access in PreconditionContext #1360
Comments
I prefer 1. because it makes the API more clear, as it cleanly separates access to the different sources, instead of mixing the data variables in with confusing precedence issues for the user. Furthermore, the current data variables also shadow static fields, as they are resolved before the static fields. |
@spockframework/supporter please comment |
I would also prefer (1) since it would make things much clearer. 👍 |
I'm also in favor of 1:
|
I don't see any value in 2 and 3 has obvious drawbacks, even though it never bothered me personally in the past. |
Context
In #1094 we added support for data variable access in the
PreconditionContext
the way it works currently is that it first tries to execute the condition without instantiating the instance/data variables, and when the condition fails with aMissingPropertyException
we check if thepropertyName
matches adataVariable
and if that is the case we install an interceptor for theFeatureMethod
and let it run. Then when feature method is invoked with the data variables, we execute the condition again.Currently, we use
propertyMissing
and check against aMap
that contains the data variables and if it has a matching entry we return it. That approach works but has some drawbacks, namely that it conflicts with the existing properties (os
,sys
,env
,jvm
,javaVersion
) on thePreconditionContext
, so if you have a data variable with the same name you can't access it.The other downside, is that we only know the available
dataVariables
on the feature level, so with the current implementation we can't easily detect a valid data variable access.In #1204 we also added support for
instance
that behaves similar to the data variables, it also usesMissingPropertyException
, but it is resolved after the data variables are resolved.#1359 will add support for
shared
, that will give access to shared fields when used on theSpecification
level. Currently, this also resolves after thedataVariables
.Proposed alternatives
data
property, that exposes the data variables, removing the need forpropertyMissing
.instance
andshared
would also become real properties. If these properties are accessed while unset (static context) we will throw a dedicated exception with which we can easily decide to add the interceptors, reducing the complexity in the exception handling. This would be a breaking change, for those that already use the data variable access, but it would make the API more straight forward.data
like in 1. but keep the existingpropertyMissing
handling for data variables, but give priority todata
,instance
,shared
. This would mostly be backwards compatible, but could lead to confusing corner cases.The text was updated successfully, but these errors were encountered: