Skip to content

Commit

Permalink
! testkit: enable custom ExceptionHandlers in routing tests
Browse files Browse the repository at this point in the history
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 680fde0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions spray-testkit/src/main/scala/spray/testkit/RouteTest.scala
Expand Up @@ -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,
Expand Down

4 comments on commit 680fde0

@stig
Copy link
Contributor

@stig stig commented on 680fde0 Jul 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

@stig stig commented on 680fde0 Jul 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.