Generating a Route stub from a route for testing

10 views
Skip to first unread message

Michael Slinn

unread,
Jul 25, 2016, 7:00:22 PM7/25/16
to play-framework
I've got a Play subproject that I'd like to test by itself. It invokes a reverse route defined in another subproject. Is there an easy way to generate a hackable reverse routes source file from a routes file?

For example, given these routes:

GET         /signOut                         controllers.silhouette.SilhouetteController.signOut
GET         /authenticate/:provider          controllers.silhouette.SocialAuthController.authenticate(provider)

GET         /signUp                          controllers.silhouette.SignUpController.view
POST        /signUp                          controllers.silhouette.SignUpController.submit


I'd like to generate something like this:

package play.api.mvc {
  case class Call(method: String, url: String, fragment: String = null) {
    override val toString = url
  }
}


package controllers.silhouette.routes {
  object SilhouetteController {
    def signOut() = Call("GET", "/signOut")
    def authenticate(provider: String) =
Call("GET", s"/authenticate/$provider")
  }

  object SignupController {
    def view() = Call("GET", "/signUp")
    def submit() = Call("POST", "/signUp")
  }
}

Seems easy enough to write, but I'd rather not reinvent this wheel.

Mike
Reply all
Reply to author
Forward
0 new messages