Skip to content

Commit

Permalink
BDD iteration RedHatOfficial#4
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Nov 14, 2019
1 parent d93373d commit a298db4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
9 changes: 9 additions & 0 deletions testing/bdd_iteration_4/accumulator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package accumulator

type acc struct {
value int
}

func (a *acc) accumulate(x int) {
a.value += x
}
35 changes: 35 additions & 0 deletions testing/bdd_iteration_4/accumulator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package accumulator

import (
"fmt"
"github.com/DATA-DOG/godog"
)

var testAccumulator *acc

func iHaveAnAccumulatorWith(initialValue int) error {
testAccumulator.value = initialValue
return nil
}

func iAddToAccumulator(value int) error {
testAccumulator.accumulate(value)
return nil
}

func theAccumulatedResultShouldBe(expected int) error {
if testAccumulator.value == expected {
return nil
}
return fmt.Errorf("Incorrect accumulator value")
}

func FeatureContext(s *godog.Suite) {
s.Step(`^I have an accumulator with (-?\d+)$`, iHaveAnAccumulatorWith)
s.Step(`^I add (-?\d+) to accumulator$`, iAddToAccumulator)
s.Step(`^the accumulated result should be (-?\d+)$`, theAccumulatedResultShouldBe)

s.BeforeScenario(func(interface{}) {
testAccumulator = &acc{}
})
}
12 changes: 12 additions & 0 deletions testing/bdd_iteration_4/features/accumulator.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: simple accumulator checks
An accumulator must be able to add a number to its content

Scenario: Accumulate positive integer
Given I have an accumulator with 0
When I add 2 to accumulator
Then the accumulated result should be 2

Scenario: Accumulate negative integer
Given I have an accumulator with 0
When I add -2 to accumulator
Then the accumulated result should be -2
14 changes: 14 additions & 0 deletions testing/bdd_iteration_4/hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
You can implement step definitions for undefined steps with these snippets:

func iAddToAccumulator(arg1 int) error {
return godog.ErrPending
}

func theAccumulatedResultShouldBe(arg1 int) error {
return godog.ErrPending
}

func FeatureContext(s *godog.Suite) {
s.Step(`^I add -(\d+) to accumulator$`, iAddToAccumulator)
s.Step(`^the accumulated result should be -(\d+)$`, theAccumulatedResultShouldBe)
}

0 comments on commit a298db4

Please sign in to comment.