Created
January 28, 2015 21:39
-
-
Save Pretz/1240f07b0edf06d87121 to your computer and use it in GitHub Desktop.
strongly typed mock model constructor for Swift tests
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
struct MockFile<T> { | |
let fileName: String | |
init(_ fileName: String) { | |
self.fileName = fileName | |
} | |
} | |
struct Mocks { | |
static let UserWithProfile = MockFile<User>("registrations_mock") | |
static let Locations = MockFile<[Location]>("locations_mock") | |
} | |
func model<T: Model>(file: MockFile<T>) -> T { | |
return T.self(fromResponseBody: jsonMock(file.fileName)) | |
} | |
func models<T: Model>(file: MockFile<[T]>) -> [T] { | |
return T.modelsFromResponseBody(jsonMock(file.fileName)) as [T] | |
} | |
//// | |
let user = model(Mocks.UserWithProfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment