Skip to content

Instantly share code, notes, and snippets.

@polac24
Created March 31, 2019 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polac24/63d658ce0b460504de95610f4b1e257d to your computer and use it in GitHub Desktop.
Save polac24/63d658ce0b460504de95610f4b1e257d to your computer and use it in GitHub Desktop.
func stub<I,O>(of: (I) throws -> (O)) -> (I) throws -> (O){
return nil!
}
func niceStub<I,O>(of: (I) throws -> (O), thatReturns: O) -> (I) throws -> (O){
return { _ in thatReturns }
}
func niceStub<I,O,E:Error>(of: (I) throws -> (O), thatThrows error: E) -> (I) throws -> (O){
return { _ in throw error }
}
func niceStub<I,O: DefaultProvidable>(of: (I) throws -> (O)) -> (I) throws -> (O){
return { _ in O.defaultValue }
}
func spyCalls<I,O>(of stub: inout (I) throws -> (O)) -> (ArgRecords<I>) {
.... // copy&paste implementation of spyCalls
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment