Closed GoogleCodeExporter closed 9 years ago
Suggestion:
def mock1 = mock(Loader, constructor: IllegalArgumentException)
def mock2 = mock(Loader, constructor: new IllegalArgumentException
("message")) // force to new an exception if parameters are needed
Original comment by JohnnyJianHY
on 14 Oct 2008 at 6:51
But how to match parameters of constructor?
Original comment by JohnnyJianHY
on 14 Oct 2008 at 6:52
Indeed. The expection should be raise only on matching constructor. What about:
def mockLoader = mock(Loader, constructor:[1,2]).raises(new Exception())
The raises keyword should then only be used when using constructor:.
Original comment by julien.g...@gmail.com
on 14 Oct 2008 at 6:58
It is good and consistent with the current API. But I just worry that is it
readable
and easy to understand for most users?
Original comment by JohnnyJianHY
on 14 Oct 2008 at 7:06
Wait, it will have to add a "raises" method to Mock, then it stops users to
mock a
method named "raises".
Consider that
def mockLoader = mock(Loader, constructor:[1,2]).raises(new Exception())
is equal to
def mockLoader = mock(Loader, constructor:[1,2])
mockLoader.raises(new Exception())
Original comment by JohnnyJianHY
on 14 Oct 2008 at 7:11
You are absolutely right. Well spotted.
What about:
mock(Loader, constructor:[1,2], raises(new Exception())
So we are still consistent with the API.
Original comment by julien.g...@gmail.com
on 14 Oct 2008 at 7:29
Should we reconsider the DSL of constructor? Because it seems to become
unreadable
if we keep on like that.
Suggestion:
def mock1 = mock(Loader) { constructor(1, 2) }
def mock2 = mock(Loader) {
constructor(1, 2).raises(Exception)
}
What's more, consider strict order mocking, if someone expects that a static
method
should be invoked before the constructor do, then our solution will not work.
Original comment by JohnnyJianHY
on 14 Oct 2008 at 7:40
As properties named "new" is supported since Groovy 1.6, we can build a DSL
like:
def mock = mock(Loader)
mock.new(1, 2)
mock.new(1, 2).raises(Exception)
Then we can add a method named "getNew" to Mock, which returns a closure.
Original comment by JohnnyJianHY
on 14 Oct 2008 at 8:46
I think I quite like your later proposal. It's not as intuitive to me as the
current
behavior but it will greatly help for the static/strict mocking.
So let's go for mock.new(1,2) and see if it work,
Original comment by julien.g...@gmail.com
on 15 Oct 2008 at 7:36
OK, but we have to update to Groovy 1.6 beta 2.
Original comment by JohnnyJianHY
on 15 Oct 2008 at 8:26
I missed the Groovy 1.6 point sorry. We can't really use it grails is still on
1.5. We'll have with something
else.
Original comment by julien.g...@gmail.com
on 15 Oct 2008 at 5:20
In Groovy 1.5, we can still mock like:
def mock = mock(Loader)
mock.'new'(1, 2)
Original comment by JohnnyJianHY
on 16 Oct 2008 at 10:59
Any thought?
Original comment by JohnnyJianHY
on 17 Oct 2008 at 9:40
I am not entirely convinced here. mock.'new'(1, 2) is not the most intuitive
part of
our dsl. Should we move this to a latter release to give us more time and some
external thought.
Original comment by julien.g...@gmail.com
on 17 Oct 2008 at 3:53
OK, two releases later. Hope Groovy 1.6 and Grails 1.1 will be released before
that.
Original comment by JohnnyJianHY
on 17 Oct 2008 at 5:23
Original comment by julien.g...@gmail.com
on 25 Dec 2008 at 3:25
Original comment by JohnnyJianHY
on 26 Dec 2008 at 5:02
Original comment by julien.g...@gmail.com
on 26 Dec 2008 at 10:58
Original issue reported on code.google.com by
JohnnyJianHY
on 14 Oct 2008 at 6:45