Permalink
Browse files

! testkit: enable custom ExceptionHandlers in routing tests

Up to now the `~>` operator injecting a request into a test route always wrapped the route execution with the default ExceptionHandler thereby ignoring potentially existing custom ExceptionHandlers. This is fixed with this patch.
 The change to the public API consists of one additional member to the implicit `TildeArrow.injectIntoRoute` method, which should rarely be called directly. In most cases this change therefore shouldn't break anything.
  • Loading branch information...
sirthias committed Jul 9, 2013
1 parent fb595ae commit 680fde0e5693b358d2f547436d19cf564ad091fe
Showing with 3 additions and 2 deletions.
  1. +3 −2 spray-testkit/src/main/scala/spray/testkit/RouteTest.scala
@@ -91,15 +91,16 @@ trait RouteTest extends RequestBuilding with RouteResultComponent {
type Out = HttpRequest
def apply(request: HttpRequest, f: HttpRequest HttpRequest) = f(request)
}
- implicit def injectIntoRoute(implicit timeout: RouteTestTimeout, settings: RoutingSettings, log: LoggingContext) =
+ implicit def injectIntoRoute(implicit timeout: RouteTestTimeout, settings: RoutingSettings,
+ log: LoggingContext, eh: ExceptionHandler) =
new TildeArrow[RequestContext, Unit] {
type Out = RouteResult
def apply(request: HttpRequest, route: Route) = {
val routeResult = new RouteResult(timeout.duration)
val effectiveRequest =
try request.withEffectiveUri(securedConnection = false)
catch { case NonFatal(_) request }
- ExecutionDirectives.handleExceptions(ExceptionHandler.default)(route) {
+ ExecutionDirectives.handleExceptions(eh orElse ExceptionHandler.default)(route) {
RequestContext(
request = effectiveRequest,
responder = routeResult.handler,

4 comments on commit 680fde0

@stig

This comment has been minimized.

Show comment
Hide comment
@stig

stig Jul 11, 2013

Contributor

I ran into this problem using 1.1-M8. I tried using a nightly build (http://nightlies.spray.io/io/spray/spray-testkit/1.2-20130710/ - as 1.1 does not have a recent enough one) but I'm still seeing the problem. Has this fix not managed to get into the 1.1/1.2 release branches yet?

Contributor

stig replied Jul 11, 2013

I ran into this problem using 1.1-M8. I tried using a nightly build (http://nightlies.spray.io/io/spray/spray-testkit/1.2-20130710/ - as 1.1 does not have a recent enough one) but I'm still seeing the problem. Has this fix not managed to get into the 1.1/1.2 release branches yet?

@sirthias

This comment has been minimized.

Show comment
Hide comment
@sirthias

sirthias Jul 11, 2013

Member

Stig, no it hasn't.
I'll do a merge from master into the release branches right away, so tomorrow's nightly will be up to date for you.

Member

sirthias replied Jul 11, 2013

Stig, no it hasn't.
I'll do a merge from master into the release branches right away, so tomorrow's nightly will be up to date for you.

@stig

This comment has been minimized.

Show comment
Hide comment
@stig

stig Jul 11, 2013

Contributor

Excellent :-)
In the meantime I've done that merge locally and verified that it does indeed work. I was thinking I could try and add a regression test for it, but I don't see where it should sit.

Contributor

stig replied Jul 11, 2013

Excellent :-)
In the meantime I've done that merge locally and verified that it does indeed work. I was thinking I could try and add a regression test for it, but I don't see where it should sit.

@sirthias

This comment has been minimized.

Show comment
Hide comment
Member

sirthias replied Jul 11, 2013

Ok, merged and pushed.

If you'd like to add a regression test for it, I guess it could sit here:
https://github.com/spray/spray/blob/f4a9b8814bc6b1751f519d9fd76ef4237670513e/spray-testkit/src/test/scala/spray/testkit/Specs2RouteTestSpec.scala

Please sign in to comment.