We should define the behavior of multiple 'returns()' calls on expectation

2 views
Skip to first unread message

Johnny

unread,
Mar 6, 2009, 1:28:53 AM3/6/09
to gmoc...@googlegroups.com
Currently, we have not treated multiple 'returns()' calls on expectation
well. Later calls will override former calls. For example:

def mock = mock()
mock.a().returns(1).returns(2)
play {
println mock.a() // output: 2
}

I think we should follow the approach of mocha:

def mock = mock()
mock.a().returns(1).returns(2)
play {
assert 1 == mock.a()
assert 2 == mock.a()
}

And also an optional 'then' property:

def mock = mock()
mock.a().returns(1).then.returns(2)
play {
assert 1 == mock.a()
assert 2 == mock.a()
}

We might also want to support multiple parameters:

def mock = mock()
mock.a().returns(1, 2, 3)
play {
assert 1 == mock.a()
assert 2 == mock.a()
assert 3 == mock.a()
}

What's your opinion?

Julien Gagnet

unread,
Mar 6, 2009, 2:38:56 AM3/6/09
to gmoc...@googlegroups.com
Yes why not. I would stick with the simplier version of it with:

mock.a().returns(1).returns(2)



2009/3/6 Johnny <johnny...@gmail.com>:

Johnny

unread,
Mar 6, 2009, 2:52:01 AM3/6/09
to gmoc...@googlegroups.com
OK. I have thought over the multiple parameters returns call, and it
will be complex with times expectation and strict ordering, so let's
shelve it until someone ask for it.

在 2009-03-06五的 07:38 +0000,Julien Gagnet写道:
Reply all
Reply to author
Forward
0 new messages