I am trying to create a mock for Play's WSClient like this:
def mockGet[A](url : String, method : String, headers : Seq[(String, String)], timeout : Duration)(
response: Future[AhcWSResponse]
) =
(mockWsClient
.url(_ : String)
.withMethod(_ : String)
.withHttpHeaders(_: (String, String)*)
.withRequestTimeout(_ : Duration)
.stream())
.expects(url, method, headers, timeout)
.returning(response)
The problem is the withHttpHeaders
- this actually takes (String, String)* but when I specify that type as above I get a compiler error like this:
[error] found : Seq[(String, String)]
[error] required: (String, String)
[error] .withHttpHeaders(_: Seq[(String, String)])
What type do I need to specify for this method because (String, String) is not correct. The actual real definition of this method is:
override def withHttpHeaders(headers: (String, String)*): Self
UPDATE
I tried this after @Mario's suggestion:
def mockGet[A](url: String, method: String, headers: Seq[(String, String)], timeout: Duration)(
response: (String, String, Duration) => Future[ws.WSResponse]
) =
(
(
xs: Seq[(String, String)]
) =>
mockWsClient
.url(_: String)
.withMethod(_: String)
.withRequestTimeout(_: Duration)
.withHttpHeaders(xs: _*)
.stream()
)
.expects(headers)
.returning(response)
but this crashes the compiler with:
[error] value x$1