Can we test self sends this way? 2011/7/19 Denis Kudriashov <[email protected]>
> I should add it to Mocketry. > > 2011/7/19 Sean P. DeNigris <[email protected]> > > Ah, so the lookups are done once when the method is compiled and then >> stored >> in the CompiledMethod... >> >> My vision is to write something like: >> cannedNow := DateAndTime stub: #now; andReturn: [ DateAndTime year: >> 2011 >> month: 12 day: 24 hour: 12 minute: 34 second: 55 ]. >> testableClass := MyClass usingDouble: cannedNow. >> >> The first line seems easy, and for the second line, I have so far (very >> rough, but working): >> >> | class copy | >> class := MyClass. >> copy := MyClass copy. >> >> copy methods do: [ :m | | classRef | >> (m hasLiteralSuchThat: [ :l | ((l isKindOf: Association) >> and: [ l key = >> #DateAndTime])]) >> ifTrue: [ | newMeth refIndex | >> newMeth := copy methodDictionary at: m >> selector put: m copy. >> refIndex := newMeth indexOfLiteralSuchThat: >> [ :l | ((l isKindOf: >> Association) and: [ l key = #DateAndTime])]. >> newMeth literalAt: refIndex put: >> #DateAndTime->MockedClass ] ]. >> ^ copy. >> >> Where CompiledMethod>>indexOfLiteralSuchThat: aBlock >> "Answer the literal index of the argument, literal, or zero if >> none." >> 2 to: self numLiterals - 1 "exclude superclass + >> selector/properties" >> do: >> [:index | >> (aBlock value: (self objectAt: index)) ifTrue: [^index - >> 1]]. >> ^0 >> >> Thanks again. >> Sean >> >> >> -- >> View this message in context: >> http://forum.world.st/Stubbing-class-side-methods-tp3674065p3676637.html >> Sent from the Pharo Smalltalk mailing list archive at Nabble.com. >> >> > -- Dennis Schetinin
