Skip to content
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

added support for execution order for "Before" and "After" hook. closes #807 #809

Merged
merged 1 commit into from
Jan 1, 2015

Conversation

mhshams
Copy link
Contributor

@mhshams mhshams commented Dec 12, 2014

Since the original method was accepting varargs (Object... args) as parameter, there was almost no way to add new method with proper parameters, without breaking backward compatibility.

this.tagExpression = tagExpression;
this.timeoutMillis = timeoutMillis;
this.timeout = timeout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you switch it back to timeoutMillis please? I've been bitten too many times by bugs caused by wrong assumptions about units.

@aslakhellesoy
Copy link
Contributor

LGTM when my minor comments are addressed.

for (Object o : tagsExpressionsAndBody) {
if (o instanceof String) {
tagExpressions.add((String) o);
} else if (o instanceof Integer) {
timeoutMillis = (Integer) o;
} else if (o instanceof Number && isDefaultTimeout) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we used instanceof Long and instanceof Integer we could use that to detect timeout and order, respectively. In other words - Long means timeout - Integer means order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume groovy developers using numbers without caring about the type (long or int). so we will end up codes like Before(1, 100, "tag1", "tag2") {}.
Don't you think it would be more error prone?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Groovy have a literal syntax for longs like Java does? I.e. 500L.

We could throw an error if you pass two or more ints and longs I suppose. There is still a danger that people would pass in 2000 hoping that would set the timeout, when in fact it would set the order (since 2000 is an int). But you have the same problem with your current implementation.

Alternatively we could break backwards compatibility and expect a Map:

Before([order: 5, timeoutMillis: 4000L, tags:["@tag1", "@tag2"]]) {
}

I don't mind too much breaking backwards compatibility if it is for a good reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the current implementation, we assume that the first number is always the timeout and only if the second number is available in the parameters it will be considered as order. This was mainly because I was thinking that there are existing code out there that passing the timeout, so their behaviour should remain the same.

If you or ok with breaking backward compatibility, we can have proper methods (overloaded) with following syntax:

public static void Before(int order, long timeoutMillis, List<String> tags, Closure body) 
//default order
public static void Before(long timeoutMillis, List<String> tags, Closure body) 
//default timeout
public static void Before(int order, List<String> tags, Closure body) 
// default tags
public static void Before(int order, long timeoutMillis,  Closure body) 
and ...

or even better if we implement it in groovy, we could have it with one method by default values.

static void Before(int order = 0, long timeoutMillis = 10000, List<String> tags = [], Closure body) 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to answer your first question.
Yes groovy does have those suffixes. http://groovy.codehaus.org/Groovy+Math

@brasmusson brasmusson merged commit 1a5e98d into cucumber:master Jan 1, 2015
brasmusson added a commit that referenced this pull request Jan 1, 2015
@brasmusson
Copy link
Contributor

I added checks for multiple timeout or order arguments (c0a6c0f).

Thanks for your contribution @mhshams

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants