Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Last active March 23, 2017 16:01
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 Thomvis/805c1285115a1a259bfd1b1115a0086e to your computer and use it in GitHub Desktop.
Save Thomvis/805c1285115a1a259bfd1b1115a0086e to your computer and use it in GitHub Desktop.
import Mimus
{% for type in types.protocols %}
{% if type.annotations.genMock %}
class {{ type.name }}Mock: {{ type.name }}, Mock {
var storage: [RecordedCall] = []
{% for method in type.allMethods %}
func {{ method.name }} {
{% if method.parameters.count == 0 %}
recordCall(withIdentifier: "{{ method.selectorName }}")
{% else %}
recordCall(withIdentifier: "{{ method.selectorName }}", arguments: [{% for p in method.parameters %}{{ p.name }}{% if not forloop.last %}, {% endif %}{% endfor %}])
{% endif %}
}
{% endfor %}
}
{% endif %}
{% endfor %}
@Thomvis
Copy link
Author

Thomvis commented Mar 23, 2017

This generates

class AuthenticationManagerMock: AuthenticationManager, Mock {

    var storage: [RecordedCall] = []

    func setup() {
        recordCall(withIdentifier: "setup()")
    }

    func beginAuthentication(with email: String, password: String, options: [String: Any]) {
        recordCall(withIdentifier: "beginAuthentication(with:password:options:)", arguments: [email, password, options])
    }


}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment