Esempio n. 1
0
func (e *specExecutor) execute() *result.SpecResult {
	specInfo := &gauge_messages.SpecInfo{Name: proto.String(e.specification.Heading.Value),
		FileName: proto.String(e.specification.FileName),
		IsFailed: proto.Bool(false), Tags: getTagValue(e.specification.Tags)}
	e.currentExecutionInfo = &gauge_messages.ExecutionInfo{CurrentSpec: specInfo}
	e.specResult = gauge.NewSpecResult(e.specification)
	resolvedSpecItems := e.resolveItems(e.specification.GetSpecItems())
	e.specResult.AddSpecItems(resolvedSpecItems)
	if _, ok := e.errMap.specErrs[e.specification]; ok {
		return e.getSkippedSpecResult()
	}
	err := e.initSpecDataStore()
	if err != nil {
		return e.createSkippedSpecResult(err)
	}
	if len(e.specification.Scenarios) == 0 {
		return e.createSkippedSpecResult(fmt.Errorf("No scenarios found in spec: %s\n", e.specification.FileName))
	}
	e.consoleReporter.SpecStart(specInfo.GetName())
	beforeSpecHookStatus := e.executeBeforeSpecHook()
	if beforeSpecHookStatus.GetFailed() {
		setSpecFailure(e.currentExecutionInfo)
		handleHookFailure(e.specResult, beforeSpecHookStatus, result.AddPreHook, e.consoleReporter)
	} else {
		dataTableRowCount := e.specification.DataTable.Table.GetRowCount()
		if dataTableRowCount == 0 {
			scenarioResult := e.executeScenarios()
			e.specResult.AddScenarioResults(scenarioResult)
		} else {
			e.executeTableDrivenSpec()
		}
	}

	afterSpecHookStatus := e.executeAfterSpecHook()
	if afterSpecHookStatus.GetFailed() {
		setSpecFailure(e.currentExecutionInfo)
		handleHookFailure(e.specResult, afterSpecHookStatus, result.AddPostHook, e.consoleReporter)
	}
	e.specResult.Skipped = e.specResult.ScenarioSkippedCount > 0
	e.consoleReporter.SpecEnd()
	return e.specResult
}
Esempio n. 2
0
func (e *specExecutor) execute() *result.SpecResult {
	specInfo := &gauge_messages.SpecInfo{Name: proto.String(e.specification.Heading.Value),
		FileName: proto.String(e.specification.FileName),
		IsFailed: proto.Bool(false), Tags: getTagValue(e.specification.Tags)}
	e.currentExecutionInfo = &gauge_messages.ExecutionInfo{CurrentSpec: specInfo}
	e.specResult = gauge.NewSpecResult(e.specification)
	resolvedSpecItems := e.resolveItems(e.specification.GetSpecItems())
	e.specResult.AddSpecItems(resolvedSpecItems)
	if _, ok := e.errMap.SpecErrs[e.specification]; ok {
		e.skipSpec()
		return e.specResult
	}

	res := e.initSpecDataStore()
	if res.GetFailed() {
		e.consoleReporter.Errorf("Failed to initialize spec datastore. Error: %s", res.GetErrorMessage())
		e.skipSpecForError(fmt.Errorf(res.GetErrorMessage()))
		return e.specResult
	}

	if len(e.specification.Scenarios) == 0 {
		e.skipSpecForError(fmt.Errorf("No scenarios found in spec: %s\n", e.specification.FileName))
		return e.specResult
	}

	e.consoleReporter.SpecStart(specInfo.GetName())
	e.notifyBeforeSpecHook()
	if !e.specResult.IsFailed {
		dataTableRowCount := e.specification.DataTable.Table.GetRowCount()
		if dataTableRowCount == 0 {
			scenarioResult := e.executeScenarios()
			e.specResult.AddScenarioResults(scenarioResult)
		} else {
			e.executeTableDrivenSpec()
		}
	}

	e.notifyAfterSpecHook()
	e.specResult.Skipped = e.specResult.ScenarioSkippedCount > 0
	e.consoleReporter.SpecEnd()
	return e.specResult
}