【问题标题】:How to test redirect location with reverse routing?如何使用反向路由测试重定向位置?
【发布时间】:2014-10-22 23:05:43
【问题描述】:

如何测试控制器是否使用 play framework 2.3 中的反向路由重定向到特定位置?我想做这样的事情:

  "LoginController#authenticate" should{
      "Redirect to index on success" in{
          ...
          val result = loginControllerTest.authenticate.apply(request)
          redirectLocation(result) must be(routes.Application.index)
   }

【问题讨论】:

    标签: scala testing playframework-2.0 specs2


    【解决方案1】:

    routes.Application.index 是一个Call,它包含一个method(GET、POST、PUT、DELETE)和一个url

    redirectLocation(result) 返回一个Option[String]None,如果没有重定向)

    你会想要这样的东西:

    redirectLocation(result) must beSome(routes.Application.index.url)
    

    routes.Application.index.toString 也会这样做。

    【讨论】:

      猜你喜欢
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 2020-10-06
      • 2017-10-22
      • 1970-01-01
      • 2016-11-22
      • 2020-04-29
      相关资源
      最近更新 更多