github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/spec.go (about)

     1  package internal
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/onsi/ginkgo/types"
     7  )
     8  
     9  type Spec struct {
    10  	Nodes Nodes
    11  	Skip  bool
    12  }
    13  
    14  func (s Spec) Text() string {
    15  	texts := []string{}
    16  	for i := range s.Nodes {
    17  		if s.Nodes[i].Text != "" {
    18  			texts = append(texts, s.Nodes[i].Text)
    19  		}
    20  	}
    21  	return strings.Join(texts, " ")
    22  }
    23  
    24  func (s Spec) FirstNodeWithType(nodeTypes types.NodeType) Node {
    25  	return s.Nodes.FirstNodeWithType(nodeTypes)
    26  }
    27  
    28  func (s Spec) FlakeAttempts() int {
    29  	flakeAttempts := 0
    30  	for i := range s.Nodes {
    31  		if s.Nodes[i].FlakeAttempts > 0 {
    32  			flakeAttempts = s.Nodes[i].FlakeAttempts
    33  		}
    34  	}
    35  
    36  	return flakeAttempts
    37  }
    38  
    39  type Specs []Spec
    40  
    41  func (s Specs) HasAnySpecsMarkedPending() bool {
    42  	for i := range s {
    43  		if s[i].Nodes.HasNodeMarkedPending() {
    44  			return true
    45  		}
    46  	}
    47  
    48  	return false
    49  }
    50  
    51  func (s Specs) CountWithoutSkip() int {
    52  	n := 0
    53  	for i := range s {
    54  		if !s[i].Skip {
    55  			n += 1
    56  		}
    57  	}
    58  	return n
    59  }
    60  
    61  func (s Specs) AtIndices(indices SpecIndices) Specs {
    62  	out := make(Specs, len(indices))
    63  	for i, idx := range indices {
    64  		out[i] = s[idx]
    65  	}
    66  	return out
    67  }