/
when_test.go
52 lines (42 loc) · 1.06 KB
/
when_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
package examples
import (
"strings"
"testing"
)
func TestWhenWithTwoExamples(t *testing.T) {
h := harness()
When("writing a test library", h,
It("helps to write tests", func(expect Expectation) {
expect("foo").ToContain("bar")
}),
It("helps to test thoroughly", func(expect Expectation) {
expect("baz").ToEqual("eggs")
}),
)
if !h.Failed {
t.Fail()
} else if !strings.Contains(h.Messages[0], "When writing a test library it helps to write tests") {
t.Fail()
} else if !strings.Contains(h.Messages[1], "When writing a test library it helps to test thoroughly") {
t.Fail()
}
}
func TestKeepGoingWhenAnExampleFails(t *testing.T) {
h := harness()
When("writing a test library", h,
It("helps to write tests", func(expect Expectation) {
expect(true).ToBeTrue()
}),
It("helps to test thoroughly", func(expect Expectation) {
expect("baz").ToEqual("eggs")
}),
It("helps to be great at writing tests", func(expect Expectation) {
expect(1).ToEqual(1)
}),
)
if !h.Failed {
t.Fail()
} else if len(h.Messages) != 1 {
t.Fail()
}
}