The #should:raise style methods don't give very good
error messages. They should report the Error they
recieved as in the following (the last method has all
the magic)
should: aBlock raise: anExceptionalEvent
self should: aBlock raise: anExceptionalEvent
description: ''
should: aBlock raise: anErrorClass description:
aStringDescription
^self should: aBlock raise: anErrorClass matching:
[:ignored| true ] description: aStringDescription
should: aBlock raise: anErrorClass matching:
aBlockForException
^self should: aBlock raise: anErrorClass matching:
aBlockForException description: ''
should: aBlock raise: anErrorClass matching:
aBlockForException description: aStringDescription
| formattedDescription raised |
aStringDescription isEmpty
ifTrue: \[formattedDescription := ''\]
ifFalse: \[formattedDescription := ' \(' ,
aStringDescription , ')'].
raised := false.
\[\[aBlock value\] sunitOn: anErrorClass
do:
\[:ex |
raised := true.
\(aBlockForException value: ex\) ifTrue: \[^true\].
self assert: false
description: 'Raised \#' , anErrorClass name , ' but
failed to match '
, aBlockForException printString,
formattedDescription ]]
sunitOn: TestResult error
do:
[:ex |
raised
ifTrue: [ex signal]
ifFalse:
[self assert: false
description: 'Should raise: #' , anErrorClass
name , ' but was: #' , ex class name
, formattedDescription]].
self assert: false description: 'Should raise: \#' ,
anErrorClass name , formattedDescription