Ah, right. I was expecting that other objects sending the message will receive the mocked result.
Thanks, Peter On Fri, Oct 20, 2017 at 2:21 PM, Denis Kudriashov <[email protected]> wrote: > Yes, but in that case you stub messages to the class itself. For your > example it means: > > Something stub askForName willReturn: 'new'. > > Something askForName should be: 'new' > > > > 2017-10-20 13:58 GMT+02:00 Peter Uhnák <[email protected]>: > >> Thanks Denis, that did the trick. >> >> But I thought that I can also mock at the class level (at least it was >> shown in the docs). >> >> Peter >> >> On Sat, Oct 7, 2017 at 11:24 AM, Denis Kudriashov <[email protected]> >> wrote: >> >>> Hi Peter. >>> >>> You should stub instance instead of class: >>> s := Something new. >>> s stub askFor... >>> >>> 7 окт. 2017 г. 9:18 пользователь "Peter Uhnák" <[email protected]> >>> написал: >>> >>> Hi, >>>> >>>> maybe I am missing something fundamental, because this seems like an >>>> obvious scenario >>>> >>>> I have a class Something with two methods >>>> >>>> Something>>askForName >>>> ^ UIManager default request: 'Name' >>>> >>>> Something>>name >>>> ^ self askForName , ' suffix' >>>> >>>> Now I want to mock out askForName, so I can run it automatically in >>>> tests... >>>> >>>> I've tried just stubbing it... >>>> >>>> SomethingTest>>testRenameStub >>>> Something stub askForName willReturn: 'new'. >>>> Something new name should be: 'new suffix' >>>> >>>> however it still opens the window to ask for the name, so the original >>>> method is being called. >>>> >>>> Right now I have to stub it with metalinks, which doesn't play well >>>> with some tools (hapao) >>>> >>>> SomethingTest>>testRenameMeta >>>> | link newName | >>>> link := MetaLink new >>>> metaObject: [ 'new' ]; >>>> control: #instead. >>>> (Something >> #askForName) ast link: link. >>>> [ newName := Something new name ] >>>> ensure: [ link uninstall ]. >>>> self assert: newName equals: 'new suffix' >>>> >>>> Thanks, >>>> Peter >>>> >>>> >> >
