/
have_received_nothing.go
48 lines (35 loc) · 1.7 KB
/
have_received_nothing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gcounterfeiter
import (
"fmt"
"github.com/tjarratt/gcounterfeiter/invocations"
)
type haveReceivedNothingMatcher struct {
expected invocations.Recorder
functionWasInvokedCount int
}
func (m *haveReceivedNothingMatcher) Match(expected interface{}) (bool, error) {
fake, ok := expected.(invocations.Recorder)
if !ok {
return false, expectedDoesNotImplementInterfaceError(expected)
}
m.expected = fake
return len(fake.Invocations()) != 0, nil
}
func (m *haveReceivedNothingMatcher) FailureMessage(interface{}) string {
return fmt.Sprintf("Expected to have received at least one invocation, but it received %d", invocations.CountTotalInvocations(m.expected.Invocations()))
}
func (m *haveReceivedNothingMatcher) NegatedFailureMessage(interface{}) string {
return fmt.Sprintf("Expected to have received nothing, but there were %d invocations", invocations.CountTotalInvocations(m.expected.Invocations()))
}
func (m *haveReceivedNothingMatcher) With(_ ...interface{}) HaveReceivableMatcher {
return newUserDoneGoofedMatcher(incorrectHaveReceivedAndWithUsageMessage)
}
func (m *haveReceivedNothingMatcher) AndWith(_ ...interface{}) HaveReceivableMatcher {
return newUserDoneGoofedMatcher(incorrectHaveReceivedAndWithUsageMessage)
}
const incorrectHaveReceivedAndWithUsageMessage = `Aww shucks.
You done goofed!
You cannot combine HaveReceived() with argument matching.
HaveReceived() on its own means "a test-double received ... some function".
HaveReceived().With(Equal("something") would mean "a test-double received ... some function?, with the argument 'something'", which is probably not what you wanted.
Perhaps you meant HaveReceived("SomeMethodToTest").With("my-special-argument") ?`