Example #1
0
func (s *MySuite) TestToFilterSpecsByWrongTagExpression(c *C) {
	myTags := []string{"tag1", "tag2"}
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading1", LineNo: 1},
		&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 2},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 3},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 4},
	}
	spec1, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	c.Assert(result.Ok, Equals, true)

	tokens1 := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading2", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 3},
	}
	spec2, result := new(parser.SpecParser).CreateSpecification(tokens1, gauge.NewConceptDictionary())
	c.Assert(result.Ok, Equals, true)

	var specs []*gauge.Specification
	specs = append(specs, spec1)
	specs = append(specs, spec2)

	c.Assert(specs[0].Tags.Values[0], Equals, myTags[0])
	c.Assert(specs[0].Tags.Values[1], Equals, myTags[1])
	specs = filterSpecsByTags(specs, "(tag1 & tag2")
	c.Assert(len(specs), Equals, 0)
}
Example #2
0
func (s *MySuite) TestRefactoringGivesOnlyThoseConceptFilesWhichAreRefactored(c *C) {
	oldStep := "first step"
	newStep := "second step"
	unchanged := "unchanged"
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},
	}
	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	agent, _ := getRefactorAgent(oldStep, newStep, nil)
	specs := append(make([]*gauge.Specification, 0), spec)
	dictionary := gauge.NewConceptDictionary()
	step1 := &gauge.Step{Value: oldStep + "sdsf", IsConcept: true}
	step2 := &gauge.Step{Value: unchanged, IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: newStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}
	step3 := &gauge.Step{Value: "Concept value", IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: oldStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}
	fileName := "file.cpt"
	dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: fileName}
	dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: fileName}
	dictionary.ConceptsMap[step3.Value] = &gauge.Concept{ConceptStep: step3, FileName: "e" + fileName}

	_, filesRefactored := agent.rephraseInSpecsAndConcepts(&specs, dictionary)

	c.Assert(filesRefactored[fileName], Equals, false)
	c.Assert(filesRefactored["e"+fileName], Equals, true)
}
Example #3
0
func (s *MySuite) TestToEvaluateTagExpression(c *C) {
	myTags := []string{"tag1", "tag2"}
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading1", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 01", LineNo: 2},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1"}, LineNo: 3},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 02", LineNo: 4},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3"}, LineNo: 5},
	}
	spec1, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	c.Assert(result.Ok, Equals, true)

	tokens1 := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading2", LineNo: 1},
		&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 2},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 3},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 4},
	}
	spec2, result := new(parser.SpecParser).CreateSpecification(tokens1, gauge.NewConceptDictionary())
	c.Assert(result.Ok, Equals, true)

	var specs []*gauge.Specification
	specs = append(specs, spec1)
	specs = append(specs, spec2)

	specs = filterSpecsByTags(specs, "tag1 & !(tag1 & tag4) & (tag2 | tag3)")
	c.Assert(len(specs), Equals, 1)
	c.Assert(len(specs[0].Scenarios), Equals, 2)
	c.Assert(specs[0].Scenarios[0].Heading.Value, Equals, "Scenario Heading 1")
	c.Assert(specs[0].Scenarios[1].Heading.Value, Equals, "Scenario Heading 2")
}
Example #4
0
func (s *MySuite) TestRefactoringOfStepsWithNoArgsAndWithMoreThanOneSpec(c *C) {
	oldStep := " first step"
	newStep := "second step"
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
		&parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},
	}
	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	tokens = []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 10},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 20},
		&parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 30},
	}
	spec1, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	specs := append(make([]*gauge.Specification, 0), spec)
	specs = append(specs, spec1)
	agent, err := getRefactorAgent(oldStep, newStep, nil)
	specRefactored, _ := agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())

	for _, isRefactored := range specRefactored {
		c.Assert(true, Equals, isRefactored)
	}
	c.Assert(err, Equals, nil)
	c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 1)
	c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)

	c.Assert(len(specs[1].Scenarios[0].Steps), Equals, 1)
	c.Assert(specs[1].Scenarios[0].Steps[0].Value, Equals, newStep)
}
Example #5
0
func (s *MySuite) TestFormatSpecificationWithTags(c *C) {
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "My Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 2},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 3},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 4},
		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 5, LineText: "Example step"},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading1", LineNo: 6},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag3", "tag4"}, LineNo: 7},
		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 8, LineText: "Example step"},
	}

	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	formatted := FormatSpecification(spec)
	c.Assert(formatted, Equals,
		`My Spec Heading
===============
tags: tag1, tag2
Scenario Heading
----------------
tags: tag3, tag4
* Example step
Scenario Heading1
-----------------
tags: tag3, tag4
* Example step
`)

}
Example #6
0
func (s *MySuite) TestPopulatingNestedConceptsWithStaticParametersLookup(c *C) {
	parser := new(SpecParser)
	specText := SpecBuilder().specHeading("A spec heading").
		scenarioHeading("First scenario").
		step("create user \"456\" \"foo\" and \"123456\"").
		String()

	conceptDictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt"))
	AddConcepts(path, conceptDictionary)

	spec, _ := parser.Parse(specText, conceptDictionary)
	concept1 := spec.Scenarios[0].Steps[0]

	dataTableLookup := new(gauge.ArgLookup).FromDataTableRow(&spec.DataTable.Table, 0)
	PopulateConceptDynamicParams(concept1, dataTableLookup)

	c.Assert(concept1.GetArg("user-id").Value, Equals, "456")
	c.Assert(concept1.GetArg("user-name").Value, Equals, "foo")
	c.Assert(concept1.GetArg("user-phone").Value, Equals, "123456")

	nestedConcept := concept1.ConceptSteps[0]
	c.Assert(nestedConcept.GetArg("userid").Value, Equals, "456")
	c.Assert(nestedConcept.GetArg("username").Value, Equals, "static-value")
}
Example #7
0
func (s *MySuite) TestCreateSkippedSpecResultWithScenarios(c *C) {
	specText := SpecBuilder().specHeading("A spec heading").
		scenarioHeading("First scenario").
		step("create user \"456\" \"foo\" and \"9900\"").
		String()

	spec, _ := new(parser.SpecParser).Parse(specText, gauge.NewConceptDictionary())
	spec.FileName = "FILE"
	specExecutor := newSpecExecutor(spec, nil, nil, indexRange{start: 0, end: 0}, nil, nil)
	specExecutor.errMap = &validationErrMaps{make(map[*gauge.Specification][]*stepValidationError), make(map[*gauge.Scenario][]*stepValidationError), make(map[*gauge.Step]*stepValidationError)}
	specExecutor.consoleReporter = reporter.Current()
	specExecutor.specResult = &result.SpecResult{ProtoSpec: &gauge_messages.ProtoSpec{}}
	result := specExecutor.createSkippedSpecResult(fmt.Errorf("ERROR"))

	c.Assert(result.IsFailed, Equals, false)
	c.Assert(result.Skipped, Equals, true)

	c.Assert(len(specExecutor.errMap.specErrs[spec]), Equals, 1)
	c.Assert(specExecutor.errMap.specErrs[spec][0].Error(), Equals, "ERROR")
	c.Assert(specExecutor.errMap.specErrs[spec][0].fileName, Equals, "FILE")
	c.Assert(specExecutor.errMap.specErrs[spec][0].step.LineNo, Equals, 1)
	c.Assert(specExecutor.errMap.specErrs[spec][0].step.LineText, Equals, "A spec heading")
	c.Assert(len(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]]), Equals, 1)
	c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].Error(), Equals, "ERROR")
	c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].fileName, Equals, "FILE")
	c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].step.LineNo, Equals, 1)
	c.Assert(specExecutor.errMap.scenarioErrs[spec.Scenarios[0]][0].step.LineText, Equals, "A spec heading")
}
Example #8
0
func (s *MySuite) TestFormatSpecification(c *C) {
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
		&parser.Token{Kind: gauge.StepKind, Value: "Example step", LineNo: 3, LineText: "Example step"},
		&parser.Token{Kind: gauge.StepKind, Value: "Step with inline table", LineNo: 3, LineText: "Step with inline table "},
		&parser.Token{Kind: gauge.TableHeader, Args: []string{"id", "name"}},
		&parser.Token{Kind: gauge.TableRow, Args: []string{"<1>", "foo"}},
		&parser.Token{Kind: gauge.TableRow, Args: []string{"2", "bar"}},
	}

	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())

	formatted := FormatSpecification(spec)

	c.Assert(formatted, Equals,
		`Spec Heading
============
Scenario Heading
----------------
* Example step
* Step with inline table`+" "+`
     |id |name|
     |---|----|
     |<1>|foo |
     |2  |bar |
`)
}
Example #9
0
func (s *MySuite) TestMultiLevelConcept(c *C) {
	conceptDictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "nested_concept2.cpt"))

	AddConcepts(path, conceptDictionary)
	actualTopLevelConcept := conceptDictionary.Search("top level concept")
	c.Assert(len(actualTopLevelConcept.ConceptStep.ConceptSteps), Equals, 2)
	actualNestedConcept := actualTopLevelConcept.ConceptStep.ConceptSteps[0]
	c.Assert(actualNestedConcept.IsConcept, Equals, true)
	c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 2)
	c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "another nested concept")
	c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "normal step 2")
	c.Assert(actualTopLevelConcept.ConceptStep.ConceptSteps[1].Value, Equals, "normal step 1")

	actualAnotherNestedConcept := conceptDictionary.Search("another nested concept")
	c.Assert(len(actualAnotherNestedConcept.ConceptStep.ConceptSteps), Equals, 1)
	step := actualAnotherNestedConcept.ConceptStep.ConceptSteps[0]
	c.Assert(step.IsConcept, Equals, false)
	c.Assert(step.Value, Equals, "normal step 3")

	nestedConcept2 := conceptDictionary.Search("nested concept")
	c.Assert(len(nestedConcept2.ConceptStep.ConceptSteps), Equals, 2)
	actualAnotherNestedConcept2 := nestedConcept2.ConceptStep.ConceptSteps[0]
	c.Assert(actualAnotherNestedConcept2.IsConcept, Equals, true)
	c.Assert(len(actualAnotherNestedConcept2.ConceptSteps), Equals, 1)
	c.Assert(actualAnotherNestedConcept2.ConceptSteps[0].Value, Equals, "normal step 3")
	c.Assert(nestedConcept2.ConceptStep.ConceptSteps[1].Value, Equals, "normal step 2")
}
Example #10
0
func (s *MySuite) TestNestedConceptLooksUpDataTableArgs(c *C) {
	parser := new(SpecParser)
	specText := SpecBuilder().specHeading("A spec heading").
		tableHeader("id", "name", "phone").
		tableHeader("123", "prateek", "8800").
		tableHeader("456", "apoorva", "9800").
		tableHeader("789", "srikanth", "7900").
		scenarioHeading("First scenario").
		step("create user <id> <name>").
		step("another step").String()

	dictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "param_nested_concept.cpt"))

	AddConcepts(path, dictionary)

	tokens, _ := parser.GenerateTokens(specText)
	spec, parseResult := parser.CreateSpecification(tokens, dictionary)

	c.Assert(parseResult.Ok, Equals, true)

	firstStepInSpec := spec.Scenarios[0].Steps[0]
	c.Assert(firstStepInSpec.IsConcept, Equals, true)
	c.Assert(firstStepInSpec.GetArg("bar").ArgType, Equals, gauge.Dynamic)
	c.Assert(firstStepInSpec.GetArg("far").ArgType, Equals, gauge.Dynamic)
	c.Assert(firstStepInSpec.GetArg("bar").Value, Equals, "id")
	c.Assert(firstStepInSpec.GetArg("far").Value, Equals, "name")

	nestedConcept := firstStepInSpec.ConceptSteps[0]
	c.Assert(nestedConcept.GetArg("baz").ArgType, Equals, gauge.Dynamic)
	c.Assert(nestedConcept.GetArg("boo").ArgType, Equals, gauge.Dynamic)
	c.Assert(nestedConcept.GetArg("baz").Value, Equals, "id")
	c.Assert(nestedConcept.GetArg("boo").Value, Equals, "name")

}
Example #11
0
func (s *MySuite) TestConceptDictionaryWithNestedConceptsWithStaticParameters(c *C) {
	conceptDictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "static_param_concept.cpt"))

	AddConcepts(path, conceptDictionary)
	concept := conceptDictionary.Search("create user {} {} and {}")
	c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 2)
	actualNestedConcept := concept.ConceptStep.ConceptSteps[0]
	c.Assert(actualNestedConcept.IsConcept, Equals, true)

	c.Assert(actualNestedConcept.Args[0].ArgType, Equals, gauge.Dynamic)
	c.Assert(actualNestedConcept.Args[0].Value, Equals, "user-id")

	c.Assert(actualNestedConcept.Args[1].ArgType, Equals, gauge.Static)
	c.Assert(actualNestedConcept.Args[1].Value, Equals, "static-value")
	c.Assert(actualNestedConcept.Lookup.GetArg("userid").Value, Equals, "user-id")
	c.Assert(actualNestedConcept.Lookup.GetArg("userid").ArgType, Equals, gauge.Dynamic)
	c.Assert(actualNestedConcept.Lookup.GetArg("username").Value, Equals, "static-value")
	c.Assert(actualNestedConcept.Lookup.GetArg("username").ArgType, Equals, gauge.Static)

	c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 2)
	c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "add id {}")
	c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].ArgType, Equals, gauge.Dynamic)
	c.Assert(actualNestedConcept.ConceptSteps[0].Args[0].Value, Equals, "userid")

	c.Assert(actualNestedConcept.ConceptSteps[1].Value, Equals, "add name {}")
	c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].ArgType, Equals, gauge.Dynamic)
	c.Assert(actualNestedConcept.ConceptSteps[1].Args[0].Value, Equals, "username")
}
Example #12
0
func (s *MySuite) TestToFilterMultipleScenariosByMultipleTags(c *C) {
	myTags := []string{"tag1", "tag2"}
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1"}, LineNo: 3},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 4},
		&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 5},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 3", LineNo: 6},
		&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 7},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 4", LineNo: 8},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"prod", "tag7", "tag1", "tag2"}, LineNo: 9},
	}
	spec, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	c.Assert(result.Ok, Equals, true)

	var specs []*gauge.Specification
	specs = append(specs, spec)

	c.Assert(len(specs[0].Scenarios), Equals, 4)
	c.Assert(len(specs[0].Scenarios[0].Tags.Values), Equals, 1)
	c.Assert(len(specs[0].Scenarios[1].Tags.Values), Equals, 2)
	c.Assert(len(specs[0].Scenarios[2].Tags.Values), Equals, 2)
	c.Assert(len(specs[0].Scenarios[3].Tags.Values), Equals, 4)

	specs = filterSpecsByTags(specs, "tag1 & tag2")
	c.Assert(len(specs[0].Scenarios), Equals, 3)
	c.Assert(specs[0].Scenarios[0].Heading.Value, Equals, "Scenario Heading 2")
	c.Assert(specs[0].Scenarios[1].Heading.Value, Equals, "Scenario Heading 3")
	c.Assert(specs[0].Scenarios[2].Heading.Value, Equals, "Scenario Heading 4")
}
Example #13
0
func (s *SpecInfoGatherer) getParsedSpecs(specFiles []string) []*gauge.Specification {
	if s.conceptDictionary == nil {
		s.conceptDictionary = gauge.NewConceptDictionary()
	}
	parsedSpecs, parseResults := parser.ParseSpecFiles(specFiles, s.conceptDictionary)
	s.handleParseFailures(parseResults)
	return parsedSpecs
}
Example #14
0
func (s *MySuite) TestRenamingWhenNumberOfArgumentsAreSame(c *C) {
	oldStep := "first step {static} and {static}"
	oldStep1 := "first step <a> and <b>"
	newStep := "second step <a> and <b>"
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},
		&parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address"}},
	}
	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	agent, _ := getRefactorAgent(oldStep1, newStep, nil)
	specs := append(make([]*gauge.Specification, 0), spec)
	dictionary := gauge.NewConceptDictionary()
	agent.rephraseInSpecsAndConcepts(&specs, dictionary)
	c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {}")
	c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")
	c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")
}
Example #15
0
func (s *MySuite) TestErrorOnCircularReferenceInConcept(c *C) {
	dictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "circular_concept.cpt"))

	err := AddConcepts(path, dictionary)

	c.Assert(err, NotNil)
	c.Assert(true, Equals, strings.Contains(err.Message, "Circular reference found in concept"))
}
Example #16
0
func (s *MySuite) TestConceptDictionaryAddDuplicateConcept(c *C) {
	dictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "duplicate_concept.cpt"))

	err := AddConcepts(path, dictionary)

	c.Assert(err, NotNil)
	c.Assert(err.Message, Equals, "Duplicate concept definition found")
}
Example #17
0
func (s *MySuite) TestScenarioIndexFilterWithWrongScenarioIndex(c *C) {
	specText := SpecBuilder().specHeading("spec heading").
		scenarioHeading("First scenario").
		step("a step").String()

	spec, parseResult := new(parser.SpecParser).Parse(specText, gauge.NewConceptDictionary())
	c.Assert(parseResult.Ok, Equals, true)

	spec.Filter(newScenarioIndexFilterToRetain(1))
	c.Assert(len(spec.Scenarios), Equals, 0)
}
Example #18
0
func (s *MySuite) TestConceptHavingItemsWithTablesAndComments(c *C) {
	conceptDictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "tabular_concept.cpt"))

	AddConcepts(path, conceptDictionary)

	concept := conceptDictionary.Search("my concept {}")
	c.Assert(len(concept.ConceptStep.Items), Equals, 3)
	c.Assert(len(concept.ConceptStep.PreComments), Equals, 1)
	c.Assert(concept.ConceptStep.PreComments[0].Value, Equals, "COMMENT")
	c.Assert(concept.ConceptStep.Items[2].(*gauge.Comment).Value, Equals, "   comment")
}
Example #19
0
func (s *MySuite) TestConceptDictionaryWithNestedConcepts(c *C) {
	dictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "nested_concept.cpt"))

	AddConcepts(path, dictionary)
	concept := dictionary.Search("test concept step 1")

	c.Assert(len(concept.ConceptStep.ConceptSteps), Equals, 1)

	actualNestedConcept := concept.ConceptStep.ConceptSteps[0]
	c.Assert(actualNestedConcept.IsConcept, Equals, true)
	c.Assert(len(actualNestedConcept.ConceptSteps), Equals, 1)
	c.Assert(actualNestedConcept.ConceptSteps[0].Value, Equals, "step 2")
}
Example #20
0
func (s *MySuite) TestRefactoringOfStepsWithNoArgsInConceptFiles(c *C) {
	oldStep := "first step"
	newStep := "second step"
	unchanged := "unchanged"
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},
	}
	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	agent, _ := getRefactorAgent(oldStep, newStep, nil)
	specs := append(make([]*gauge.Specification, 0), spec)
	dictionary := gauge.NewConceptDictionary()
	step1 := &gauge.Step{Value: oldStep + "sdsf", IsConcept: true}
	step2 := &gauge.Step{Value: unchanged, IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: oldStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}

	dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: "file.cpt"}
	dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: "file.cpt"}

	agent.rephraseInSpecsAndConcepts(&specs, dictionary)

	c.Assert(dictionary.ConceptsMap[unchanged].ConceptStep.Items[0].(*gauge.Step).Value, Equals, newStep)
	c.Assert(dictionary.ConceptsMap[unchanged].ConceptStep.Items[1].(*gauge.Step).Value, Equals, oldStep+"T")
}
Example #21
0
func (s *MySuite) TestRefactoringGivesOnlySpecsThatAreRefactored(c *C) {
	oldStep := " first step"
	newStep := "second step"
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
		&parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},
	}
	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	tokens = []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 10},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 20},
		&parser.Token{Kind: gauge.StepKind, Value: newStep, LineNo: 30},
	}
	spec1, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	specs := append(make([]*gauge.Specification, 0), spec)
	specs = append(specs, spec1)
	agent, _ := getRefactorAgent(oldStep, newStep, nil)
	specRefactored, _ := agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())

	c.Assert(true, Equals, specRefactored[specs[0]])
	c.Assert(false, Equals, specRefactored[specs[1]])
}
Example #22
0
func CreateConceptsDictionary(shouldIgnoreErrors bool) (*gauge.ConceptDictionary, *ParseResult) {
	conceptFiles := util.FindConceptFilesIn(filepath.Join(config.ProjectRoot, common.SpecsDirectoryName))
	conceptsDictionary := gauge.NewConceptDictionary()
	for _, conceptFile := range conceptFiles {
		if err := AddConcepts(conceptFile, conceptsDictionary); err != nil {
			if shouldIgnoreErrors {
				logger.APILog.Error("Concept parse failure: %s %s", conceptFile, err)
				continue
			}
			logger.Error(err.Error())
			return nil, &ParseResult{ParseError: err, FileName: conceptFile}
		}
	}
	return conceptsDictionary, &ParseResult{Ok: true}
}
Example #23
0
func (s *MySuite) TestFormatConcepts(c *C) {
	dictionary := gauge.NewConceptDictionary()
	step1 := &gauge.Step{Value: "sdsf", LineText: "sdsf", IsConcept: true, LineNo: 1, PreComments: []*gauge.Comment{&gauge.Comment{Value: "COMMENT", LineNo: 1}}}
	step2 := &gauge.Step{Value: "dsfdsfdsf", LineText: "dsfdsfdsf", IsConcept: true, LineNo: 2, Items: []gauge.Item{&gauge.Step{Value: "sfd", LineText: "sfd", IsConcept: false}, &gauge.Step{Value: "sdfsdf" + "T", LineText: "sdfsdf" + "T", IsConcept: false}}}

	dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: "file.cpt"}
	dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: "file.cpt"}

	formatted := FormatConcepts(dictionary)
	c.Assert(formatted["file.cpt"], Equals, `COMMENT
# sdsf
# dsfdsfdsf
* sdfsdfT
`)
}
Example #24
0
func (s *MySuite) TestConceptHavingItemsWithComments(c *C) {
	conceptDictionary := gauge.NewConceptDictionary()
	path, _ := filepath.Abs(filepath.Join("testdata", "dynamic_param_concept.cpt"))

	AddConcepts(path, conceptDictionary)
	concept := conceptDictionary.Search("create user {} {} and {}")

	c.Assert(len(concept.ConceptStep.Items), Equals, 3)
	c.Assert(concept.ConceptStep.Items[2].(*gauge.Comment).Value, Equals, "Comments")

	concept = conceptDictionary.Search("assign id {} and name {}")

	c.Assert(len(concept.ConceptStep.Items), Equals, 4)
	c.Assert(concept.ConceptStep.Items[3].(*gauge.Comment).Value, Equals, "Comment1")
}
Example #25
0
func (s *MySuite) TestToCheckTagsInScenarioLevel(c *C) {
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},
		&parser.Token{Kind: gauge.TagKind, Args: []string{"tag1", "tag2"}, LineNo: 3},
	}

	spec, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())

	c.Assert(result.Ok, Equals, true)

	c.Assert(len(spec.Scenarios[0].Tags.Values), Equals, 2)
	c.Assert(spec.Scenarios[0].Tags.Values[0], Equals, "tag1")
	c.Assert(spec.Scenarios[0].Tags.Values[1], Equals, "tag2")
}
Example #26
0
func (s *MySuite) TestConceptDictionaryAdd(c *C) {
	dictionary := gauge.NewConceptDictionary()
	step1Text := "test concept step 1"
	step2Text := "test concept step 2"
	step1 := &gauge.Step{Value: step1Text, LineNo: 1, IsConcept: true, LineText: step1Text}
	step2 := &gauge.Step{Value: step2Text, LineNo: 4, IsConcept: true, LineText: step2Text}
	path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))

	err := AddConcepts(path, dictionary)

	c.Assert(err, IsNil)
	assertStepEqual(c, dictionary.ConceptsMap[step1Text].ConceptStep, step1)
	c.Assert(dictionary.ConceptsMap[step1Text].FileName, Equals, path)
	assertStepEqual(c, dictionary.ConceptsMap[step2Text].ConceptStep, step2)
	c.Assert(dictionary.ConceptsMap[step2Text].FileName, Equals, path)
}
Example #27
0
func CreateConceptsDictionary(shouldIgnoreErrors bool, dirs []string) (*gauge.ConceptDictionary, *ParseResult) {
	var conceptFiles []string
	for _, d := range dirs {
		conceptFiles = append(conceptFiles, util.GetConceptFiles(d)...)
	}

	conceptsDictionary := gauge.NewConceptDictionary()
	for _, conceptFile := range conceptFiles {
		if err := AddConcepts(conceptFile, conceptsDictionary); err != nil {
			if shouldIgnoreErrors {
				logger.APILog.Error("Concept parse failure: %s %s", conceptFile, err)
				continue
			}
			return nil, &ParseResult{ParseError: err, FileName: conceptFile}
		}
	}
	return conceptsDictionary, &ParseResult{Ok: true}
}
Example #28
0
func (s *MySuite) TestScenarioIndexFilterFirstScenario(c *C) {
	specText := SpecBuilder().specHeading("spec heading").
		scenarioHeading("First scenario").
		step("a step").
		scenarioHeading("Second scenario").
		step("second step").
		scenarioHeading("Third scenario").
		step("third user").
		scenarioHeading("Fourth scenario").
		step("Fourth user").String()

	spec, parseResult := new(parser.SpecParser).Parse(specText, gauge.NewConceptDictionary())
	c.Assert(parseResult.Ok, Equals, true)

	spec.Filter(newScenarioIndexFilterToRetain(0))
	c.Assert(len(spec.Scenarios), Equals, 1)
	c.Assert(spec.Scenarios[0].Heading.Value, Equals, "First scenario")

}
Example #29
0
func (s *MySuite) TestResolveNestedConceptToProtoConceptItem(c *C) {
	conceptDictionary := gauge.NewConceptDictionary()

	specText := SpecBuilder().specHeading("A spec heading").
		scenarioHeading("First scenario").
		step("create user \"456\" \"foo\" and \"9900\"").
		String()

	path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))
	parser.AddConcepts(path, conceptDictionary)
	specParser := new(parser.SpecParser)
	spec, _ := specParser.Parse(specText, conceptDictionary)

	specExecutor := newSpecExecutor(spec, nil, nil, indexRange{start: 0, end: 0}, nil, nil)
	specExecutor.errMap = &validationErrMaps{make(map[*gauge.Specification][]*stepValidationError), make(map[*gauge.Scenario][]*stepValidationError), make(map[*gauge.Step]*stepValidationError)}
	protoConcept := specExecutor.resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0]).GetConcept()
	checkConceptParameterValuesInOrder(c, protoConcept, "456", "foo", "9900")

	c.Assert(protoConcept.GetSteps()[0].GetItemType(), Equals, gauge_messages.ProtoItem_Concept)

	nestedConcept := protoConcept.GetSteps()[0].GetConcept()
	checkConceptParameterValuesInOrder(c, nestedConcept, "456", "foo")

	firstNestedStep := nestedConcept.GetSteps()[0].GetStep()
	params := getParameters(firstNestedStep.GetFragments())
	c.Assert(1, Equals, len(params))
	c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)
	c.Assert(params[0].GetValue(), Equals, "456")

	secondNestedStep := nestedConcept.GetSteps()[1].GetStep()
	params = getParameters(secondNestedStep.GetFragments())
	c.Assert(1, Equals, len(params))
	c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)
	c.Assert(params[0].GetValue(), Equals, "foo")

	c.Assert(protoConcept.GetSteps()[1].GetItemType(), Equals, gauge_messages.ProtoItem_Step)
	secondStepInConcept := protoConcept.GetSteps()[1].GetStep()
	params = getParameters(secondStepInConcept.GetFragments())
	c.Assert(1, Equals, len(params))
	c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)
	c.Assert(params[0].GetValue(), Equals, "9900")

}
Example #30
0
func (s *MySuite) TestToFilterScenariosByUnavailableTags(c *C) {
	myTags := []string{"tag1", "tag2"}
	tokens := []*parser.Token{
		&parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 2", LineNo: 4},
		&parser.Token{Kind: gauge.TagKind, Args: myTags, LineNo: 3},
		&parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 3", LineNo: 5},
	}
	spec, result := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary())
	c.Assert(result.Ok, Equals, true)

	c.Assert(len(spec.Scenarios), Equals, 3)
	c.Assert(len(spec.Scenarios[1].Tags.Values), Equals, 2)

	var specs []*gauge.Specification
	specs = append(specs, spec)
	specs = filterSpecsByTags(specs, "tag3")
	c.Assert(len(specs), Equals, 0)
}