forked from regen-network/gocuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_test.go
71 lines (57 loc) · 1.37 KB
/
custom_test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gocuke_test
import (
"regexp"
"testing"
"github.com/stretchr/testify/require"
"github.com/regen-network/gocuke"
)
func TestCustomSteps(t *testing.T) {
gocuke.NewRunner(t, &customStepsSuite{}).
Path("examples/simple/simple.feature").
Step(`I have (\d+) cukes`, (*customStepsSuite).A).
Step(regexp.MustCompile(`I eat (\d+)`), (*customStepsSuite).B).
Step(`I have (\d+) left`, (*customStepsSuite).C).
Before((*customStepsSuite).before).
After((*customStepsSuite).after).
BeforeStep((*customStepsSuite).beforeStep).
AfterStep((*customStepsSuite).afterStep).
NonParallel().
Run()
require.Equal(t, 2, beforeCalled)
require.Equal(t, 2, afterCalled)
require.Equal(t, 6, beforeStepCalled)
require.Equal(t, 6, afterStepCalled)
}
var (
beforeCalled int
afterCalled int
beforeStepCalled int
afterStepCalled int
)
type customStepsSuite struct {
gocuke.TestingT
cukes int64
}
func (c customStepsSuite) before() {
beforeCalled += 1
}
func (s *customStepsSuite) A(a int64) {
s.cukes = a
}
func (s *customStepsSuite) B(a int64) {
s.cukes -= a
}
func (s *customStepsSuite) C(a int64) {
if a != s.cukes {
s.Fatalf("expected %d cukes, have %d", a, s.cukes)
}
}
func (c customStepsSuite) after() {
afterCalled += 1
}
func (c customStepsSuite) beforeStep() {
beforeStepCalled += 1
}
func (c customStepsSuite) afterStep() {
afterStepCalled += 1
}