1

Trying add scalacheck into the spray-testkit + specs2 example: service with following route:

def myRoute = get(
  path("add" / IntNumber / IntNumber) ((a, b) =>
    complete((a+b).toString)
  )
)

and the test spec for it:

  "MyService" should {
    "do calculation" in {
      Get("/add/30/58") ~> myRoute ~> check {
        responseAs[String] === "88"
      }
    }
    "do calculation with scalacheck" in {
      check { (a: Int, b: Int) ⇒
        Get(s"/add/$a/$b") ~> myRoute ~> check {
          responseAs[String] === s"${a+b}"
        }
      }
    }
  }

should be pretty simple, but my brain is not allowed to formulate the second test case. i get error like

...MyService.Spec.scala:44: not found: value a"
 check { (a:Int, b:Int)
          ^
...MyService.Spec.scala:44: value ? is not a member of (Int, Int)
 check { (a:Int, b:Int) ?
                        ^

whats going on here and how to fix?

python_kaa
  • 1,034
  • 13
  • 27

1 Answers1

2

Replace the => for the arrow instead of the unicode character .

Then you should use prop instead of check and write:

"do calculation with scalacheck" in {
  prop { (a: Int, b: Int) =>
    Get(s"/add/$a/$b") ~> myRoute ~> check {
      responseAs[String] === s"${a+b}"
    }
  }
}
Eric
  • 15,494
  • 38
  • 61
  • sorry, in the error message was no closing curly, my mistake – python_kaa Oct 29 '15 at 08:42
  • Can you try to use `=>` for the arrow instead of the unicode character `⇒`? – Eric Oct 29 '15 at 08:43
  • Yes it was! Probably IDEA makes that. Looks better now but now at "in" keyword: could not find implicit value for evidence parameter of type org.specs2.execute.AsResult[MyServiceSpec.this.RouteResult => ((Int, Int) => org.specs2.matcher.MatchResult[Any])]´ – python_kaa Oct 29 '15 at 08:52
  • I think the issue comes from using `check`. See my edited answer. – Eric Oct 29 '15 at 08:55
  • how to import "prop"? from which namespace comes it from? – python_kaa Oct 29 '15 at 09:08
  • You get it if you extend the `org.specs2.ScalaCheck` trait on your specification. Also you need to make sure that you have the `specs2-scalacheck` jar on your classpath (and the `scalacheck` jar as well of course). – Eric Oct 29 '15 at 09:10
  • yes it works now! Thanks, couldn't figure it out without your help. Now the test works but fails after a few tries with Request was not handled but I think it is another problem – python_kaa Oct 29 '15 at 12:41
  • anyone, can you take a look at [this question](https://stackoverflow.com/questions/33669605/request-was-not-handled-with-spray-testkit)? it drives me nuts – python_kaa Jan 27 '16 at 10:35