...
1 package internal
2
3 import (
4 "strings"
5 "time"
6
7 "github.com/onsi/ginkgo/v2/types"
8 )
9
10 type Spec struct {
11 Nodes Nodes
12 Skip bool
13 }
14
15 func (s Spec) SubjectID() uint {
16 return s.Nodes.FirstNodeWithType(types.NodeTypeIt).ID
17 }
18
19 func (s Spec) Text() string {
20 texts := []string{}
21 for i := range s.Nodes {
22 if s.Nodes[i].Text != "" {
23 texts = append(texts, s.Nodes[i].Text)
24 }
25 }
26 return strings.Join(texts, " ")
27 }
28
29 func (s Spec) FirstNodeWithType(nodeTypes types.NodeType) Node {
30 return s.Nodes.FirstNodeWithType(nodeTypes)
31 }
32
33 func (s Spec) FlakeAttempts() int {
34 flakeAttempts := 0
35 for i := range s.Nodes {
36 if s.Nodes[i].FlakeAttempts > 0 {
37 flakeAttempts = s.Nodes[i].FlakeAttempts
38 }
39 }
40
41 return flakeAttempts
42 }
43
44 func (s Spec) MustPassRepeatedly() int {
45 mustPassRepeatedly := 0
46 for i := range s.Nodes {
47 if s.Nodes[i].MustPassRepeatedly > 0 {
48 mustPassRepeatedly = s.Nodes[i].MustPassRepeatedly
49 }
50 }
51
52 return mustPassRepeatedly
53 }
54
55 func (s Spec) SpecTimeout() time.Duration {
56 return s.FirstNodeWithType(types.NodeTypeIt).SpecTimeout
57 }
58
59 type Specs []Spec
60
61 func (s Specs) HasAnySpecsMarkedPending() bool {
62 for i := range s {
63 if s[i].Nodes.HasNodeMarkedPending() {
64 return true
65 }
66 }
67
68 return false
69 }
70
71 func (s Specs) CountWithoutSkip() int {
72 n := 0
73 for i := range s {
74 if !s[i].Skip {
75 n += 1
76 }
77 }
78 return n
79 }
80
81 func (s Specs) AtIndices(indices SpecIndices) Specs {
82 out := make(Specs, len(indices))
83 for i, idx := range indices {
84 out[i] = s[idx]
85 }
86 return out
87 }
88
View as plain text