...
1
2
3 package matchers
4
5 import (
6 "fmt"
7
8 "github.com/onsi/gomega/format"
9 )
10
11 type HaveOccurredMatcher struct {
12 }
13
14 func (matcher *HaveOccurredMatcher) Match(actual interface{}) (success bool, err error) {
15
16 if actual == nil {
17 return false, nil
18 }
19
20
21 if !isError(actual) {
22 return false, fmt.Errorf("Expected an error-type. Got:\n%s", format.Object(actual, 1))
23 }
24
25
26 return !isNil(actual), nil
27 }
28
29 func (matcher *HaveOccurredMatcher) FailureMessage(actual interface{}) (message string) {
30 return fmt.Sprintf("Expected an error to have occurred. Got:\n%s", format.Object(actual, 1))
31 }
32
33 func (matcher *HaveOccurredMatcher) NegatedFailureMessage(actual interface{}) (message string) {
34 return fmt.Sprintf("Unexpected error:\n%s\n%s", format.Object(actual, 1), "occurred")
35 }
36
View as plain text