jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-4442

'with' method should return the object in which it was called

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major 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

Improvement - An improvement or enhancement to an existing feature or task. GROOVY-3976 Improve "with" by ending with implied "return delegate"

  • Major - Major loss of function.
  • Open - The issue is open and ready for the assignee to start work on it.

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Roshan Dawrani added a comment - 29/Sep/10 6:29 AM

Duplicate of issue GROOVY-3976. Please track that one for this requirement.

Show
Roshan Dawrani added a comment - 29/Sep/10 6:29 AM Duplicate of issue GROOVY-3976. Please track that one for this requirement.

People

  • Assignee:
    Roshan Dawrani
    Reporter:
    Luiz Ribeiro
Vote (0)
Watch (0)

Dates

  • Created:
    27/Sep/10 1:18 PM
    Updated:
    29/Sep/10 6:29 AM
    Resolved:
    29/Sep/10 6:29 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.