Created
June 7, 2017 09:01
-
-
Save fuxx/d9073abe1e7453edf350e6265937dfd2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// MARK: - Expectations | |
extension XCTestCase { | |
enum Expectation: String { | |
case Exists = "exists == 1" | |
case NotExists = "exists == 0" | |
case Hittable = "hittable == 1" | |
case NotHittable = "hittable == 0" | |
func predicate() -> NSPredicate { | |
return NSPredicate(format: self.rawValue, argumentArray: nil) | |
} | |
} | |
/** | |
Short hand version to check if an element exists. Returns the check object. | |
- parameter expectation: An expectation which should match | |
- parameter object: Object to perform check on | |
- parameter timeout: How long we query until timeout | |
- parameter expectHandler: called if expectation matches | |
- parameter waitHandler: called if waiting is completed | |
- returns: Original object passed as object to to check | |
*/ | |
func expect<T: AnyObject>(_ expectation: Expectation, object: T, timeout: TimeInterval, expectHandler: XCPredicateExpectationHandler? = nil, waitHandler: XCWaitCompletionHandler? = nil) -> T { | |
self.expectation(for: expectation.predicate(), evaluatedWith: object, handler: expectHandler) | |
self.waitForExpectations(timeout: timeout, handler: waitHandler) | |
return object | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment