-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1496 from guillep/fix-tests
Defer tests to the morphic ui thread
- Loading branch information
Showing
5 changed files
with
193 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
Class { | ||
#name : 'SpBasePresenterTest', | ||
#superclass : 'SpBaseTest', | ||
#instVars : [ | ||
'presenter', | ||
'window' | ||
], | ||
#category : 'Spec2-Tests-Utils', | ||
#package : 'Spec2-Tests', | ||
#tag : 'Utils' | ||
} | ||
|
||
{ #category : 'testing' } | ||
SpBasePresenterTest class >> isAbstract [ | ||
|
||
^ self = SpBasePresenterTest | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBasePresenterTest >> adapter [ | ||
|
||
^ self subclassResponsibility | ||
] | ||
|
||
{ #category : 'assertions' } | ||
SpBasePresenterTest >> assertEvent: anEventName isRaisedInPresenter: aPresenter whenDoing: aBlock [ | ||
|
||
self | ||
assertWith: [ :times | times > 0 ] | ||
timesRaisedEvent: anEventName | ||
inPresenter: aPresenter | ||
whenDoing: aBlock | ||
] | ||
|
||
{ #category : 'assertions' } | ||
SpBasePresenterTest >> assertWith: assertionBlock timesRaisedEvent: anEventName inPresenter: aPresenter whenDoing: actionBlock [ | ||
|
||
| timesCalled | | ||
timesCalled := 0. | ||
aPresenter perform: anEventName with: [ timesCalled := timesCalled + 1 ]. | ||
actionBlock value. | ||
assertionBlock value: timesCalled | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBasePresenterTest >> classToTest [ | ||
self subclassResponsibility | ||
] | ||
|
||
{ #category : 'assertions' } | ||
SpBasePresenterTest >> denyEvent: anEventName isRaisedInPresenter: aPresenter whenDoing: aBlock [ | ||
|
||
self | ||
assertWith: [ :times | times = 0 ] | ||
timesRaisedEvent: anEventName | ||
inPresenter: aPresenter | ||
whenDoing: aBlock | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpBasePresenterTest >> initializeTestedInstance [ | ||
] | ||
|
||
{ #category : 'utilities' } | ||
SpBasePresenterTest >> openInstance [ | ||
|
||
window ifNil: [ window := presenter open ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBasePresenterTest >> presenter [ | ||
^ presenter | ||
] | ||
|
||
{ #category : 'running' } | ||
SpBasePresenterTest >> setUp [ | ||
super setUp. | ||
presenter := self classToTest newApplication: self application. | ||
self initializeTestedInstance | ||
] | ||
|
||
{ #category : 'running' } | ||
SpBasePresenterTest >> tearDown [ | ||
window ifNotNil: [ window delete ]. | ||
super tearDown | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testNewPresenterIsNotBuilt [ | ||
self deny: presenter isBuilt | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testNewPresenterIsNotDisplayed [ | ||
self deny: presenter isDisplayed | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testNonOpenPresenterDoesNotRaiseBuiltEvent [ | ||
| built | | ||
built := false. | ||
presenter whenBuiltDo: [ built := true ]. | ||
self deny: built | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testNonOpenPresenterDoesNotRaiseDisplayedEvent [ | ||
| displayed | | ||
displayed := false. | ||
presenter whenDisplayDo: [ displayed := true ]. | ||
self deny: displayed | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testOpenPresenterIsBuilt [ | ||
self openInstance. | ||
self assert: presenter isBuilt | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testOpenPresenterIsDisplayed [ | ||
self openInstance. | ||
self assert: presenter isDisplayed | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testOpenPresenterRaisesBuiltEvent [ | ||
| built | | ||
built := false. | ||
presenter whenBuiltDo: [ built := true ]. | ||
self openInstance. | ||
self assert: built | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testOpenPresenterRaisesDisplayEvent [ | ||
| displayed | | ||
displayed := false. | ||
presenter whenDisplayDo: [ displayed := true ]. | ||
self openInstance. | ||
self assert: displayed | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBasePresenterTest >> testRebuildPresenterDoNotLetReferencesInAnnouncer [ | ||
|
||
| oldSize newSize | | ||
presenter build. | ||
oldSize := presenter announcer subscriptions subscriptions size. | ||
"rebuild" | ||
presenter build. | ||
newSize := presenter announcer subscriptions subscriptions size. | ||
|
||
self assert: oldSize equals: newSize | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBasePresenterTest >> widget [ | ||
|
||
^ self adapter widget | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,167 +1,48 @@ | ||
" | ||
I am an abstract test class that makes all my subclass' test run on the UI thread to avoid concurrency issues. | ||
" | ||
Class { | ||
#name : 'SpBaseTest', | ||
#superclass : 'TestCase', | ||
#instVars : [ | ||
'presenter', | ||
'window' | ||
], | ||
#category : 'Spec2-Tests-Utils', | ||
#package : 'Spec2-Tests', | ||
#tag : 'Utils' | ||
} | ||
|
||
{ #category : 'testing' } | ||
SpBaseTest class >> isAbstract [ | ||
|
||
^ self = SpBaseTest | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBaseTest >> adapter [ | ||
|
||
^ self subclassResponsibility | ||
] | ||
|
||
{ #category : 'running' } | ||
SpBaseTest >> application [ | ||
|
||
^ SpApplication new | ||
] | ||
|
||
{ #category : 'assertions' } | ||
SpBaseTest >> assertEvent: anEventName isRaisedInPresenter: aPresenter whenDoing: aBlock [ | ||
|
||
self | ||
assertWith: [ :times | times > 0 ] | ||
timesRaisedEvent: anEventName | ||
inPresenter: aPresenter | ||
whenDoing: aBlock | ||
] | ||
|
||
{ #category : 'assertions' } | ||
SpBaseTest >> assertWith: assertionBlock timesRaisedEvent: anEventName inPresenter: aPresenter whenDoing: actionBlock [ | ||
|
||
| timesCalled | | ||
timesCalled := 0. | ||
aPresenter perform: anEventName with: [ timesCalled := timesCalled + 1 ]. | ||
actionBlock value. | ||
assertionBlock value: timesCalled | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBaseTest >> classToTest [ | ||
self subclassResponsibility | ||
] | ||
|
||
{ #category : 'assertions' } | ||
SpBaseTest >> denyEvent: anEventName isRaisedInPresenter: aPresenter whenDoing: aBlock [ | ||
|
||
self | ||
assertWith: [ :times | times = 0 ] | ||
timesRaisedEvent: anEventName | ||
inPresenter: aPresenter | ||
whenDoing: aBlock | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpBaseTest >> initializeTestedInstance [ | ||
] | ||
|
||
{ #category : 'utilities' } | ||
SpBaseTest >> openInstance [ | ||
|
||
window ifNil: [ window := presenter open ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBaseTest >> presenter [ | ||
^ presenter | ||
] | ||
|
||
{ #category : 'running' } | ||
SpBaseTest >> setUp [ | ||
super setUp. | ||
presenter := self classToTest newApplication: self application. | ||
self initializeTestedInstance | ||
^ SpApplication new | ||
useBackend: #Morphic with: StPharoMorphicConfiguration new; | ||
yourself | ||
] | ||
|
||
{ #category : 'running' } | ||
SpBaseTest >> tearDown [ | ||
window ifNotNil: [ window delete ]. | ||
super tearDown | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testNewPresenterIsNotBuilt [ | ||
self deny: presenter isBuilt | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testNewPresenterIsNotDisplayed [ | ||
self deny: presenter isDisplayed | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testNonOpenPresenterDoesNotRaiseBuiltEvent [ | ||
| built | | ||
built := false. | ||
presenter whenBuiltDo: [ built := true ]. | ||
self deny: built | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testNonOpenPresenterDoesNotRaiseDisplayedEvent [ | ||
| displayed | | ||
displayed := false. | ||
presenter whenDisplayDo: [ displayed := true ]. | ||
self deny: displayed | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testOpenPresenterIsBuilt [ | ||
self openInstance. | ||
self assert: presenter isBuilt | ||
] | ||
SpBaseTest >> run [ | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testOpenPresenterIsDisplayed [ | ||
self openInstance. | ||
self assert: presenter isDisplayed | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testOpenPresenterRaisesBuiltEvent [ | ||
| built | | ||
built := false. | ||
presenter whenBuiltDo: [ built := true ]. | ||
self openInstance. | ||
self assert: built | ||
] | ||
| finished result | | ||
UIManager default uiProcess == Processor activeProcess ifTrue: [ | ||
^ super run ]. | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testOpenPresenterRaisesDisplayEvent [ | ||
| displayed | | ||
displayed := false. | ||
presenter whenDisplayDo: [ displayed := true ]. | ||
self openInstance. | ||
self assert: displayed | ||
finished := Semaphore new. | ||
self application defer: [ | ||
result := super run. | ||
finished signal ]. | ||
finished wait. | ||
^ result | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpBaseTest >> testRebuildPresenterDoNotLetReferencesInAnnouncer [ | ||
|
||
| oldSize newSize | | ||
presenter build. | ||
oldSize := presenter announcer subscriptions subscriptions size. | ||
"rebuild" | ||
presenter build. | ||
newSize := presenter announcer subscriptions subscriptions size. | ||
|
||
self assert: oldSize equals: newSize | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpBaseTest >> widget [ | ||
|
||
^ self adapter widget | ||
{ #category : 'running' } | ||
SpBaseTest >> run: aResult [ | ||
|
||
| finished result | | ||
UIManager default uiProcess == Processor activeProcess ifTrue: [ | ||
^ super run: aResult ]. | ||
|
||
finished := Semaphore new. | ||
self application backend defer: [ | ||
result := super run: aResult. | ||
finished signal ]. | ||
finished wait. | ||
^ result | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters