Этот коммит содержится в:
Fredrik Lönnblad 2020-03-10 09:39:59 -03:00
родитель 0ab3e09327
коммит f045623fcf
2 изменённых файлов: 15 добавлений и 15 удалений

Просмотреть файл

@ -312,14 +312,14 @@ func (f *pretty) printStep(result *stepResult) {
} }
scenarioHeaderLength, maxLength := f.scenarioLengths(result.owner.AstNodeIds[0]) scenarioHeaderLength, maxLength := f.scenarioLengths(result.owner.AstNodeIds[0])
stepLength := f.lengthPickleStep(astStep.Keyword, astStep.Text) stepLength := f.lengthPickleStep(astStep.Keyword, result.step.Text)
firstExecutedScenarioStep := len(f.lastFeature().lastPickleResult().stepResults) == backgroundSteps+1 firstExecutedScenarioStep := len(f.lastFeature().lastPickleResult().stepResults) == backgroundSteps+1
if !astBackgroundStep && firstExecutedScenarioStep { if !astBackgroundStep && firstExecutedScenarioStep {
f.printScenarioHeader(astScenario, maxLength-scenarioHeaderLength) f.printScenarioHeader(astScenario, maxLength-scenarioHeaderLength)
} }
text := s(f.indent*2) + result.status.clr()(strings.TrimSpace(astStep.Keyword)) + " " + result.status.clr()(astStep.Text) text := s(f.indent*2) + result.status.clr()(strings.TrimSpace(astStep.Keyword)) + " " + result.status.clr()(result.step.Text)
if result.def != nil { if result.def != nil {
text += s(maxLength - stepLength + 1) text += s(maxLength - stepLength + 1)
text += blackb("# " + result.def.definitionID()) text += blackb("# " + result.def.definitionID())

Просмотреть файл

@ -107,31 +107,31 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite))
s.BeforeStep(c.inject) s.BeforeStep(c.inject)
} }
func (s *suiteContext) inject(step *gherkin.Step) {
func (s *suiteContext) inject(step *messages.Pickle_PickleStep) {
if !s.allowInjection { if !s.allowInjection {
return return
} }
step.Text = injectAll(step.Text) step.Text = injectAll(step.Text)
args := step.Argument
if args != nil { if table := step.Argument.GetDataTable(); table != nil {
switch arg := args.(type) { for i := 0; i < len(table.Rows); i++ {
case *gherkin.DataTable: for n, cell := range table.Rows[i].Cells {
for i := 0; i < len(arg.Rows); i++ { table.Rows[i].Cells[n].Value = injectAll(cell.Value)
for n, cell := range arg.Rows[i].Cells {
arg.Rows[i].Cells[n].Value = injectAll(cell.Value)
} }
} }
case *gherkin.DocString:
arg.Content = injectAll(arg.Content)
} }
if doc := step.Argument.GetDocString(); doc != nil {
doc.Content = injectAll(doc.Content)
} }
} }
func injectAll(inTo string) string { func injectAll(src string) string {
re := regexp.MustCompile(`{{[^{}]+}}`) re := regexp.MustCompile(`{{[^{}]+}}`)
return re.ReplaceAllStringFunc( return re.ReplaceAllStringFunc(
inTo, src,
func(key string) string { func(key string) string {
injectRegex := regexp.MustCompile(`^{{.+}}$`) injectRegex := regexp.MustCompile(`^{{.+}}$`)
if injectRegex.MatchString(key) { if injectRegex.MatchString(key) {