forked from luontola/gospec
-
Notifications
You must be signed in to change notification settings - Fork 1
/
expectations_test.go
77 lines (66 loc) · 2.04 KB
/
expectations_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
72
73
74
75
76
77
// Copyright © 2009-2011 Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0
package gospec
import (
"github.com/orfjackal/nanospec.go/src/nanospec"
)
func ExpectationsSpec(c nanospec.Context) {
c.Specify("When a spec has passing expectations or assumptions", func() {
results := runSpec(func(c Context) {
c.Expect(1, Equals, 1)
c.Assume(1, Equals, 1)
c.Specify("Child", func() {})
})
c.Specify("then the spec passes", func() {
c.Expect(results.FailCount()).Equals(0)
})
c.Specify("then its children are executed", func() {
c.Expect(results.TotalCount()).Equals(2)
})
})
c.Specify("When a spec has failing expectations", func() {
results := runSpec(func(c Context) {
c.Expect(1, Equals, 2)
c.Specify("Child", func() {})
})
c.Specify("then the spec fails", func() {
c.Expect(results.FailCount()).Equals(1)
})
c.Specify("then its children are executed", func() {
c.Expect(results.TotalCount()).Equals(2)
})
})
c.Specify("When a spec has failing assumptions", func() {
results := runSpec(func(c Context) {
c.Assume(1, Equals, 2)
c.Specify("Child", func() {})
})
c.Specify("then the spec fails", func() {
c.Expect(results.FailCount()).Equals(1)
})
c.Specify("then its children are NOT executed", func() {
c.Expect(results.TotalCount()).Equals(1)
})
})
c.Specify("The location of a failed expectation is reported", func() {
results := runSpec(func(c Context) {
c.Expect(1, Equals, 2)
})
c.Expect(fileOfError(results)).Equals("expectations_test.go")
})
c.Specify("The location of a failed assumption is reported", func() {
results := runSpec(func(c Context) {
c.Assume(1, Equals, 2)
})
c.Expect(fileOfError(results)).Equals("expectations_test.go")
})
}
func fileOfError(results *ResultCollector) string {
file := ""
for spec := range results.sortedRoots() {
error := spec.errors.Front().Value.(*Error)
file = error.StackTrace[0].FileName()
}
return file
}