Skip to content

Instantly share code, notes, and snippets.

@andru255
Created July 25, 2018 16:24
Show Gist options
  • Save andru255/8e16de158831dfa6e79919ecfe75b94c to your computer and use it in GitHub Desktop.
Save andru255/8e16de158831dfa6e79919ecfe75b94c to your computer and use it in GitHub Desktop.
class MockUserActions: UserActionProtocol {
private var totalLogin: Int = 0
private var totalRegister: Int = 0
func login(nick: String, password: String) {
self.totalLogin += 1
}
func register(email: String, nick: String, password: String) {
self.totalRegister += 1
}
// Lo que un mock debe cumplir, contar las veces que fué invocado un método
func getTotalLogins() -> Int {
return totalLogin
}
func getTotalRegister() -> Int {
return totalRegister
}
}
//Haciendo uso de nuestra clase mock
let mock = MockUserActions()
mock.login(nick: "foo", password: "bar")
mock.login(nick: "foo2", password: "bar2")
mock.register(email: "foo", nick: "foo", password: "bar")
print("total Login:", mock.getTotalLogins()) // nos retornará que usamos el método login 2 veces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment