forked from r7kamura/gospel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.go
More file actions
59 lines (49 loc) · 1.35 KB
/
example.go
File metadata and controls
59 lines (49 loc) · 1.35 KB
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
49
50
51
52
53
54
55
56
57
58
package gospel
import "strings"
// func It() creates a new Example object.
type Example struct {
*ExampleGroup
Message string
Evaluator func()
HasFailure bool
Formatter
}
// func It() calls this function to run the newly created example.
func (example *Example) Run() {
example.Started()
example.Evaluate()
if !example.HasFailure {
example.Succeeded()
}
previousExample = example
}
// Invokes its Evaluator function.
func (example *Example) Evaluate() {
example.Evaluator()
}
// Called when started.
func (example *Example) Started() {
example.Formatter.Started(example)
}
// Called when all of expectations passed.
func (example *Example) Succeeded() {
example.Formatter.Succeeded(example)
}
// Called when any of expectations failed.
func (example *Example) Failed(message string) {
example.Root().T.Fail()
example.HasFailure = true
example.Formatter.Failed(example, message)
}
// Returns its entire descriptions + message as a string.
func (example *Example) FullDescription() string {
return strings.Join(append(example.Descriptions(), example.Message), " ")
}
// Returns its ExamplesGroups' descriptions as an array of string.
func (example *Example) Descriptions() []string {
segments := []string{}
for _, ancestor := range example.ExampleGroup.ReverseAncestorsAndSelf() {
segments = append(segments, ancestor.Description)
}
return segments
}