CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

AlamofireMock 1.0.0

AlamofireMock 1.0.0

Maintained by Doug Mason.



 
Depends on:
Alamofire~> 4.9.0
SwiftyJSON~> 5.0.0
AlamofireExtended~> 1.0.5
 

  • By
  • Doug Mason

AlamofireMock

Allows for easy mocking without having to resort to using a custom URLProtocol. Using a custom URLProtocol subclass is easier but also involves async operations when testing.

Example of usage

import XCTest
import AlamofireMock

class MyTest: XCTestCase
{
    func testThingReturnsData()
    {
        let rawJson = "[{ \"group\":\"Research and Development\", \"name\":\"Engineering\" }]".data(using: .utf8)
        let manager = SessionManagerMock(responseStore: DefaultResponseStore(data: rawJson))
        let sut = SomeAPI(manager: manager)
        
        let expection = XCTestExpectation(description: "Expecting items to be retrieved.")
        sut.fetchDepartments { items in
            XCTAssertEqual(items, 1)
            XCTAssertEqual(items[0].group, "Research and Development")
            XCTAssertEqual(items[0].name, "Engineering")
            expection.fulfill()
        }
        
        // don't really need since all closure's are synchronous
        wait(for: [expection], timeout: 1)
    }
}