var session: Session! override func setUp() { super.setUp() let expectation = expectationWithDescription("Set up Pact environment") // ϞοΫαʔόʔͷॳظԽ controlServer.startSession(withConsumerName: "Cookpad", providerName: "APIServer") { newSession in if let newSession = newSession { self.session = newSession expectation.fulfill() } } waitForExpectationsWithTimeout(3.0) } func testSearchRecipe() { let manager = RecipeManager(baseURL: session.baseURL) let expected = [ "recipes": [ ["name": "େτϩ", "description": "ඒຯ͍"], ["name": "͏ʹ", "description": "ඒຯ͍"], ] ] // Interactionͷొ let expectation = expectationWithDescription("recipes are found") session.given("some recipes exist") // Provider State .uponReceiving("a request for recipes") .with(method: .GET, path: "/recipes", query: [ "keyword": "ण࢘", ]) .willRespondWith(status: 200, body: expected) session.run(completionBlock: { isValid in // completeTest࣮ߦޙʹݺΕΔ XCTAssertTrue(isValid) expectation.fulfill() }) { completeTest in // APIϦΫΤετΛૹΔ manager.fetchRecipesFromKeyword("ण࢘") { (recipes, error) in XCTAssertEqual(recipes.count, 2) XCTAssertNil(error) XCTAssertEqual(recipes[0].name, "େτϩ") XCTAssertEqual(recipes[0].description, "ඒຯ͍") XCTAssertEqual(recipes[1].name, "͏ʹ") XCTAssertEqual(recipes[1].description, "ඒຯ͍") completeTest() // Mock ServerʹϨεϙϯε͕ਖ਼͍͜͠ͱΛ௨ } }) waitForExpectationsWithTimeout(3.0) } }