Skip to content

Commit

Permalink
Merge branch 'hotfix/0.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddspog committed Jun 8, 2018
2 parents d99dd12 + d0a8cdf commit 8538ff3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 9 additions & 2 deletions internal/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ func (g *Gold) Get(key string) (val interface{}) {

// Load unmarshall the json into input and gold pointers received.
func (g *Gold) Load(input, gold interface{}) {
_ = encoder.Load(g.Input, input)
_ = encoder.Load(g.Golden, gold)
if input != nil {
_ = encoder.Load(g.Input, input)
}

if gold != nil {
_ = encoder.Load(g.Golden, gold)
}
}

// Update get an struct or a map, and loads into golden part of test
Expand Down Expand Up @@ -104,6 +109,8 @@ func NewManager(feat, given string) (m *Manager) {
if err = encoder.Read(&testdata); err != nil {
panic(err)
}

currentFeature = feature
}

if _, ok := testdata[given]; ok {
Expand Down
14 changes: 13 additions & 1 deletion spec/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,23 @@ type Configuration struct {
LastIt string
}

// ResetLasts sets all lats variables to empty. This makes config ready
// ResetLasts sets all last variables to empty. This makes config ready
// to print information about another context.
func (c *Configuration) ResetLasts() {
c.ResetWhen()
c.LastGiven = ""
}

// ResetWhen sets when and it last variables to empty. This makes
// config ready to print information about another condition.
func (c *Configuration) ResetWhen() {
c.ResetIt()
c.LastWhen = ""
}

// ResetIt sets it last variables to empty. This makes config ready to
// print information about another verification.
func (c *Configuration) ResetIt() {
c.LastIt = ""
}

Expand Down
11 changes: 8 additions & 3 deletions spec/specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type failingLineData struct {
next string
filename string
number int
lines []string
}

// TestSpecification holds the state of the test context for a specific specification.
Expand All @@ -45,6 +44,8 @@ func (spec *TestSpecification) PrintFeature() {
}
config.LastFeature = spec.Feature
}

config.ResetLasts()
}

// PrintContext prints line informing about context being tested.
Expand All @@ -55,6 +56,8 @@ func (spec *TestSpecification) PrintContext() {
}
config.LastGiven = spec.Given
}

config.ResetWhen()
}

// PrintWhen prints line informing about situation being tested.
Expand All @@ -65,6 +68,8 @@ func (spec *TestSpecification) PrintWhen() {
}
config.LastWhen = spec.When
}

config.ResetIt()
}

// PrintIt prints line informing about verification being tested when
Expand Down Expand Up @@ -147,13 +152,13 @@ func failingLine() (fl failingLineData, err error) {
// called after the Assertion has been executed to print details to the
// string.

_, filename, ln, _ := runtime.Caller(5)
_, filename, ln, _ := runtime.Caller(6)

// this is really hacky, need to find a way of not using magic numbers for runtime.Caller
// If we are not in a test file, we must still be inside this package,
// so we need to go up one more stack frame to get to the test file
if !strings.HasSuffix(filename, "_test.go") {
_, filename, ln, _ = runtime.Caller(6)
_, filename, ln, _ = runtime.Caller(7)
}

bf, err := ioutil.ReadFile(filename)
Expand Down

0 comments on commit 8538ff3

Please sign in to comment.