How to use Steps method of gauge Package

Best Gauge code snippet using gauge.Steps

refactor_test.go

Source:refactor_test.go Github

copy

Full Screen

...19)20func Test(t *testing.T) { TestingT(t) }21type MySuite struct{}22var _ = Suite(&MySuite{})23func (s *MySuite) TestRefactoringOfStepsWithNoArgs(c *C) {24 oldStep := "first step"25 newStep := "second step"26 tokens := []*parser.Token{27 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},28 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},29 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},30 }31 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")32 agent, errs := getRefactorAgent(oldStep, newStep, nil)33 specs := append(make([]*gauge.Specification, 0), spec)34 agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())35 c.Assert(len(errs), Equals, 0)36 c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 1)37 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)38}39func (s *MySuite) TestRefactoringOfStepsWithNoArgsAndWithMoreThanOneScenario(c *C) {40 oldStep := "first step"41 newStep := "second step"42 unchanged := "unchanged"43 tokens := []*parser.Token{44 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},45 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},46 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},47 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 5},48 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},49 &parser.Token{Kind: gauge.StepKind, Value: unchanged, LineNo: 30},50 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 50},51 }52 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")53 agent, errs := getRefactorAgent(oldStep, newStep, nil)54 specs := append(make([]*gauge.Specification, 0), spec)55 agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())56 c.Assert(len(errs), Equals, 0)57 c.Assert(len(specs[0].Scenarios), Equals, 2)58 c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 2)59 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)60 c.Assert(specs[0].Scenarios[0].Steps[1].Value, Equals, newStep)61 c.Assert(len(specs[0].Scenarios[1].Steps), Equals, 2)62 c.Assert(specs[0].Scenarios[1].Steps[0].Value, Equals, unchanged)63 c.Assert(specs[0].Scenarios[1].Steps[1].Value, Equals, newStep)64}65func (s *MySuite) TestRefactoringOfStepsWithNoArgsAndWithMoreThanOneSpec(c *C) {66 oldStep := " first step"67 newStep := "second step"68 tokens := []*parser.Token{69 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},70 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},71 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},72 }73 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")74 tokens = []*parser.Token{75 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 10},76 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 20},77 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 30},78 }79 spec1, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")80 specs := append(make([]*gauge.Specification, 0), spec)81 specs = append(specs, spec1)82 agent, errs := getRefactorAgent(oldStep, newStep, nil)83 specRefactored, _ := agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())84 for _, isRefactored := range specRefactored {85 c.Assert(true, Equals, isRefactored)86 }87 c.Assert(len(errs), Equals, 0)88 c.Assert(len(specs[0].Scenarios[0].Steps), Equals, 1)89 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, newStep)90 c.Assert(len(specs[1].Scenarios[0].Steps), Equals, 1)91 c.Assert(specs[1].Scenarios[0].Steps[0].Value, Equals, newStep)92}93func (s *MySuite) TestRefactoringOfStepsWithNoArgsInConceptFiles(c *C) {94 oldStep := "first step"95 newStep := "second step"96 unchanged := "unchanged"97 tokens := []*parser.Token{98 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},99 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},100 }101 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")102 agent, _ := getRefactorAgent(oldStep, newStep, nil)103 specs := append(make([]*gauge.Specification, 0), spec)104 dictionary := gauge.NewConceptDictionary()105 step1 := &gauge.Step{Value: oldStep + "sdsf", IsConcept: true}106 step2 := &gauge.Step{Value: unchanged, IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: oldStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}107 dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: "file.cpt"}108 dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: "file.cpt"}109 agent.rephraseInSpecsAndConcepts(&specs, dictionary)110 c.Assert(dictionary.ConceptsMap[unchanged].ConceptStep.Items[0].(*gauge.Step).Value, Equals, newStep)111 c.Assert(dictionary.ConceptsMap[unchanged].ConceptStep.Items[1].(*gauge.Step).Value, Equals, oldStep+"T")112}113func (s *MySuite) TestRefactoringGivesOnlySpecsThatAreRefactored(c *C) {114 oldStep := " first step"115 newStep := "second step"116 tokens := []*parser.Token{117 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},118 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 2},119 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3},120 }121 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")122 tokens = []*parser.Token{123 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 10},124 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading", LineNo: 20},125 &parser.Token{Kind: gauge.StepKind, Value: newStep, LineNo: 30},126 }127 spec1, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")128 specs := append(make([]*gauge.Specification, 0), spec)129 specs = append(specs, spec1)130 agent, _ := getRefactorAgent(oldStep, newStep, nil)131 specRefactored, _ := agent.rephraseInSpecsAndConcepts(&specs, gauge.NewConceptDictionary())132 c.Assert(true, Equals, specRefactored[specs[0]])133 c.Assert(false, Equals, specRefactored[specs[1]])134}135func (s *MySuite) TestRefactoringGivesOnlyThoseConceptFilesWhichAreRefactored(c *C) {136 oldStep := "first step"137 newStep := "second step"138 unchanged := "unchanged"139 tokens := []*parser.Token{140 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},141 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 20},142 }143 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")144 agent, _ := getRefactorAgent(oldStep, newStep, nil)145 specs := append(make([]*gauge.Specification, 0), spec)146 dictionary := gauge.NewConceptDictionary()147 step1 := &gauge.Step{Value: oldStep + "sdsf", IsConcept: true}148 step2 := &gauge.Step{Value: unchanged, IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: newStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}149 step3 := &gauge.Step{Value: "Concept value", IsConcept: true, Items: []gauge.Item{&gauge.Step{Value: oldStep, IsConcept: false}, &gauge.Step{Value: oldStep + "T", IsConcept: false}}}150 fileName := "file.cpt"151 dictionary.ConceptsMap[step1.Value] = &gauge.Concept{ConceptStep: step1, FileName: fileName}152 dictionary.ConceptsMap[step2.Value] = &gauge.Concept{ConceptStep: step2, FileName: fileName}153 dictionary.ConceptsMap[step3.Value] = &gauge.Concept{ConceptStep: step3, FileName: "e" + fileName}154 _, filesRefactored := agent.rephraseInSpecsAndConcepts(&specs, dictionary)155 c.Assert(filesRefactored[fileName], Equals, false)156 c.Assert(filesRefactored["e"+fileName], Equals, true)157}158func (s *MySuite) TestRenamingWhenNumberOfArgumentsAreSame(c *C) {159 oldStep := "first step {static} and {static}"160 oldStep1 := "first step <a> and <b>"161 newStep := "second step <a> and <b>"162 tokens := []*parser.Token{163 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},164 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},165 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address"}},166 }167 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")168 agent, _ := getRefactorAgent(oldStep1, newStep, nil)169 specs := append(make([]*gauge.Specification, 0), spec)170 dictionary := gauge.NewConceptDictionary()171 agent.rephraseInSpecsAndConcepts(&specs, dictionary)172 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {}")173 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")174 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")175}176func (s *MySuite) TestRenamingWhenArgumentsOrderIsChanged(c *C) {177 oldStep := "first step {static} and {static} and {static} and {static}"178 oldStep1 := "first step <a> and <b> and <c> and <d>"179 newStep := "second step <d> and <b> and <c> and <a>"180 tokens := []*parser.Token{181 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},182 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},183 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},184 }185 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")186 agent, _ := getRefactorAgent(oldStep1, newStep, nil)187 specs := append(make([]*gauge.Specification, 0), spec)188 dictionary := gauge.NewConceptDictionary()189 agent.rephraseInSpecsAndConcepts(&specs, dictionary)190 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")191 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "id")192 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")193 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "number")194 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "name")195}196func (s *MySuite) TestCreateOrderGivesMapOfOldArgsAndNewArgs(c *C) {197 step1 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "a"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "d"}}}198 step2 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "d"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "a"}}}199 agent := &rephraseRefactorer{step1, step2, false, nil}200 orderMap := agent.createOrderOfArgs()201 c.Assert(orderMap[0], Equals, 3)202 c.Assert(orderMap[1], Equals, 1)203 c.Assert(orderMap[2], Equals, 2)204}205func (s *MySuite) TestCreateOrderGivesMapOfOldArgsAndNewWhenArgsAreAdded(c *C) {206 step1 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "a"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "d"}}}207 step2 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "d"}, &gauge.StepArg{Name: "e"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "a"}}}208 agent := &rephraseRefactorer{step1, step2, false, nil}209 orderMap := agent.createOrderOfArgs()210 c.Assert(orderMap[0], Equals, 3)211 c.Assert(orderMap[1], Equals, -1)212 c.Assert(orderMap[2], Equals, 1)213 c.Assert(orderMap[3], Equals, 2)214 c.Assert(orderMap[4], Equals, 0)215}216func (s *MySuite) TestCreateOrderGivesMapOfOldArgsAndNewWhenArgsAreRemoved(c *C) {217 step1 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "a"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}, &gauge.StepArg{Name: "d"}}}218 step2 := &gauge.Step{Args: []*gauge.StepArg{&gauge.StepArg{Name: "d"}, &gauge.StepArg{Name: "b"}, &gauge.StepArg{Name: "c"}}}219 agent := &rephraseRefactorer{step1, step2, false, nil}220 orderMap := agent.createOrderOfArgs()221 c.Assert(orderMap[0], Equals, 3)222 c.Assert(orderMap[1], Equals, 1)223 c.Assert(orderMap[2], Equals, 2)224}225func (s *MySuite) TestCreationOfOrderMapForStep(c *C) {226 agent, _ := getRefactorAgent("Say <greeting> to <name>", "Say <greeting> to <name> \"DD\"", nil)227 orderMap := agent.createOrderOfArgs()228 c.Assert(orderMap[0], Equals, 0)229 c.Assert(orderMap[1], Equals, 1)230 c.Assert(orderMap[2], Equals, -1)231}232func (s *MySuite) TestRenamingWhenArgumentsIsAddedAtLast(c *C) {233 oldStep := "first step {static} and {static} and {static}"234 oldStep1 := "first step <a> and <b> and <c>"235 newStep := "second step <a> and <b> and <c> and <d>"236 tokens := []*parser.Token{237 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},238 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},239 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number"}},240 }241 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")242 agent, _ := getRefactorAgent(oldStep1, newStep, nil)243 specs := append(make([]*gauge.Specification, 0), spec)244 dictionary := gauge.NewConceptDictionary()245 agent.rephraseInSpecsAndConcepts(&specs, dictionary)246 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")247 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")248 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")249 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "number")250 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "d")251}252func (s *MySuite) TestRenamingWhenArgumentsIsAddedAtFirst(c *C) {253 oldStep := "first step {static} and {static} and {static}"254 oldStep1 := "first step <a> and <b> and <c>"255 newStep := "second step <d> and <a> and <b> and <c>"256 tokens := []*parser.Token{257 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},258 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},259 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number"}},260 }261 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")262 agent, _ := getRefactorAgent(oldStep1, newStep, nil)263 specs := append(make([]*gauge.Specification, 0), spec)264 dictionary := gauge.NewConceptDictionary()265 agent.rephraseInSpecsAndConcepts(&specs, dictionary)266 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")267 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "d")268 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "name")269 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "address")270 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "number")271}272func (s *MySuite) TestRenamingWhenArgumentsIsAddedInMiddle(c *C) {273 oldStep := "first step {static} and {static} and {static}"274 oldStep1 := "first step <a> and <b> and <c>"275 newStep := "second step <a> and <d> and <b> and <c>"276 tokens := []*parser.Token{277 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},278 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},279 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number"}},280 }281 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")282 agent, _ := getRefactorAgent(oldStep1, newStep, nil)283 specs := append(make([]*gauge.Specification, 0), spec)284 dictionary := gauge.NewConceptDictionary()285 agent.rephraseInSpecsAndConcepts(&specs, dictionary)286 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {} and {}")287 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")288 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "d")289 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "address")290 c.Assert(specs[0].Scenarios[0].Steps[0].Args[3].Value, Equals, "number")291}292func (s *MySuite) TestRenamingWhenArgumentsIsRemovedFromLast(c *C) {293 oldStep := "first step {static} and {static} and {static} and {static}"294 oldStep1 := "first step <a> and <b> and <c> and <d>"295 newStep := "second step <a> and <b> and <c>"296 tokens := []*parser.Token{297 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},298 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},299 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},300 }301 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")302 agent, _ := getRefactorAgent(oldStep1, newStep, nil)303 specs := append(make([]*gauge.Specification, 0), spec)304 dictionary := gauge.NewConceptDictionary()305 agent.rephraseInSpecsAndConcepts(&specs, dictionary)306 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {}")307 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")308 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")309 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "number")310}311func (s *MySuite) TestRenamingWhenArgumentsIsRemovedFromBegining(c *C) {312 oldStep := "first step {static} and {static} and {static} and {static}"313 oldStep1 := "first step <a> and <b> and <c> and <d>"314 newStep := "second step <b> and <c> and <d>"315 tokens := []*parser.Token{316 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},317 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},318 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},319 }320 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")321 agent, _ := getRefactorAgent(oldStep1, newStep, nil)322 specs := append(make([]*gauge.Specification, 0), spec)323 dictionary := gauge.NewConceptDictionary()324 agent.rephraseInSpecsAndConcepts(&specs, dictionary)325 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {}")326 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "address")327 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "number")328 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "id")329}330func (s *MySuite) TestRenamingWhenArgumentsIsRemovedFromMiddle(c *C) {331 oldStep := "first step {static} and {static} and {static} and {static}"332 oldStep1 := "first step <a> and <b> and <c> and <d>"333 newStep := "second step <a> and <b> and <d>"334 tokens := []*parser.Token{335 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},336 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},337 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},338 }339 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")340 agent, _ := getRefactorAgent(oldStep1, newStep, nil)341 specs := append(make([]*gauge.Specification, 0), spec)342 dictionary := gauge.NewConceptDictionary()343 agent.rephraseInSpecsAndConcepts(&specs, dictionary)344 c.Assert(specs[0].Scenarios[0].Steps[0].Value, Equals, "second step {} and {} and {}")345 c.Assert(specs[0].Scenarios[0].Steps[0].Args[0].Value, Equals, "name")346 c.Assert(specs[0].Scenarios[0].Steps[0].Args[1].Value, Equals, "address")347 c.Assert(specs[0].Scenarios[0].Steps[0].Args[2].Value, Equals, "id")348}349func (s *MySuite) TestGenerateNewStepNameGivesLineTextWithActualParamNames(c *C) {350 args := []string{"name", "address", "id"}351 newStep := "second step <a> and <b> and <d>"352 orderMap := make(map[int]int)353 orderMap[0] = 1354 orderMap[1] = 2355 orderMap[2] = 0356 agent, _ := getRefactorAgent(newStep, newStep, nil)357 linetext := agent.generateNewStepName(args, orderMap)358 c.Assert(linetext, Equals, "second step <address> and <id> and <name>")359}360func (s *MySuite) TestGenerateNewStepNameWhenParametersAreAdded(c *C) {361 args := []string{"name", "address"}362 newStep := "changed step <a> and <b> and \"id\""363 orderMap := make(map[int]int)364 orderMap[0] = 1365 orderMap[1] = 0366 orderMap[2] = -1367 agent, _ := getRefactorAgent(newStep, newStep, nil)368 linetext := agent.generateNewStepName(args, orderMap)369 c.Assert(linetext, Equals, "changed step <address> and <name> and \"id\"")370}371func (s *MySuite) TestGenerateNewStepNameWhenParametersAreRemoved(c *C) {372 args := []string{"name", "address", "desc"}373 newStep := "changed step <b> and \"id\""374 orderMap := make(map[int]int)375 orderMap[0] = 1376 orderMap[1] = -1377 orderMap[2] = -1378 agent, _ := getRefactorAgent(newStep, newStep, nil)379 linetext := agent.generateNewStepName(args, orderMap)380 c.Assert(linetext, Equals, "changed step <address> and \"id\"")381}382func (s *MySuite) TestGenerateNewStepNameWhenParametersAreUnchanged(c *C) {383 args := []string{"a"}384 newStep := "make comment <a>"385 agent, _ := getRefactorAgent("Comment <a>", newStep, nil)386 linetext := agent.generateNewStepName(args, agent.createOrderOfArgs())387 c.Assert(linetext, Equals, "make comment <a>")388}389func (s *MySuite) TestRefactoringInContextStep(c *C) {390 oldStep := "first step {static} and {static} and {static} and {static}"391 oldStep1 := "first step <a> and <b> and <c> and <d>"392 newStep := "second step <d> and <b> and <c> and <a>"393 tokens := []*parser.Token{394 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},395 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},396 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},397 &parser.Token{Kind: gauge.StepKind, Value: oldStep + " sdf", LineNo: 3, Args: []string{"name", "address", "number", "id"}},398 }399 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")400 agent, _ := getRefactorAgent(oldStep1, newStep, nil)401 specs := append(make([]*gauge.Specification, 0), spec)402 dictionary := gauge.NewConceptDictionary()403 agent.rephraseInSpecsAndConcepts(&specs, dictionary)404 c.Assert(specs[0].Contexts[0].Value, Equals, "second step {} and {} and {} and {}")405 c.Assert(specs[0].Contexts[0].Args[0].Value, Equals, "id")406 c.Assert(specs[0].Contexts[0].Args[1].Value, Equals, "address")407 c.Assert(specs[0].Contexts[0].Args[2].Value, Equals, "number")408 c.Assert(specs[0].Contexts[0].Args[3].Value, Equals, "name")409}410func (s *MySuite) TestRefactoringInTearDownStep(c *C) {411 oldStep := "first step {static} and {static} and {static} and {static}"412 oldStep1 := "first step <a> and <b> and <c> and <d>"413 newStep := "second step <d> and <b> and <c> and <a>"414 tokens := []*parser.Token{415 &parser.Token{Kind: gauge.SpecKind, Value: "Spec Heading", LineNo: 1},416 &parser.Token{Kind: gauge.StepKind, Value: oldStep + "sdf", LineNo: 3, Args: []string{"name", "address", "number", "id"}},417 &parser.Token{Kind: gauge.ScenarioKind, Value: "Scenario Heading 1", LineNo: 2},418 &parser.Token{Kind: gauge.StepKind, Value: oldStep + " sdf", LineNo: 3, Args: []string{"name", "address", "number", "id"}},419 &parser.Token{Kind: gauge.TearDownKind, Value: "____", LineNo: 3},420 &parser.Token{Kind: gauge.StepKind, Value: oldStep, LineNo: 3, Args: []string{"name", "address", "number", "id"}},421 }422 spec, _ := new(parser.SpecParser).CreateSpecification(tokens, gauge.NewConceptDictionary(), "")423 agent, _ := getRefactorAgent(oldStep1, newStep, nil)424 specs := append(make([]*gauge.Specification, 0), spec)425 dictionary := gauge.NewConceptDictionary()426 agent.rephraseInSpecsAndConcepts(&specs, dictionary)427 c.Assert(specs[0].TearDownSteps[0].Value, Equals, "second step {} and {} and {} and {}")428 c.Assert(specs[0].TearDownSteps[0].Args[0].Value, Equals, "id")429 c.Assert(specs[0].TearDownSteps[0].Args[1].Value, Equals, "address")430 c.Assert(specs[0].TearDownSteps[0].Args[2].Value, Equals, "number")431 c.Assert(specs[0].TearDownSteps[0].Args[3].Value, Equals, "name")432}...

Full Screen

Full Screen

specDetails.go

Source:specDetails.go Github

copy

Full Screen

...62func (s *SpecInfoGatherer) Init() {63 // Concepts parsed first because we need to create a concept dictionary that spec parsing can use64 s.initConceptsCache()65 s.initSpecsCache()66 s.initStepsCache()67 s.initParamsCache()68 s.initTagsCache()69 go s.watchForFileChanges()70 s.waitGroup.Wait()71}72func (s *SpecInfoGatherer) initTagsCache() {73 s.tagsCache.mutex.Lock()74 defer s.tagsCache.mutex.Unlock()75 s.specsCache.mutex.Lock()76 s.tagsCache.tags = make(map[string][]string)77 for file, specDetail := range s.specsCache.specDetails {78 s.updateTagsCacheFromSpecs(file, specDetail)79 }80 defer s.specsCache.mutex.Unlock()81}82func (s *SpecInfoGatherer) initParamsCache() {83 s.paramsCache.mutex.Lock()84 defer s.paramsCache.mutex.Unlock()85 s.specsCache.mutex.Lock()86 s.paramsCache.staticParams = make(map[string]map[string]gauge.StepArg)87 s.paramsCache.dynamicParams = make(map[string]map[string]gauge.StepArg)88 for file, specDetail := range s.specsCache.specDetails {89 s.updateParamCacheFromSpecs(file, specDetail)90 }91 s.specsCache.mutex.Unlock()92 s.conceptsCache.mutex.Lock()93 for file, concepts := range s.conceptsCache.concepts {94 s.updateParamsCacheFromConcepts(file, concepts)95 }96 s.conceptsCache.mutex.Unlock()97}98func (s *SpecInfoGatherer) initSpecsCache() {99 details := s.getParsedSpecs(getSpecFiles(s.SpecDirs))100 s.specsCache.mutex.Lock()101 defer s.specsCache.mutex.Unlock()102 s.specsCache.specDetails = make(map[string]*SpecDetail)103 logger.Infof(false, "Initializing specs cache with %d specs", len(details))104 for _, d := range details {105 logger.Debugf(false, "Adding specs from %s", d.Spec.FileName)106 s.addToSpecsCache(d.Spec.FileName, d)107 }108}109func getSpecFiles(specs []string) []string {110 var specFiles []string111 for _, dir := range specs {112 specFiles = append(specFiles, util.FindSpecFilesIn(dir)...)113 }114 return specFiles115}116func (s *SpecInfoGatherer) initConceptsCache() {117 s.conceptsCache.mutex.Lock()118 defer s.conceptsCache.mutex.Unlock()119 parsedConcepts := s.getParsedConcepts()120 s.conceptsCache.concepts = make(map[string][]*gauge.Concept)121 logger.Infof(false, "Initializing concepts cache with %d concepts", len(parsedConcepts))122 for _, concept := range parsedConcepts {123 logger.Debugf(false, "Adding concepts from %s", concept.FileName)124 s.addToConceptsCache(concept.FileName, concept)125 }126}127func (s *SpecInfoGatherer) initStepsCache() {128 s.stepsCache.mutex.Lock()129 defer s.stepsCache.mutex.Unlock()130 s.stepsCache.steps = make(map[string][]*gauge.Step)131 stepsFromSpecsMap := s.getStepsFromCachedSpecs()132 stepsFromConceptsMap := s.getStepsFromCachedConcepts()133 for filename, steps := range stepsFromConceptsMap {134 s.addToStepsCache(filename, steps)135 }136 for filename, steps := range stepsFromSpecsMap {137 s.addToStepsCache(filename, steps)138 }139 logger.Infof(false, "Initializing steps cache with %d steps", len(stepsFromSpecsMap)+len(stepsFromConceptsMap))140}141func (s *SpecInfoGatherer) updateParamsCacheFromConcepts(file string, concepts []*gauge.Concept) {142 s.paramsCache.staticParams[file] = make(map[string]gauge.StepArg)143 s.paramsCache.dynamicParams[file] = make(map[string]gauge.StepArg)144 for _, concept := range concepts {145 s.addParamsFromSteps([]*gauge.Step{concept.ConceptStep}, file)146 s.addParamsFromSteps(concept.ConceptStep.ConceptSteps, file)147 }148}149func (s *SpecInfoGatherer) updateParamCacheFromSpecs(file string, specDetail *SpecDetail) {150 s.paramsCache.staticParams[file] = make(map[string]gauge.StepArg)151 s.paramsCache.dynamicParams[file] = make(map[string]gauge.StepArg)152 s.addParamsFromSteps(specDetail.Spec.Contexts, file)153 for _, sce := range specDetail.Spec.Scenarios {154 s.addParamsFromSteps(sce.Steps, file)155 }156 s.addParamsFromSteps(specDetail.Spec.TearDownSteps, file)157 if specDetail.Spec.DataTable.IsInitialized() {158 for _, header := range specDetail.Spec.DataTable.Table.Headers {159 s.paramsCache.dynamicParams[file][header] = gauge.StepArg{Value: header, ArgType: gauge.Dynamic}160 }161 }162}163func (s *SpecInfoGatherer) addParamsFromSteps(steps []*gauge.Step, file string) {164 for _, step := range steps {165 for _, arg := range step.Args {166 if arg.ArgType == gauge.Static {167 s.paramsCache.staticParams[file][arg.ArgValue()] = *arg168 } else {169 s.paramsCache.dynamicParams[file][arg.ArgValue()] = *arg170 }171 }172 }173}174func (s *SpecInfoGatherer) updateTagsCacheFromSpecs(file string, specDetail *SpecDetail) {175 if specDetail.Spec.Tags != nil {176 s.tagsCache.tags[file] = specDetail.Spec.Tags.Values()177 }178 for _, sce := range specDetail.Spec.Scenarios {179 if sce.Tags != nil {180 s.tagsCache.tags[file] = append(s.tagsCache.tags[file], sce.Tags.Values()...)181 }182 }183}184func removeDuplicateTags(tags []string) []string {185 encountered := map[string]bool{}186 result := []string{}187 for i := range tags {188 if !encountered[tags[i]] {189 encountered[tags[i]] = true190 result = append(result, tags[i])191 }192 }193 return result194}195func (s *SpecInfoGatherer) addToSpecsCache(key string, value *SpecDetail) {196 if s.specsCache.specDetails == nil {197 return198 }199 s.specsCache.specDetails[key] = value200}201func (s *SpecInfoGatherer) addToConceptsCache(key string, value *gauge.Concept) {202 if s.conceptsCache.concepts == nil {203 return204 }205 if s.conceptsCache.concepts[key] == nil {206 s.conceptsCache.concepts[key] = make([]*gauge.Concept, 0)207 }208 s.conceptsCache.concepts[key] = append(s.conceptsCache.concepts[key], value)209}210func (s *SpecInfoGatherer) deleteFromConceptDictionary(file string) {211 for _, c := range s.conceptsCache.concepts[file] {212 if file == s.conceptDictionary.ConceptsMap[c.ConceptStep.Value].FileName {213 s.conceptDictionary.Remove(c.ConceptStep.Value)214 }215 }216}217func (s *SpecInfoGatherer) addToStepsCache(fileName string, allSteps []*gauge.Step) {218 if s.stepsCache.steps == nil {219 return220 }221 s.stepsCache.steps[fileName] = allSteps222}223func (s *SpecInfoGatherer) getParsedSpecs(specFiles []string) []*SpecDetail {224 if s.conceptDictionary == nil {225 s.conceptDictionary = gauge.NewConceptDictionary()226 }227 parsedSpecs, parseResults := parser.ParseSpecFiles(specFiles, s.conceptDictionary, gauge.NewBuildErrors())228 specs := make(map[string]*SpecDetail)229 for _, spec := range parsedSpecs {230 specs[spec.FileName] = &SpecDetail{Spec: spec}231 }232 for _, v := range parseResults {233 _, ok := specs[v.FileName]234 if !ok {235 specs[v.FileName] = &SpecDetail{Spec: &gauge.Specification{FileName: v.FileName}, Errs: v.ParseErrors}236 }237 }238 details := make([]*SpecDetail, 0)239 for _, d := range specs {240 details = append(details, d)241 }242 return details243}244func (s *SpecInfoGatherer) getParsedConcepts() map[string]*gauge.Concept {245 var result *parser.ParseResult246 var err error247 s.conceptDictionary, result, err = parser.CreateConceptsDictionary()248 if err != nil {249 logger.Fatalf(true, "Unable to parse concepts : %s", err.Error())250 }251 handleParseFailures([]*parser.ParseResult{result})252 return s.conceptDictionary.ConceptsMap253}254func (s *SpecInfoGatherer) getStepsFromCachedSpecs() map[string][]*gauge.Step {255 s.specsCache.mutex.RLock()256 defer s.specsCache.mutex.RUnlock()257 var stepsFromSpecsMap = make(map[string][]*gauge.Step)258 for _, detail := range s.specsCache.specDetails {259 stepsFromSpecsMap[detail.Spec.FileName] = append(stepsFromSpecsMap[detail.Spec.FileName], getStepsFromSpec(detail.Spec)...)260 }261 return stepsFromSpecsMap262}263func (s *SpecInfoGatherer) getStepsFromCachedConcepts() map[string][]*gauge.Step {264 var stepsFromConceptMap = make(map[string][]*gauge.Step)265 s.conceptsCache.mutex.RLock()266 defer s.conceptsCache.mutex.RUnlock()267 for _, conceptList := range s.conceptsCache.concepts {268 for _, concept := range conceptList {269 stepsFromConceptMap[concept.FileName] = append(stepsFromConceptMap[concept.FileName], getStepsFromConcept(concept)...)270 }271 }272 return stepsFromConceptMap273}274func (s *SpecInfoGatherer) OnSpecFileModify(file string) {275 logger.Debugf(false, "Spec file added / modified: %s", file)276 details := s.getParsedSpecs([]string{file})277 s.specsCache.mutex.Lock()278 s.addToSpecsCache(file, details[0])279 s.specsCache.mutex.Unlock()280 var steps []*gauge.Step281 steps = append(steps, getStepsFromSpec(details[0].Spec)...)282 s.stepsCache.mutex.Lock()283 s.addToStepsCache(file, steps)284 s.stepsCache.mutex.Unlock()285 s.paramsCache.mutex.Lock()286 s.updateParamCacheFromSpecs(file, details[0])287 s.paramsCache.mutex.Unlock()288 s.tagsCache.mutex.Lock()289 s.updateTagsCacheFromSpecs(file, details[0])290 s.tagsCache.mutex.Unlock()291}292func (s *SpecInfoGatherer) OnConceptFileModify(file string) {293 s.conceptsCache.mutex.Lock()294 defer s.conceptsCache.mutex.Unlock()295 logger.Debugf(false, "Concept file added / modified: %s", file)296 s.deleteFromConceptDictionary(file)297 concepts, parseErrors, err := parser.AddConcepts([]string{file}, s.conceptDictionary)298 if err != nil {299 logger.Fatalf(true, "Unable to update concepts : %s", err.Error())300 }301 if len(parseErrors) > 0 {302 res := &parser.ParseResult{}303 res.ParseErrors = append(res.ParseErrors, parseErrors...)304 res.Ok = false305 handleParseFailures([]*parser.ParseResult{res})306 }307 s.conceptsCache.concepts[file] = make([]*gauge.Concept, 0)308 var stepsFromConcept []*gauge.Step309 for _, concept := range concepts {310 c := gauge.Concept{ConceptStep: concept, FileName: file}311 s.addToConceptsCache(file, &c)312 stepsFromConcept = append(stepsFromConcept, getStepsFromConcept(&c)...)313 }314 s.addToStepsCache(file, stepsFromConcept)315 s.paramsCache.mutex.Lock()316 defer s.paramsCache.mutex.Unlock()317 s.updateParamsCacheFromConcepts(file, s.conceptsCache.concepts[file])318}319func (s *SpecInfoGatherer) onSpecFileRemove(file string) {320 logger.Debugf(false, "Spec file removed: %s", file)321 s.specsCache.mutex.Lock()322 defer s.specsCache.mutex.Unlock()323 delete(s.specsCache.specDetails, file)324 s.removeStepsFromCache(file)325}326func (s *SpecInfoGatherer) removeStepsFromCache(fileName string) {327 s.stepsCache.mutex.Lock()328 defer s.stepsCache.mutex.Unlock()329 delete(s.stepsCache.steps, fileName)330}331func (s *SpecInfoGatherer) onConceptFileRemove(file string) {332 logger.Debugf(false, "Concept file removed: %s", file)333 s.conceptsCache.mutex.Lock()334 defer s.conceptsCache.mutex.Unlock()335 s.deleteFromConceptDictionary(file)336 delete(s.conceptsCache.concepts, file)337 s.removeStepsFromCache(file)338}339func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) {340 if util.IsDir(file) {341 addDirToFileWatcher(watcher, file)342 }343 s.onFileModify(watcher, file)344}345func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) {346 if util.IsSpec(file) {347 s.OnSpecFileModify(file)348 } else if util.IsConcept(file) {349 s.OnConceptFileModify(file)350 }351}352func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) {353 if util.IsSpec(file) {354 s.onSpecFileRemove(file)355 } else if util.IsConcept(file) {356 s.onConceptFileRemove(file)357 } else {358 removeWatcherOn(watcher, file)359 }360}361func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) {362 s.onFileRemove(watcher, file)363}364func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) {365 s.waitGroup.Wait()366 file, err := filepath.Abs(event.Name)367 if err != nil {368 logger.Errorf(false, "Failed to get abs file path for %s: %s", event.Name, err)369 return370 }371 if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) {372 switch event.Op {373 case fsnotify.Create:374 s.onFileAdd(watcher, file)375 case fsnotify.Write:376 s.onFileModify(watcher, file)377 case fsnotify.Rename:378 s.onFileRename(watcher, file)379 case fsnotify.Remove:380 s.onFileRemove(watcher, file)381 }382 }383}384func (s *SpecInfoGatherer) watchForFileChanges() {385 s.waitGroup.Add(1)386 watcher, err := fsnotify.NewWatcher()387 if err != nil {388 logger.Errorf(false, "Error creating fileWatcher: %s", err)389 }390 defer watcher.Close()391 done := make(chan bool)392 go func() {393 for {394 select {395 case event := <-watcher.Events:396 s.handleEvent(event, watcher)397 case err := <-watcher.Errors:398 logger.Errorf(false, "Error event while watching specs %s", err)399 }400 }401 }()402 var allDirsToWatch []string403 var specDir string404 for _, dir := range s.SpecDirs {405 specDir = filepath.Join(config.ProjectRoot, dir)406 allDirsToWatch = append(allDirsToWatch, specDir)407 allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...)408 }409 for _, dir := range allDirsToWatch {410 addDirToFileWatcher(watcher, dir)411 }412 s.waitGroup.Done()413 <-done414}415// GetAvailableSpecs returns the list of all the specs in the gauge project416func (s *SpecInfoGatherer) GetAvailableSpecDetails(specs []string) []*SpecDetail {417 if len(specs) < 1 {418 specs = util.GetSpecDirs()419 }420 specFiles := getSpecFiles(specs)421 s.specsCache.mutex.RLock()422 defer s.specsCache.mutex.RUnlock()423 var details []*SpecDetail424 for _, f := range specFiles {425 if d, ok := s.specsCache.specDetails[f]; ok {426 details = append(details, d)427 }428 }429 return details430}431func (s *SpecInfoGatherer) GetSpecDirs() []string {432 return s.SpecDirs433}434// Steps returns the list of all the steps in the gauge project. Duplicate steps are filtered435func (s *SpecInfoGatherer) Steps(filterConcepts bool) []*gauge.Step {436 s.stepsCache.mutex.RLock()437 defer s.stepsCache.mutex.RUnlock()438 filteredSteps := make(map[string]*gauge.Step)439 for _, steps := range s.stepsCache.steps {440 for _, s := range steps {441 if !filterConcepts || !s.IsConcept {442 filteredSteps[s.Value] = s443 }444 }445 }446 var steps []*gauge.Step447 for _, sv := range filteredSteps {448 steps = append(steps, sv)449 }450 return steps451}452// Steps returns the list of all the steps in the gauge project including duplicate steps453func (s *SpecInfoGatherer) AllSteps(filterConcepts bool) []*gauge.Step {454 s.stepsCache.mutex.RLock()455 defer s.stepsCache.mutex.RUnlock()456 var allSteps []*gauge.Step457 for _, steps := range s.stepsCache.steps {458 if filterConcepts {459 for _, s := range steps {460 if !s.IsConcept {461 allSteps = append(allSteps, s)462 }463 }464 } else {465 allSteps = append(allSteps, steps...)466 }467 }468 return allSteps469}470// Steps returns the list of all the steps in the gauge project471func (s *SpecInfoGatherer) Params(filePath string, argType gauge.ArgType) []gauge.StepArg {472 s.paramsCache.mutex.RLock()473 defer s.paramsCache.mutex.RUnlock()474 var params []gauge.StepArg475 if argType == gauge.Static {476 for _, param := range s.paramsCache.staticParams[filePath] {477 params = append(params, param)478 }479 } else {480 for _, param := range s.paramsCache.dynamicParams[filePath] {481 params = append(params, param)482 }483 }484 return params485}486// Concepts returns an array containing information about all the concepts present in the Gauge project487func (s *SpecInfoGatherer) Concepts() []*gauge_messages.ConceptInfo {488 var conceptInfos []*gauge_messages.ConceptInfo489 s.conceptsCache.mutex.RLock()490 defer s.conceptsCache.mutex.RUnlock()491 for _, conceptList := range s.conceptsCache.concepts {492 for _, concept := range conceptList {493 stepValue := parser.CreateStepValue(concept.ConceptStep)494 conceptInfos = append(conceptInfos, &gauge_messages.ConceptInfo{StepValue: gauge.ConvertToProtoStepValue(&stepValue), Filepath: concept.FileName, LineNumber: int32(concept.ConceptStep.LineNo)})495 }496 }497 return conceptInfos498}499func (s *SpecInfoGatherer) Tags() []string {500 s.tagsCache.mutex.RLock()501 defer s.tagsCache.mutex.RUnlock()502 var allTags []string503 for _, tags := range s.tagsCache.tags {504 allTags = append(allTags, tags...)505 }506 return removeDuplicateTags(allTags)507}508// SearchConceptDictionary searches for a concept in concept dictionary509func (s *SpecInfoGatherer) SearchConceptDictionary(stepValue string) *gauge.Concept {510 return s.conceptDictionary.Search(stepValue)511}512func getStepsFromSpec(spec *gauge.Specification) []*gauge.Step {513 steps := spec.Contexts514 for _, scenario := range spec.Scenarios {515 steps = append(steps, scenario.Steps...)516 }517 steps = append(steps, spec.TearDownSteps...)518 return steps519}520func getStepsFromConcept(concept *gauge.Concept) []*gauge.Step {521 return concept.ConceptStep.ConceptSteps522}523func handleParseFailures(parseResults []*parser.ParseResult) {524 for _, result := range parseResults {525 if !result.Ok {526 logger.Errorf(false, "Parse failure: %s", result.Errors())527 }528 }529}530func addDirToFileWatcher(watcher *fsnotify.Watcher, dir string) {531 err := watcher.Add(dir)532 if err != nil {533 logger.Errorf(false, "Unable to add directory %v to file watcher: %s", dir, err.Error())534 } else {535 logger.Debugf(false, "Watching directory: %s", dir)...

Full Screen

Full Screen

dataTableSpecs_test.go

Source:dataTableSpecs_test.go Github

copy

Full Screen

...20 {21 specs: []*gauge.Specification{22 {23 Heading: &gauge.Heading{},24 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}}},25 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{26 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},27 }, 0)},28 },29 },30 want: 2,31 message: "Create specs for each data table row",32 },33 {34 specs: []*gauge.Specification{35 {36 Heading: &gauge.Heading{},37 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}}},38 },39 },40 want: 1,41 message: "Create non data table driven specs",42 },43 {44 specs: []*gauge.Specification{45 {46 Heading: &gauge.Heading{},47 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}}},48 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{49 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},50 }, 0)},51 },52 {53 Heading: &gauge.Heading{},54 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}}},55 },56 },57 want: 3,58 message: "Create data table driven and non data table driven specs",59 },60 {61 specs: []*gauge.Specification{62 {63 Heading: &gauge.Heading{},64 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "abc", ArgType: gauge.Static}}}}}},65 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{66 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},67 }, 0)},68 Contexts: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}},69 },70 },71 want: 2,72 message: "Create specs with context steps using table param",73 },74 {75 specs: []*gauge.Specification{76 {77 Heading: &gauge.Heading{},78 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "abc", ArgType: gauge.Static}}}}}},79 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{80 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},81 }, 0)},82 TearDownSteps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}},83 },84 },85 want: 2,86 message: "Create specs with Teardown steps using table param",87 },88}89func TestGetSpecsForDataTableRows(t *testing.T) {90 for _, test := range tests {91 got := GetSpecsForDataTableRows(test.specs, gauge.NewBuildErrors())92 if len(got) != test.want {93 t.Errorf("Failed: %s. Wanted: %d specs, Got: %d specs", test.message, test.want, len(got))94 }95 }96}97func TestGetSpecsForDataTableRowsShouldHaveEqualNumberOfScenearioInSpecsScenariosAndItemCollection(t *testing.T) {98 specs := []*gauge.Specification{99 {100 Heading: &gauge.Heading{},101 Scenarios: []*gauge.Scenario{102 {Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}},103 {Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "param1", ArgType: gauge.Static, Name: "param1"}}}}},104 },105 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{106 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},107 }, 0)},108 },109 }110 actualSpecs := GetSpecsForDataTableRows(specs, gauge.NewBuildErrors())111 if !containsScenario(actualSpecs[0].Scenarios, actualSpecs[0].Items) {112 itemsJSON, _ := json.Marshal(actualSpecs[0].Items)113 scnJSON, _ := json.Marshal(actualSpecs[0].Scenarios)114 t.Errorf("Failed: Wanted items:\n\n%s\n\nto contain all scenarios: \n\n%s", itemsJSON, scnJSON)115 }116}117func containsScenario(scenarios []*gauge.Scenario, items []gauge.Item) bool {118 for _, scenario := range scenarios {119 contains := false120 for _, item := range items {121 if item.Kind() == gauge.ScenarioKind && reflect.DeepEqual(scenario, item.(*gauge.Scenario)) {122 contains = true123 }124 }125 if !contains {126 return false127 }128 }129 return true130}131func TestGetSpecsForDataTableRowsShouldHaveEqualNumberOfScenearioInSpecsScenariosAndItemCollectionForScenarioDataTable(t *testing.T) {132 old := env.AllowScenarioDatatable133 env.AllowScenarioDatatable = func() bool {134 return true135 }136 specs := []*gauge.Specification{137 {138 Heading: &gauge.Heading{},139 Scenarios: []*gauge.Scenario{140 {141 Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}},142 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{143 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}, {Value: "row3", CellType: gauge.Static}},144 }, 0)}},145 },146 },147 }148 actualSpecs := GetSpecsForDataTableRows(specs, gauge.NewBuildErrors())149 if !containsScenario(actualSpecs[0].Scenarios, actualSpecs[0].Items) {150 itemsJSON, _ := json.Marshal(actualSpecs[0].Items)151 scnJSON, _ := json.Marshal(actualSpecs[0].Scenarios)152 t.Errorf("Failed: Wanted items:\n\n%s\n\nto contain all scenarios: \n\n%s", itemsJSON, scnJSON)153 }154 env.AllowScenarioDatatable = old155}156func TestGetTableWithOneRow(t *testing.T) {157 table := gauge.NewTable([]string{"header"}, [][]gauge.TableCell{158 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},159 }, 0)160 want := *gauge.NewTable([]string{"header"}, [][]gauge.TableCell{{{Value: "row1", CellType: gauge.Static}}}, 0)161 got := *getTableWithOneRow(table, 0)162 if !reflect.DeepEqual(want, got) {163 t.Errorf("Failed: Table with 1 row. Wanted: %v, Got: %v", want, got)164 }165}166func TestCreateSpecsForTableRows(t *testing.T) {167 spec := &gauge.Specification{168 Heading: &gauge.Heading{},169 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}}},170 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{171 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},172 }, 0)},173 Contexts: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}},174 Items: []gauge.Item{175 &gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{176 {{Value: "row1", CellType: gauge.Static}, {Value: "row2", CellType: gauge.Static}},177 }, 0)},178 &gauge.Scenario{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}},179 },180 TearDownSteps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "abc", ArgType: gauge.Static}}}},181 }182 want := []*gauge.Specification{183 {184 Heading: &gauge.Heading{},185 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}, SpecDataTableRow: *gauge.NewTable([]string{"header"}, [][]gauge.TableCell{186 {{Value: "row1", CellType: gauge.Static}},187 }, 0), SpecDataTableRowIndex: 0}},188 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{189 {{Value: "row1", CellType: gauge.Static}},190 }, 0)},191 Contexts: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}},192 Items: []gauge.Item{193 &gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{194 {{Value: "row1", CellType: gauge.Static}},195 }, 0)},196 &gauge.Scenario{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}, SpecDataTableRow: *gauge.NewTable([]string{"header"}, [][]gauge.TableCell{197 {{Value: "row1", CellType: gauge.Static}},198 }, 0), SpecDataTableRowIndex: 0},199 },200 TearDownSteps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "abc", ArgType: gauge.Static}}}},201 },202 {203 Heading: &gauge.Heading{},204 Scenarios: []*gauge.Scenario{{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}, SpecDataTableRow: *gauge.NewTable([]string{"header"}, [][]gauge.TableCell{205 {{Value: "row2", CellType: gauge.Static}},206 }, 0), SpecDataTableRowIndex: 1}},207 DataTable: gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{208 {{Value: "row2", CellType: gauge.Static}},209 }, 0)},210 Contexts: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}},211 Items: []gauge.Item{212 &gauge.DataTable{Table: gauge.NewTable([]string{"header"}, [][]gauge.TableCell{213 {{Value: "row2", CellType: gauge.Static}},214 }, 0)},215 &gauge.Scenario{Steps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "header", ArgType: gauge.Dynamic, Name: "header"}}}}, SpecDataTableRow: *gauge.NewTable([]string{"header"}, [][]gauge.TableCell{216 {{Value: "row2", CellType: gauge.Static}},217 }, 0), SpecDataTableRowIndex: 1},218 },219 TearDownSteps: []*gauge.Step{{Args: []*gauge.StepArg{{Value: "abc", ArgType: gauge.Static}}}},220 },221 }222 got := createSpecsForTableRows(spec, spec.Scenarios, gauge.NewBuildErrors())223 if !reflect.DeepEqual(want, got) {224 gotJSON, _ := json.Marshal(got)225 wantJSON, _ := json.Marshal(want)226 t.Errorf("Failed: Create specs for table row.\n\tWanted: %v\n\tGot: %v", string(wantJSON), string(gotJSON))227 }228}...

Full Screen

Full Screen

Steps

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 gauge.Step("Hello World", func() {4 fmt.Println("Hello World")5 })6}7import (8func main() {9 gauge.Step("Hello World", func() {10 fmt.Println("Hello World")11 })12}13import (14func main() {15 gauge.Step("Hello World", func() {16 fmt.Println("Hello World")17 })18}19import (20func main() {21 gauge.Step("Hello World", func() {22 fmt.Println("Hello World")23 })24}25import (26func main() {27 gauge.Step("Hello World", func() {28 fmt.Println("Hello World")29 })30}31import (32func main() {33 gauge.Step("Hello World", func() {34 fmt.Println("Hello World")35 })36}37import (38func main() {39 gauge.Step("Hello World", func() {40 fmt.Println("Hello World")41 })42}43import (44func main() {45 gauge.Step("Hello World", func() {46 fmt.Println("Hello World")47 })48}

Full Screen

Full Screen

Steps

Using AI Code Generation

copy

Full Screen

1import (2import (3func main() {4 gauge.Step("Step 1", func() {5 fmt.Println("Step 1")6 })7}

Full Screen

Full Screen

Steps

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4}5func StepImplementation() {6 gauge.Step("step text", func() {7 fmt.Println("Hello World")8 })9}10import (11func main() {12 fmt.Println("Hello World")13}14func StepImplementation() {15 gauge.Step("step text", func() {16 fmt.Println("Hello World")17 })18}19import (20func main() {21 fmt.Println("Hello World")22}23func StepImplementation() {24 gauge.Step("step text", func() {25 fmt.Println("Hello World")26 })27}28import (29func main() {30 fmt.Println("Hello World")31}32func StepImplementation() {33 gauge.Step("step text", func() {34 fmt.Println("Hello World")35 })36}37import (38func main() {39 fmt.Println("Hello World")40}41func StepImplementation() {42 gauge.Step("step text", func() {43 fmt.Println("Hello World")44 })45}46import (47func main() {48 fmt.Println("Hello World")49}50func StepImplementation() {51 gauge.Step("step text", func() {52 fmt.Println("Hello World")53 })54}55import (56func main() {57 fmt.Println("Hello World")58}59func StepImplementation() {60 gauge.Step("step text", func() {

Full Screen

Full Screen

Steps

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/getgauge-contrib/gauge-go/gauge"3func main() {4 gauge.Step("Step Implementation", func() {5 fmt.Println("Step Implementation")6 })7}8import "fmt"9import "github.com/getgauge-contrib/gauge-go/gauge"10func main() {11 gauge.Step("Step Implementation", func() {12 fmt.Println("Step Implementation")13 })14}

Full Screen

Full Screen

Steps

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var gauge1 Gauge = Gauge{0, 10}4 fmt.Println(gauge1)5 gauge1.Steps(3)6 fmt.Println(gauge1)7 gauge1.Steps(-2)8 fmt.Println(gauge1)9}10import "fmt"11func main() {12 var gauge1 Gauge = Gauge{0, 10}13 fmt.Println(gauge1)14 gauge1.Increment()15 fmt.Println(gauge1)16 gauge1.Increment()17 fmt.Println(gauge1)18}19import "fmt"20func main() {21 var gauge1 Gauge = Gauge{0, 10}22 fmt.Println(gauge1)23 gauge1.Decrement()24 fmt.Println(gauge1)25 gauge1.Decrement()26 fmt.Println(gauge1)27}28import "fmt"29func main() {30 var gauge1 Gauge = Gauge{0, 10}31 fmt.Println(gauge1)32 gauge1.Steps(3)33 fmt.Println(gauge1)34 gauge1.Reset()35 fmt.Println(gauge1)36}37import "fmt"38func main() {39 var gauge1 Gauge = Gauge{0, 10}40 fmt.Println(gauge1)41 gauge1.SetMax(20)42 fmt.Println(gauge1)43 gauge1.Steps(3)44 fmt.Println(gauge1)45 gauge1.SetMax(15)46 fmt.Println(gauge1)47}48import "fmt"49func main() {50 var gauge1 Gauge = Gauge{0, 10}51 fmt.Println(gauge1)52 gauge1.SetMin(-10)53 fmt.Println(gauge1)54 gauge1.Steps(-3)55 fmt.Println(gauge1)56 gauge1.SetMin(-5)57 fmt.Println(gauge1)58}

Full Screen

Full Screen

Steps

Using AI Code Generation

copy

Full Screen

1import (2func Steps() {3 gauge.Step("This is a step", func() {4 fmt.Println("This is a step")5 })6}

Full Screen

Full Screen

Steps

Using AI Code Generation

copy

Full Screen

1import (2func SayHelloWorldToGauge() {3 gauge.Message("Hello World to Gauge!", gauge.MessageInfo)4}5func SayHelloWorldToGaugeWithParam(param string) {6 gauge.Message("Hello World to Gauge!", gauge.MessageInfo)7}8func SayHelloWorldToGaugeWithParamAndTable(param string, table *gauge.Table) {9 gauge.Message("Hello World to Gauge!", gauge.MessageInfo)10}11func SayHelloWorldToGaugeWithParamAndTableAndConcept(param string, table *gauge.Table, concept *gauge.Concept) {12 gauge.Message("Hello World to Gauge!", gauge.MessageInfo)13}14func SayHelloWorldToGaugeWithParamAndTableAndConceptAndDynamicParam(param string, table *gauge.Table, concept *gauge.Concept, dynamicParam *gauge.DynamicParam) {15 gauge.Message("Hello World to Gauge!", gauge.MessageInfo)16}17func SayHelloWorldToGaugeWithParamAndTableAndConceptAndDynamicParamAndSpecialTable(param string, table *gauge.Table, concept *gauge.Concept, dynamicParam *gauge.DynamicParam, specialTable *gauge.Table) {18 gauge.Message("Hello World to Gauge!", gauge.MessageInfo)19}20func SayHelloWorldToGaugeWithParamAndTableAndConceptAndDynamicParamAndSpecialTableAndSpecialTable(param string, table *gauge.Table, concept *gauge.Concept, dynamicParam *gauge.DynamicParam, specialTable *gauge.Table, specialTable1 *gauge.Table) {21 gauge.Message("Hello

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful