导致spec2单元测试编译错误的受保护特征 [英] Secured trait causing spec2 unit test compilation errors
问题描述
我已经按照但是,当我使用withAuth
函数装饰控制器动作时,如下所示:
However, when I decorate my controller actions with the withAuth
function like so:
def export = withAuth { username => implicit request =>
val csv = csv()
Ok(csv)
.as("text/csv")
.withHeaders(
CONTENT_DISPOSITION -> ("attachment; filename=export.csv"),
CONTENT_LENGTH -> csv.length.toString
)
}
我的控制器specs2单元测试中出现编译错误:
I get compilation errors in my controller specs2 unit tests:
"export data as CSV" in {
val controller = new controllers.DataController
val result = controller.export().apply(FakeRequest())
headers(result) must havePair("Content-Disposition" -> ("attachment; filename=export.csv"))
}
对headers
测试助手功能的调用失败,并显示以下编译器错误消息:
The call to the headers
test helper function fails with the following compiler error message:
类型不匹配;找到:play.api.libs.iteratee.Iteratee [Array [Byte],play.api.mvc.Result]必需:scala.concurrent.Future [play.api.mvc.Result]
type mismatch; found : play.api.libs.iteratee.Iteratee[Array[Byte],play.api.mvc.Result] required: scala.concurrent.Future[play.api.mvc.Result]
我做错什么了吗?我已经尝试了一些补救措施
Am I doing something wrong? I've tried some of the remedies suggested by other Stackoverflow users but they all seem to rely on setting the body type, but my actions do not have a body type.
似乎对withAuth
的调用使被包装的Action的某些类型模糊了,所以也许有一种更安全的方式来表达Secured
特征的方式?
It looks as though the call to withAuth
obscures some of the types of the Action being wrapped so maybe there is a more type-safe way of expressing the Secured
trait?
推荐答案
尝试更改此内容:
val result = controller.export().apply(FakeRequest())
对此:
val result = controller.export().apply(FakeRequest()).run
然后它应该工作.
这篇关于导致spec2单元测试编译错误的受保护特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!