Created
July 2, 2015 20:22
-
-
Save cojoj/de7e4457e5137de6e75f to your computer and use it in GitHub Desktop.
Guard coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Got this method which makes call to API, blah, blah, blah... | |
self.sendRequestWithMethod(.GET, endpoint: .Repositories, params: nil, query: nil, body: nil) { (response, body, error) -> () in | |
guard error == nil else { | |
completion(repositories: nil, error: error) | |
return | |
} | |
guard let repositoriesBody = (body as? NSDictionary)?["results"] as? NSArray else { | |
completion(repositories: nil, error: Error.withInfo("Wrong body \(body)")) | |
return | |
} | |
let repos: [Repository] = XcodeServerArray(repositoriesBody) | |
completion(repositories: repos, error: nil) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given this test case | |
func testGetRepositories() { | |
let expectation = self.expectationWithDescription("Get Repositories") | |
let server = self.getRecordingXcodeServer("get_repositories") | |
server.getRepositories() { (repositories, error) in | |
XCTAssertNil(error, "Error should be nil") | |
XCTAssertNotNil(repositories, "Repositories shouldn't be nil") | |
if let repos = repositories { | |
XCTAssertEqual(repos.count, 2, "There should be two repositories available") | |
for (index, repo) in repos.enumerate() { | |
XCTAssertEqual(repo.name, "Test\(index + 1)") | |
} | |
XCTAssertEqual(repos[0].sshAccess, Repository.SSHAccessType.LoggedInReadWrite) | |
XCTAssertEqual(repos[1].writeAccessExternalIds, [ "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050", "D024C308-CEBE-4E72-BE40-E1E4115F38F9" ]) | |
} | |
expectation.fulfill() | |
} | |
self.waitForExpectationsWithTimeout(10.0, handler: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I run this test case I get code coverage like this:
Which is strange because setting breakpoint at
let repos: [Repository] = XcodeServerArray(repositoriesBody)
executes this breakpoint - so it's executed properly!If I change
guard
style toif
style coverage gets marked correctly: