以下是我正在寻找的行为.我想要一个Groovy MockFor ignore方法来调用一个demand方法,而不是dontIgnoreMe()直接调用该方法的ignore方法.
从本质上讲,我想dontIgnoreMe()用mock 替换我,并ignoreMe()调用mock(我用metaClass做过)看起来类别可能是更好的解决方案.我将在下周调查一下,看看:groovy nabble feed
import groovy.mock.interceptor.MockFor
class Ignorable {
def dontIgnoreMe() { 'baz' }
def ignoreMe() { dontIgnoreMe() }
}
def mock = new MockFor(Ignorable)
mock.ignore('ignoreMe')
mock.demand.dontIgnoreMe { 'hey' }
mock.use {
def p = new Ignorable()
assert p.dontIgnoreMe() == 'hey'
assert p.ignoreMe() == 'hey'
}
Run Code Online (Sandbox Code Playgroud)
Assertion failed:
assert p.ignoreMe() == 'hey'
| | |
| baz false
Ignorable@6879c0f4
Run Code Online (Sandbox Code Playgroud)