-
Notifications
You must be signed in to change notification settings - Fork 29
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
Support hooks without parameter #26
Comments
Naive implementation would be to add methods like this: // Current method
def Before(tagExpression: String)(body: Scenario => Unit): Unit = {
Before(tagExpression, DEFAULT_BEFORE_ORDER)(body)
}
// Added method
def Before(tagExpression: String)(body: => Unit): Unit = {
Before(tagExpression, DEFAULT_BEFORE_ORDER)(_ => body)
} But from a user perspective, you get errors "Cannot resolve overloaded method 'Before'". After having a look, I came up with a solution that I don't think it's worth shipping because it would:
What I ended up writing: sealed trait HookType
case object BeforeType extends HookType
// TODO other types
val Before = new Hook(BeforeType)
// TODO other vals
final class Hook(hookType: HookType) {
def apply(tagExpression: String = EMPTY_TAG_EXPRESSION, order: Int = DEFAULT_BEFORE_ORDER): HookImpl = new HookImpl(hookType, tagExpression, order)
}
final class HookImpl(hookType: HookType, tagExpression: String, order: Int) {
def apply(body: HookBody): Unit = {
hookType match {
case BeforeType =>
registry.beforeHooks += ScalaHookDetails(tagExpression, order, body)
// TODO other cases
}
}
def apply(body: => Unit): Unit = {
apply(_ => body)
}
} If anyone has an idea how to implement it easily, please shout :) |
Actually, after a day of reflexion and after implementing the |
If possible we should support hooks without parameters.
For instance instead of writing that:
We should be able to write this:
The text was updated successfully, but these errors were encountered: