forked from r7kamura/gospel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsl.go
57 lines (49 loc) · 1.24 KB
/
dsl.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
49
50
51
52
53
54
55
56
57
package gospel
import "testing"
var (
currentExampleGroup *ExampleGroup
currentExample *Example
previousExample *Example
)
func Describe(t *testing.T, description string, callback func()) {
currentExampleGroup = &ExampleGroup{
T: t,
Description: description,
BeforeFilters: []func(){},
}
callback()
currentExampleGroup.PrintResult()
currentExampleGroup = nil
}
func Context(description string, callback func()) {
currentExampleGroup = &ExampleGroup{
Description: description,
Parent: currentExampleGroup,
BeforeFilters: []func(){},
}
callback()
currentExampleGroup = currentExampleGroup.Parent
}
func It(message string, evaluator func()) {
currentExampleGroup.RunBeforeFilters()
currentExample = &Example{
ExampleGroup: currentExampleGroup,
Message: message,
Evaluator: evaluator,
Formatter: newFormatter(),
}
currentExample.Run()
currentExampleGroup.RunAfterFilters()
}
func Before(filter func()) {
currentExampleGroup.BeforeFilters = append(currentExampleGroup.BeforeFilters, filter)
}
func After(filter func()) {
currentExampleGroup.AfterFilters = append(currentExampleGroup.AfterFilters, filter)
}
func Expect(actual interface{}) *Expectation {
return &Expectation{
Actual: actual,
Example: currentExample,
}
}