From 2f4206a8e6e98dc27fd0129502d8f4ce2120f858 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Mon, 29 Aug 2016 13:31:32 +0100 Subject: [PATCH] updates --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 11bad0d..af44eba 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ go install github.com/matryer/moq Mocking interfaces is a nice way to write unit tests where you can easily control the behaviour of the mocked object. -Moq creates a struct that has a function field for each method, which you can declare in your test code: +Moq creates a struct that has a function field for each method, which you can declare in your test code. + +This this example, Moq generated the `EmailSenderMock` type: ```go func TestCompleteSignup(t *testing.T) { @@ -28,7 +30,7 @@ func TestCompleteSignup(t *testing.T) { called := false var sentTo string - mockedEmailSender = &SenderMock{ + mockedEmailSender = &EmailSenderMock{ SendFunc: func(to, subject, body string) error { called = true sentTo = to @@ -46,6 +48,10 @@ func TestCompleteSignup(t *testing.T) { } } + +func CompleteSignUp(to string, sender EmailSender) { + // TODO: this +} ``` The mocked structure implements the interface, where each method calls the associated function field. \ No newline at end of file