Mockingdrive
September 22, 2015 ยท View on GitHub
Framework for stubbing Hypermedia HTTP requests. Making use of Mockingjay and the Swift Representor.
Usage
Mockingdrive can be used to stub any requests matching a Mockingjay matcher by a Representor. Here's an example of using the Representor builder pattern:
stubRepresentor(uri("/questions")) {
\$0.addTransition("next", uri: "/questions?page=2")
\$0.addAttribute("count", value: 22)
}
You can also pass in directory a representor structure:
stub(everything, representor)
Full example using the Hyperdrive Hypermedia client.
class QuestionTests : XCTestCase {
let hyperdrive = Hyperdrive()
func testQuestions() {
// Stub /questions using the Representor builder pattern
stubRepresentor(uri("/questions")) {
\$0.addTransition("next", uri:"/questions?page=2")
\$0.addAttribute("count", value: 22)
}
// Use an XCTest expectation, so our tests wait for the request to finish
let expectation = expectationWithDescription("Mockingdrive")
// Perform request (using Hyperdrive, you can use other networking libraries)
hyperdrive.enter("https://polls.apiblueprint.org/questions") { result in
switch result {
case .Success(let representor):
// Assert we have a transition for using the "next" relation
XCTAssertNotNil(representor.transitions["next"])
expectation.fulfill()
case .Failure:
XCTFail("Unexpected Failure")
}
}
waitForExpectationsWithTimeout(1.0, handler: nil)
}
}
Installation
CocoaPods is the recommended way to add Mockingdrive to your project.
pod 'Mockingdrive'
License
Mockingdrive is released under the MIT license. See LICENSE.