Skip to content
andrewspinks edited this page Aug 22, 2016 · 1 revision

Changes in 0.3

It is no longer necessary to provide the done callback when constructing a new MockService. The MockService will now automatically fail the XCodeTest if the expected and received callbacks do not match.

This:

animalMockService = MockService(provider: "Animal Service", consumer: "Animal Consumer Swift", done: { result in
  expect(result).to(equal(PactVerificationResult.Passed))
})

Changes to:

    animalMockService = MockService(provider: "Animal Service", consumer: "Animal Consumer Swift")

It is no longer necessary to manually wait for the test to finish in the test. The run method now waits for the testComplete() function to be called.

it("gets an alligator") {
   var complete: Bool = false

   animalMockService!.given("an alligator exists")
                     .uponReceiving("a request for an alligator")
                     .withRequest(method:.GET, path: "/alligator")
   animalMockService!.run { (testComplete) -> Void in
     animalServiceClient!.getAlligator( { (alligator) in
         expect(alligator.name).to(equal("Mary"))
         complete = true
         testComplete()
       }, failure: { (error) in
         complete = true
         testComplete()
     })
   }

   // Wait for asynch HTTP requests to finish
   expect(complete).toEventually(beTrue())
}

Can be simplified to:

it("gets an alligator") {
   animalMockService!.given("an alligator exists")
                     .uponReceiving("a request for an alligator")
                     .withRequest(method:.GET, path: "/alligator")
   animalMockService!.run { (testComplete) -> Void in
     animalServiceClient!.getAlligator( { (alligator) in
         expect(alligator.name).to(equal("Mary"))
         testComplete()
       }, failure: { (error) in
         testComplete()
     })
   }
}

NB: To allow these changes to be added simply I have added a dependency to Nimble.

Clone this wiki locally