Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 1.7.5
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
Description
The method 'with' is very useful to write clean code, but it would be even more useful if it returned the object in which it is called, making it very nice for creating DSLs.
I was writing an automated test with selenium and I wanted to do something like:
class MyTestsSuperClass extends SeleneseTestCase {
def fill(Form form) {
// implementation details
}
}
class MyTest extends MyTestsSuperClass {
@Test
def testSomething() {
// ...
fill form.with { date = "2010/09/27" }
// ...
}
}
I can't do it right now because form.with {} will return me a String (the result of the last statement executed inside the closure).
I worked it around overwriting 'with' in my Form class as:
def with(Closure closure) { super.with(closure) return this }
But I think it would make more sense if this was the default behavior of the 'with' method.
Sorry if this suggestion has come up already.. it is not so easy to search for 'with' though, I hope you understand.
Thanks a lot!
Issue Links
- duplicates
-
GROOVY-3976
Improve "with" by ending with implied "return delegate"
-
Duplicate of issue GROOVY-3976. Please track that one for this requirement.