Hi guys
in RPackage there is a method named withOrganizer:do: defined as follows and I
would like to test it to understand really if it does
what it says.
withOrganizer: aNewOrganizer do: aBlock
"Perform an action locally to aNewOrganizer. Does not impact any other
organizers."
| old shouldRegisterAtTheEnd|
[
old := self organizer.
shouldRegisterAtTheEnd := false.
old hasRegistered ifTrue: [
old unregister.
shouldRegisterAtTheEnd := true.
].
self organizer: aNewOrganizer.
aBlock cull: aNewOrganizer.] ensure: [
self organizer: old.
shouldRegisterAtTheEnd ifTrue: [
self organizer register.
].
aNewOrganizer unregister.
]
So I wrote two tests
testWithDoIsCorrectlyReinstallingDefault
"self debug: #testWithDoIsCorrectlyReinstallingDefault"
| current empty |
current := RPackageOrganizer default.
empty := RPackageOrganizer basicNew initialize.
RPackage withOrganizer: empty
do: [ self assert: (SystemAnnouncer announcer hasSubscriber:
empty).
self deny: (SystemAnnouncer announcer hasSubscriber:
current)].
self assert: (SystemAnnouncer announcer hasSubscriber: current).
self deny: (SystemAnnouncer announcer hasSubscriber: empty)
and
testWithDoIsCorrectlyReinstallingDefaultEvenIfHalt
"self debug: #testWithDoIsCorrectlyReinstallingDefaultEvenIfHalt"
| current empty |
current := RPackageOrganizer default.
empty := RPackageOrganizer basicNew initialize.
RPackage withOrganizer: empty
do: [ self error.
self assert: (SystemAnnouncer announcer hasSubscriber:
empty).
self deny: (SystemAnnouncer announcer hasSubscriber:
current)].
self assert: (SystemAnnouncer announcer hasSubscriber: current).
self deny: (SystemAnnouncer announcer hasSubscriber: empty)
Now I would like to make sure that I raise an error or whaever to make sure
that the ensure: block argument
is executed. Does anybody have an idea how I can do that. because self error
does not work.
Stef