There is already <font color="#000080">#should:raise:withExceptionDo:</font> which purposes exactly this purpose.<br>
<br>
Can I change the behavior of the <font color="#000080">#should:raise:</font> selectors so that they answer the result of aBlock if there was no error? For instance, this should just work:<br>
<br>
    <font color="#FF0000">result</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#000000">TestCase</font><font color="#000000"> </font><font color="#000080">new</font><font color="#000000"> </font><font color="#000080">should:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">2</font><font color="#000080">/</font><font color="#800000">0</font><font color="#000000">]</font><font color="#000000"> </font><font color="#000080">raise:</font><font color="#000000"> </font><font color="#000000">ZeroDivide</font><font color="#000000"> </font><font color="#000080">withExceptionDo:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000000">:</font><font color="#000080">ex</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#000080">ex</font><font color="#000000"> </font><font color="#000080">resume:</font><font color="#000000"> </font><font color="#800000">42</font><font color="#000000">]</font><br>
<br>
<br>
<font color="#808080">(Fun fact: Today, you can even find that existing selector with my refurbished method finder from SimulationStudio:<br>
</font><br>
<font color="#000000">    </font><font color="#808080">|</font><font color="#000000"> </font><font color="#6B6B6B">case</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"><br>
    </font><font color="#6B6B6B">case</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#000000">TestCase</font><font color="#000000"> </font><font color="#000080">new</font><font color="#000000">.</font><font color="#000000"><br>
    </font><font color="#000000">Sandbox</font><font color="#000000"><br>
        </font><font color="#000080">findSelectorsFor:</font><font color="#000000"> </font><font color="#6B6B6B">case</font><font color="#000000"><br>
        </font><font color="#000080">arguments:</font><font color="#000000"> </font><font color="#000000">{</font><font color="#000000">[</font><font color="#000000">Dictionary</font><font color="#000000"> </font><font color="#000080">new</font><font color="#000000"> </font><font color="#000080">at:</font><font color="#000000"> </font><font color="#800000">0</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"> </font><font color="#000000">KeyNotFound</font><font color="#000000">.</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000000">:</font><font color="#000080">ex</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">assert:</font><font color="#000000"> </font><font color="#000080">ex</font><font color="#000000"> </font><font color="#000080">key</font><font color="#000000"> </font><font color="#000080">=</font><font color="#000000"> </font><font color="#800000">0</font><font color="#000000">]</font><font color="#000000">}</font><font color="#000000"><br>
        </font><font color="#000080">thatAnswer:</font><font color="#000000"> </font><font color="#6B6B6B">case</font><font color="#000000"> </font><font color="#008080">"a Set(#should:raise:withExceptionDo: #addModelMenuItemsTo:forMorph:hand: #toFinalizeSend:to:with: #should:raise:description:)"</font><font color="#808080"><br>
<br>
:-) )</font><br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font><br>
<br>
On 2020-03-20T19:01:48+00:00, commits@source.squeak.org wrote:<br>
<br>
> Christoph Thiede uploaded a new version of SUnit to project The Inbox:<br>
> http://source.squeak.org/inbox/SUnit-ct.124.mcz<br>
> <br>
> ==================== Summary ====================<br>
> <br>
> Name: SUnit-ct.124<br>
> Author: ct<br>
> Time: 20 March 2020, 8:01:47.398237 pm<br>
> UUID: d936b6a0-e7c7-2742-a817-35fa6511a15a<br>
> Ancestors: SUnit-mt.121<br>
> <br>
> Proposal for discussion: Adds assertion message #should:raise:then: to allow for interactively working with expected exceptions. If you like, we could also talk about #should:raise:that: (however, I still like BlockClosure >> #handles:*).<br>
> <br>
> Examples:<br>
> <br>
> TestCase new in: [:test |<br>
>     <br>
>     test<br>
>         should: [<br>
>             test<br>
>                 should: [self error: #foo]<br>
>                 raise: Error<br>
>                 then: #pass]<br>
>         raise: UnhandledError.<br>
>     <br>
>         test<br>
>             should: [self error: #foo]<br>
>             raise: Error<br>
>             then: [:ex |<br>
>                 test assert: #foo equals: ex messageText].<br>
>     <br>
> ]<br>
> <br>
> * See exception patterns: http://forum.world.st/The-Inbox-Kernel-ct-1292-mcz-tp5109282p5109284.html<br>
> <br>
> =============== Diff against SUnit-mt.121 ===============<br>
> <br>
> Item was added:<br>
> + ----- Method: TestCase>>should:raise:then: (in category 'accessing') -----<br>
> + should: aBlock raise: anExceptionalEvent then: aHandlerBlock<br>
> + <br>
> +     | raised result |<br>
> +     raised := false.<br>
> +     result := aBlock<br>
> +         on: anExceptionalEvent<br>
> +         do: [:ex |<br>
> +             raised := true.<br>
> +             aHandlerBlock cull: ex].<br>
> +     self assert: raised.<br>
> +     ^ result!<br>
> <br>