Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions extensions/table/table_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ func (t TableEntry) generateIt(itBody reflect.Value) {
return
}

values := []reflect.Value{}
values := make([]reflect.Value, 0)
itBodyType := itBody.Type()

for i, param := range t.Parameters {
var value reflect.Value

if param == nil {
inType := itBody.Type().In(i)
inType := itBodyType.In(i)
value = reflect.Zero(inType)
} else {
value = reflect.ValueOf(param)
Expand All @@ -36,14 +38,34 @@ func (t TableEntry) generateIt(itBody reflect.Value) {
values = append(values, value)
}

body := func() {
itBody.Call(values)
var (
body interface{}
timeout []float64
)

if itBodyType.NumIn() >= 1 && itBodyType.In(0).Kind() == reflect.Chan &&
itBodyType.In(0).Elem().Kind() == reflect.Interface {

lenValues := len(values)
if lenValues > 0 && values[lenValues-1].Kind() == reflect.Float64 {
timeout = append(timeout, values[lenValues-1].Interface().(float64))
values = values[:lenValues-1]
}

body = func(done chan<- interface{}) {
values = append([]reflect.Value{reflect.ValueOf(done)}, values...)
itBody.Call(values)
}
} else {
body = func() {
itBody.Call(values)
}
}

if t.Focused {
ginkgo.FIt(t.Description, body)
ginkgo.FIt(t.Description, body, timeout...)
} else {
ginkgo.It(t.Description, body)
ginkgo.It(t.Description, body, timeout...)
}
}

Expand Down
20 changes: 19 additions & 1 deletion extensions/table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package table_test
import (
"strings"

. "github.com/onsi/ginkgo/extensions/table"
. "github.com/Antonov-guap/ginkgo/extensions/table"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"time"
)

var _ = Describe("Table", func() {
Expand All @@ -19,6 +20,23 @@ var _ = Describe("Table", func() {
Entry("x < y", 0, 1, false),
)

DescribeTable("a simple table with async flow",
func(done Done, msg string, after time.Duration) { //use done Done in params to make async flow
c := make(chan string, 0)

go func(c chan string) {
time.Sleep(after)
c <- "Hello, " + msg
}(c)

Expect(<-c).To(ContainSubstring(msg))

close(done)
},
Entry("Sam", "Sam", 100*time.Millisecond), //default timeout 1 sec + 100ms latency
Entry("John", "John", 1050*time.Millisecond, 1.2), //set timeout 1.2 sec (last param) + 1050ms latency
)

type ComplicatedThings struct {
Superstructure string
Substructure string
Expand Down