question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support (groovy) method names with spaces

See original GitHub issue

Groovy allows method names with spaces and other special chars, like this here:

@Given("")
void "ein Benutzer ist als Admin mit dem Benutzernamen {string} angemeldet"(String userMail) {
	final def adminEmail = getProperty(userMail);
}

This would allow us to use the actual step definition string as the method name, instead of artificial/weird method names.

This could easily be supported by adding this “fix” to the JavaStepDefinition class. Instead of failing if the annotation value is empty, it could do this:

if (expression != null && !"".intern().equals(expression)) {
	this.expression = requireNonNull(expression, "cucumber-expression may not be null");
} else {
	// groovy methods can be strings, so in case the expression is empty, we just use the method name
	this.expression = method.getName();
}

Possibly combined with a check if the class implements GroovyObject.

Additionally it would be nice to set the annotation default values to an empty string, so that @Given("") could be further reduced to @Given.

With such a small code change groovy support could be drastically improved (even without a separate backend!).

I tried this myself (created a new groovy backend) but failed because both the java and my groovy backend matched the same step definitions leading to duplication exceptions.

Hope you guys are open for such improvements 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mpkorstanjecommented, Apr 9, 2020

I’m not really interested in maintaining an exception and associated tests for Groovy.

it would conflict with the java backend.

Each backend should use its own annotations/methods and through the ObjectFactory each backend also has access to the same test context. There should be very little conflict.

0reactions
stale[bot]commented, Sep 21, 2021

This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective.

Read more comments on GitHub >

github_iconTop Results From Across the Web

groovy call method name contains special character
Save this question. Show activity on this post. I'd like to call a method which name contains space in static context, but it...
Read more >
Groovy Language Documentation
is an agile and dynamic language for the Java Virtual Machine. builds upon the strengths of Java but has additional power features inspired...
Read more >
Groovy Goodness: Use Keywords as Method Names - Mrhaki
Normally we cannot use keywords in Java or Groovy to use as method names. But in Groovy we can. We need to enclose...
Read more >
[groovy-dev] Inconsistent behavior when method name has ...
remembered that in some Spock example I had seen that working fine. So, officially, does groovy support methods with names having spaces? Right...
Read more >
Special characters in method names - Google Groups
Does the JVM specification allow special characters (e.g. space, ... if I could use such method names in my Groovy-based DSL, but first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found