0

I'm having trouble using scalamock to stub the post() method in WSRequestHolder in the Play WS library.

Here's what I'm trying:

(request.post[Results.EmptyContent](_ : Results.EmptyContent)(_ : Writeable[Results.EmptyContent], _: ContentTypeOf[Results.EmptyContent])) when(Results.EmptyContent(), *,*) returns Future.successful(response)

The aim is to return Future.successful(response) when a post() is called with Results.EmptyContent.

The compiler error I'm getting is:

value when is not a member of (play.api.mvc.Results.EmptyContent, play.api.http.Writeable[play.api.mvc.Results.EmptyContent], play.api.http.ContentTypeOf[play.api.mvc.Results.EmptyContent]) => scala.concurrent.Future[play.api.libs.ws.WSResponse] (request.post[Results.EmptyContent](_ : Results.EmptyContent)(_ : Writeable[Results.EmptyContent], _: ContentTypeOf[Results.EmptyContent])).when(Results.EmptyContent(), ,) returns Future.successful(response)

Any idea what I'm doing wrong?


UPDATE

There is something going on here that I don't really understand. If I define the following trait:

  trait TestTrait {
    def post[T](data: T)(implicit wrt: Writeable[T], ct: ContentTypeOf[T]): Future[WSResponse]
  }

which has a post() method with the same signature as WSRequestHolder.post(), I can successfully stub it. So, there is some weirdness specific to WSRequestHolder.post() that is manifesting in this problem. Some nuance with regard to type inference maybe?


UPDATE 2

So, I've found a workaround. In my test, I define a new trait that extends WSRequestHolder:

trait StubbableWSRequestHolder extends WSRequestHolder {
  override def post[T](data: T)(implicit wrt: Writeable[T], ct: ContentTypeOf[T]): Future[WSResponse] =
    withMethod("POST").withBody(body).execute()
}

In my test, I create my stub from this trait. As you can see, unlike in WSRequestHolder, my overriden signature for post() is explicit about the return type of Future[WSResponse].

The question remains, though, as to what exactly is going on here? Is this some kind of limitation with scalamock with regard to type inference?

DrewEaster
  • 3,316
  • 3
  • 35
  • 39
  • It's not immediately obvious to me what's going on here. Can you report a bug https://github.com/paulbutcher/ScalaMock/issues ideally with a small project that reproduces the problem and we'll see if we can take a look. – Paul Butcher Dec 13 '14 at 23:56
  • Okay, done: https://github.com/paulbutcher/ScalaMock/issues/87 – DrewEaster Dec 15 '14 at 16:21

1 Answers1

0

This issue was fixed in the ScalaMock-3.2.1

Pawel Wiejacha
  • 704
  • 7
  • 5