-
Notifications
You must be signed in to change notification settings - Fork 2
/
gomuti_dsl_test.go
63 lines (52 loc) · 1.2 KB
/
gomuti_dsl_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
package gomuti_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/xeger/gomuti"
"github.com/xeger/gomuti/types"
)
type good struct {
Mock types.Mock
}
type bad struct {
mock types.Mock
}
var _ = Describe("Allow", func() {
It("has an RSpec-like DSL", func() {
double := good{Mock: types.Mock{}}
Allow(double).ToReceive("Foo", 2)
})
It("has a Gomega-like DSL", func() {
double := good{Mock: types.Mock{}}
Â(double).Call("Foo").With(1)
Â(double, "Foo", 2)
})
It("accepts Mock", func() {
double := types.Mock{}
Â(double, "Foo", 1)
})
It("accepts struct with an initialized Mock field", func() {
double := good{Mock: types.Mock{}}
Â(double, "Foo", 2)
})
It("accepts pointer-to-struct with a nil Mock field", func() {
double := &good{}
Allow(double).ToReceive("Foo", 2)
Expect(double.Mock).NotTo(BeNil())
})
It("panics when it cannot initialize a Mock", func() {
Expect(func() {
var double *types.Mock
Â(double, "Foo", 1)
}).To(Panic())
Expect(func() {
double := good{}
Â(double, "Foo", 1)
Expect(double).NotTo(BeNil())
}).To(Panic())
Expect(func() {
var double types.Mock
Â(double, "Foo", 1)
}).To(Panic())
})
})