2

I have problem with Pact JVM for spec2 consumer running with sbt. - What can be wrong? - I doesn't generate any pact file.

given:

  • sbt project with dependencies

    "au.com.dius" %% "pact-jvm-consumer-specs2" % "3.2.11"

    "org.specs2" %% "specs2-junit" % "3.3.1"

I have spec class:

import java.util.concurrent.TimeUnit.MILLISECONDS

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
import akka.stream.ActorMaterializer
import au.com.dius.pact.consumer.PactSpec
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner

import scala.concurrent.duration._
import scala.concurrent.Await
import scala.concurrent.duration.Duration

@RunWith(classOf[JUnitRunner])
class PactClientSpec extends Specification with PactSpec {
  sequential

  override val provider: String = "SpecsProvider"
  override val consumer: String = "SpecsConsumer"


  implicit val actorSystem = ActorSystem()
  implicit val materializer = ActorMaterializer()
  implicit val dispatcher = actorSystem.dispatcher

  val timeout = Duration(5000, MILLISECONDS)

  override def is = uponReceiving("a request for foo")
    .matching(path = "/users/1234")
    .willRespondWith(body = "{}")
    .withConsumerTest { providerConfig =>

      val responseFuture= Http().singleRequest(HttpRequest(uri = s"http://${providerConfig.url}/users/1234"))
      val response = Await.result(responseFuture, 10 seconds)
      "Hello world" must endWith("world")
    }
}

When I run with sbt test I get:

x Consumer 'SpecsConsumer' has a pact with Provider 'SpecsProvider': a request for foo 2
[error]
[error]  missing:
[error]         method: GET
[error]         path: /users/1234
[error]         query: null
[error]         headers: [:]
[error]         matchers: [:]
[error]         body: au.com.dius.pact.model.OptionalBody(EMPTY, ) (PactSpec.scala:29)
[info] PactClientSpec
[info]
[info] Total for specification PactClientSpec
[info] Finished in 707 ms
[info] 1 example, 1 failure, 0 error
[info]
[info] ScalaCheck
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] ScalaTest
[info] Run completed in 2 seconds, 562 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error]         PactClientSpec
[error] (token-manager/test:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 8 s, completed Sep 29, 2016 2:26:52 PM
J_A_X
  • 12,824
  • 1
  • 23
  • 31

1 Answers1

0

I seems that problem was using akka + spec2. Similar example with scalaetest and pact jvm works.