[Seaside-dev] Testing trouble

Julian Fitzell jfitzell at gmail.com
Sat Jan 12 15:43:29 UTC 2013


We prefer to have an error signaled as it makes it easier to spot problems
(if a nil is returned, an error might not be thrown until much later and
you might not know why it's nil). You shouldn't be getting a dNU, though;
you should be a getting a WARequestContextNotFound.

As Ken suggests, if your code actually depends on the session, you'd be
better to provide one in your test setup. If not, you can always implement
#user to use #on:do:

user
  ^ [ self session user ] on: WARequestContextNotFound do: [ :e | nil ]

Julian

On Fri, Jan 11, 2013 at 9:59 AM, Diego Lont <diego.lont at delware.nl> wrote:

> Hi all,
>
> I have a problem in testing my code. I have a user in my session I want to
> use for logging changes (among other things). By default I can access the
> user in a WAObject by the following code:
>         self session user.
>
> When I now write a test, this code crashes on a doesNotUnderstand on
> #session. In WAObject the requestContext is nil, because it is not in a
> request (it is in a test) and I have no session. I want to include one fix
> in WAObject:
>
> session
>         "Answer the current seaside session, instance of WASesssion or a
> subclass."
>         self requestContext ifNotNilDo: [ :context | ^context session ].
>         ^nil
>
> And the same trick in my own code saying:
>
> user
>         "Answer the current seaside session, instance of WASesssion or a
> subclass."
>         self session ifNotNilDo: [ :session | ^session user ].
>         ^nil
>
> In this way I have no trouble in testing my code.
>
> Does this change make sense to you too?
>
> Cheers,
> Diego_______________________________________________
> seaside-dev mailing list
> seaside-dev at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside-dev/attachments/20130112/38a065c8/attachment.htm


More information about the seaside-dev mailing list