52 строки
1,1 КиБ
Go
52 строки
1,1 КиБ
Go
package godog
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/DATA-DOG/godog/colors"
|
|
)
|
|
|
|
func okStep() error {
|
|
return nil
|
|
}
|
|
|
|
func TestPrintsStepDefinitions(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
w := colors.Uncolored(&buf)
|
|
s := &Suite{}
|
|
|
|
steps := []string{
|
|
"^passing step$",
|
|
`^with name "([^"])"`,
|
|
}
|
|
|
|
for _, step := range steps {
|
|
s.Step(step, okStep)
|
|
}
|
|
s.printStepDefinitions(w)
|
|
|
|
out := buf.String()
|
|
ref := `github.com/DATA-DOG/godog.okStep`
|
|
for i, def := range strings.Split(strings.TrimSpace(out), "\n") {
|
|
if idx := strings.Index(def, steps[i]); idx == -1 {
|
|
t.Fatalf(`step "%s" was not found in output`, steps[i])
|
|
}
|
|
if idx := strings.Index(def, ref); idx == -1 {
|
|
t.Fatalf(`step definition reference "%s" was not found in output: "%s"`, ref, def)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPrintsNoStepDefinitionsIfNoneFound(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
w := colors.Uncolored(&buf)
|
|
s := &Suite{}
|
|
s.printStepDefinitions(w)
|
|
|
|
out := strings.TrimSpace(buf.String())
|
|
if out != "there were no contexts registered, could not find any step definition.." {
|
|
t.Fatalf("expected output does not match to: %s", out)
|
|
}
|
|
}
|