Two suggestions inspired by spock

2 views
Skip to first unread message

Johnny

unread,
Mar 5, 2009, 7:22:29 PM3/5/09
to gmoc...@googlegroups.com
Two new features are quickly coming into my mind after I read spock's
document.

1. Allow using regular expressions as method names:

def mock = mock()
mock./set.*/(1).returns(2)
play {
assertEquals 2, mock.setSomething(1)
}

It is easy to implement, just change '==' to '==~' in method name
matching.

2. AST transformation @WithGMock(I am not sure it is a proper name):

@WithGMock
class SomeTest extends TestCase { // not extending GMockTestCase
void testSomething() {
def mock = mock()
mock.fun()
play {
mock.fun()
}
}
}

The code above will be transformed to:

class SomeTest extends TestCase {
private $gMockController = new org.gmock.GMockController()
private mock(Object... args) {
$gMockController.mock(args)
}
...
private match(Closure closure) {
org.gmock.GMock.match(closure)
}
...
void testSomething() {
def mock = mock()
mock.fun()
play {
mock.fun()
}
}
}

This can simplify the tests which are not extending GMockTestCase.


Julien Gagnet

unread,
Mar 6, 2009, 2:37:14 AM3/6/09
to gmoc...@googlegroups.com
I noticed the regex in method names and I must say it's very cool. If
it's as easy as you think to implement then we should probably push it
to the current release.

The AST transformation is really cool as well. We need to use Groovy
1.6 for that one I think so after or within gmock 0.8

2009/3/6 Johnny <johnny...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages