예제 #1
0
func (s *MySuite) TestResolveConceptToProtoConceptItem(c *C) {
	conceptDictionary := new(parser.ConceptDictionary)

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

	conceptText := SpecBuilder().
		specHeading("create user <user-id> <user-name> and <user-phone>").
		step("assign id <user-id> and name <user-name>").
		step("assign phone <user-phone>").String()

	concepts, _ := new(parser.ConceptParser).Parse(conceptText)
	conceptDictionary.Add(concepts, "file.cpt")
	spec, _ := new(parser.SpecParser).Parse(specText, conceptDictionary)

	specExecutor := newSpecExecutor(spec, nil, nil, indexRange{start: 0, end: 0}, nil)
	protoConcept := specExecutor.resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0]).GetConcept()

	checkConceptParameterValuesInOrder(c, protoConcept, "456", "foo", "9900")

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

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

}
예제 #2
0
func (s *MySuite) TestFormatConcepts(c *C) {
	dictionary := new(parser.ConceptDictionary)
	step1 := &parser.Step{Value: "sdsf", LineText: "sdsf", IsConcept: true, LineNo: 1, PreComments: []*parser.Comment{&parser.Comment{Value: "COMMENT", LineNo: 1}}}
	step2 := &parser.Step{Value: "dsfdsfdsf", LineText: "dsfdsfdsf", IsConcept: true, LineNo: 2, Items: []parser.Item{&parser.Step{Value: "sfd", LineText: "sfd", IsConcept: false}, &parser.Step{Value: "sdfsdf" + "T", LineText: "sdfsdf" + "T", IsConcept: false}}}
	dictionary.Add([]*parser.Step{step1, step2}, "file.cpt")

	formatted := FormatConcepts(dictionary)
	c.Assert(formatted["file.cpt"], Equals, `COMMENT
# sdsf
# dsfdsfdsf
* sdfsdfT
`)
}
예제 #3
0
func (s *MySuite) TestRefactoringOfStepsWithNoArgsInConceptFiles(c *C) {
	oldStep := "first step"
	newStep := "second step"
	unchanged := "unchanged"
	tokens := []*parser.Token{
		&parser.Token{Kind: parser.SpecKind, Value: "Spec Heading", LineNo: 1},
		&parser.Token{Kind: parser.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},
	}
	spec, _ := new(parser.SpecParser).CreateSpecification(tokens, new(parser.ConceptDictionary))
	agent, _ := getRefactorAgent(oldStep, newStep, nil)
	specs := append(make([]*parser.Specification, 0), spec)
	dictionary := new(parser.ConceptDictionary)
	step1 := &parser.Step{Value: oldStep + "sdsf", IsConcept: true}
	step2 := &parser.Step{Value: unchanged, IsConcept: true, Items: []parser.Item{&parser.Step{Value: oldStep, IsConcept: false}, &parser.Step{Value: oldStep + "T", IsConcept: false}}}
	dictionary.Add([]*parser.Step{step1, step2}, "file.cpt")

	agent.rephraseInSpecsAndConcepts(&specs, dictionary)

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

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

	c.Assert(filesRefactored[fileName], Equals, false)
	c.Assert(filesRefactored["e"+fileName], Equals, true)
}
예제 #5
0
func (s *MySuite) TestResolveToProtoConceptItemWithDataTable(c *C) {
	conceptDictionary := new(parser.ConceptDictionary)

	specText := SpecBuilder().specHeading("A spec heading").
		tableHeader("id", "name", "phone").
		tableHeader("123", "foo", "8800").
		tableHeader("666", "bar", "9900").
		scenarioHeading("First scenario").
		step("create user <id> <name> and <phone>").
		String()

	conceptText := SpecBuilder().
		specHeading("create user <user-id> <user-name> and <user-phone>").
		step("assign id <user-id> and name <user-name>").
		step("assign phone <user-phone>").
		specHeading("assign id <userid> and name <username>").
		step("add id <userid>").
		step("add name <username>").String()

	concepts, _ := new(parser.ConceptParser).Parse(conceptText)
	conceptDictionary.Add(concepts, "file.cpt")
	parser := new(parser.SpecParser)
	spec, _ := parser.Parse(specText, conceptDictionary)

	specExecutor := newSpecExecutor(spec, nil, nil, indexRange{start: 0, end: 0}, nil)

	// For first row
	specExecutor.currentTableRow = 0
	protoConcept := specExecutor.resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0]).GetConcept()
	checkConceptParameterValuesInOrder(c, protoConcept, "123", "foo", "8800")

	c.Assert(protoConcept.GetSteps()[0].GetItemType(), Equals, gauge_messages.ProtoItem_Concept)
	nestedConcept := protoConcept.GetSteps()[0].GetConcept()
	checkConceptParameterValuesInOrder(c, nestedConcept, "123", "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, "123")

	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, "8800")

	// For second row
	specExecutor.currentTableRow = 1
	protoConcept = specExecutor.resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0]).GetConcept()
	c.Assert(protoConcept.GetSteps()[0].GetItemType(), Equals, gauge_messages.ProtoItem_Concept)
	checkConceptParameterValuesInOrder(c, protoConcept, "666", "bar", "9900")

	nestedConcept = protoConcept.GetSteps()[0].GetConcept()
	checkConceptParameterValuesInOrder(c, nestedConcept, "666", "bar")
	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, "666")

	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, "bar")

	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")
}