Open GoogleCodeExporter opened 8 years ago
Same here: groovy: 2.2.2, spock: 0.7-groovy-2.0
I need it to be working in the same way, as I'm mocking collaborators and with
GroovyMock they evaluate to false, and throw exceptions. For now I'll use
regular mocks.
Original comment by janusz.s...@gmail.com
on 28 Apr 2014 at 5:22
Example test http://meetspock.appspot.com/script/5700735861784576
Original comment by janusz.s...@gmail.com
on 28 Apr 2014 at 5:28
Why is your test depending on the truthiness of a mock object? What's the use
case?
Original comment by pnied...@gmail.com
on 28 Apr 2014 at 5:31
This will do the trick:
def groovyMock = GroovyMock(Map) { asBoolean() >> true }
Perhaps this should be the default. Not sure.
Original comment by pnied...@gmail.com
on 28 Apr 2014 at 5:33
void initialize() {
if( ! config) {
throw new RuntimeException('configuration has not been injected')
}
// ... initialize logic
}
I'm not saying it's good design to have initialize method, but it'll work for
now. However GroovyMock config object injected via constructor evaluates to
false. Using Mock, it's OK.
Original comment by janusz.s...@gmail.com
on 28 Apr 2014 at 5:35
I see. Thanks for the explanation.
By the way, GroovyMock() should only be used where Mock() isn't good enough.
Original comment by pnied...@gmail.com
on 28 Apr 2014 at 5:37
>> def groovyMock = GroovyMock(Map) { asBoolean() >> true }
Great - thanks for reply. Works perfectly :-)
Original comment by janusz.s...@gmail.com
on 28 Apr 2014 at 5:39
I see I used the elvis operator so that's probably the specific case I ran into
at the time. I suspect I was doing some kind of lookup and found a GroovyMock
instance but instead I got the value on the right side of the operator.
I don't like having to explicitly define this kind of behavior or the explicit
Object type on the groovy mock or be forced to use null checking instead of the
elvis operator.
As for preferring GroovyMock instead of Mock. I understand why you may feel
that way but I do prefer the dynamic aspect of GroovyMock in some cases. Much
like how Brian Marick uses dynamic mocks in his Robozzle kata.
(http://vimeo.com/19404746)
Does it not make more sense for Mock and GroovyMock to behave the same way?
Original comment by s...@thinkerit.be
on 28 Apr 2014 at 6:28
Original issue reported on code.google.com by
s...@thinkerit.be
on 17 Jun 2013 at 12:36