Skip to content

Commit

Permalink
updating based on latest gogivens
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcorbyeaglen committed Jan 23, 2018
1 parent c5409fd commit ea771f1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
65 changes: 33 additions & 32 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"github.com/corbym/gocrest"
"github.com/corbym/gocrest/is"
. "github.com/corbym/gocrest/then"
"github.com/corbym/gogiven/base"
"github.com/corbym/gogiven/generator"
"github.com/corbym/gogiven/testdata"
"github.com/corbym/jsonspec"
"testing"
)
Expand All @@ -27,22 +25,24 @@ func TestTestOutputGenerator_Generate(testing *testing.T) {
`{
"title": "Generator Test",
"test_state": {
"foo": {
"test title": {
"test_results": {
"id": "foo",
"failed": false,
"skipped": false,
"test_output": ""
"id": "abc2124",
"failed": true,
"skipped": true,
"test_output": "well alrighty then"
},
"test_title": "Generator Test",
"test_title": "test title",
"interesting_givens": {
"faff": "flap"
},
"captured_io": {
"foob": "barb"
},
"given_when_then": [
"GivenWhenThen"
"given",
"when",
"then"
]
}
}
Expand All @@ -64,7 +64,7 @@ func isValidJson() *gocrest.Matcher {
func TestTestOutputGenerator_GenerateConcurrently(testing *testing.T) {
for i := 0; i < 15; i++ {
go func() {
data := newPageData(newSomeMap())
data := newPageData(false, false)

html := underTest.Generate(data)
AssertThat(testing, html, is.ValueContaining("Generator Test"))
Expand All @@ -81,33 +81,34 @@ func TestTestOutputGenerator_Panics(t *testing.T) {
recovered := recover()
AssertThat(t, recovered, is.Not(is.Nil()))
}()
data := newPageData(newSomeMap())
data.SomeMap = nil

underTest.Generate(data)
underTest.Generate(nil)
}

func fileIsConverted() {
jsonString = underTest.Generate(newPageData(newSomeMap()))
}

func newSomeMap() *base.SomeMap {
testingT := new(base.TestMetaData)
some := base.NewSome(testingT,
"Generator Test",
base.NewTestMetaData("foo"),
[]string{"GivenWhenThen"},
func(givens testdata.InterestingGivens) {
givens["faff"] = "flap"
})
some.CapturedIO()["foob"] = "barb"
someMap := &base.SomeMap{"foo": some}
return someMap
jsonString = underTest.Generate(newPageData(true, true))
}

func newPageData(someMap *base.SomeMap) *generator.PageData {
func newPageData(skipped bool, failed bool) *generator.PageData {
testData := make(map[string]*generator.TestData)
capturedIO := make(map[interface{}]interface{})
capturedIO["foob"] = "barb"
interestingGivens := make(map[interface{}]interface{})
interestingGivens["faff"] = "flap"
testData["test title"] = &generator.TestData{
TestTitle: "test title",
GivenWhenThen: []string{"given", "when", "then"},
CapturedIO: capturedIO,
InterestingGivens: interestingGivens,
TestResult: &generator.TestResult{
Failed: failed,
Skipped: skipped,
TestOutput: "well alrighty then",
TestId: "abc2124",
},
}
return &generator.PageData{
Title: "Generator Test",
SomeMap: someMap,
TestResults: testData,
Title: "Generator Test",
}
}

6 changes: 3 additions & 3 deletions model/jsondata.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type jsonData struct {
func NewJsonData(pageData *generator.PageData) (jsonPageData *jsonData) {
jsonPageData = new(jsonData)
jsonPageData.Title = pageData.Title
jsonPageData.TestState = make(map[string]*testState, len(*pageData.SomeMap))
for k, v := range *pageData.SomeMap {
jsonPageData.TestState[k] = NewTestState(v)
jsonPageData.TestState = make(map[string]*testState, len(pageData.TestResults))
for k, v := range pageData.TestResults {
jsonPageData.TestState[k] = NewTestState(*v)
}
return
}
14 changes: 8 additions & 6 deletions model/testresults.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package model

import "github.com/corbym/gogiven/base"
import (
"github.com/corbym/gogiven/generator"
)

type testResults struct {
Id string `json:"id"`
Expand All @@ -10,10 +12,10 @@ type testResults struct {
}

//NewTestResults is internal and creates a new json data object for marshalling test data
func NewTestResults(data *base.TestMetaData) *testResults {
return &testResults{Failed: data.Failed(),
TestOutput: data.TestOutput(),
Id: data.TestId,
Skipped: data.Skipped(),
func NewTestResults(data *generator.TestResult) *testResults {
return &testResults{Failed: data.Failed,
TestOutput: data.TestOutput,
Id: data.TestId,
Skipped: data.Skipped,
}
}
14 changes: 7 additions & 7 deletions model/teststate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package model

import (
"fmt"
"github.com/corbym/gogiven/base"
"github.com/corbym/gogiven/generator"
)

type testState struct {
Expand All @@ -14,13 +14,13 @@ type testState struct {
}

//NewTestState is internal and creates a new json data object for marshalling test data
func NewTestState(some *base.Some) *testState {
func NewTestState(testData generator.TestData) *testState {
return &testState{
TestResults: NewTestResults(some.TestingT),
TestTitle: some.TestTitle,
InterestingGivens: convertToMapStringInterface(some.InterestingGivens()),
CapturedIO: convertToMapStringInterface(some.CapturedIO()),
GivenWhenThen: some.GivenWhenThen,
TestResults: NewTestResults(testData.TestResult),
TestTitle: testData.TestTitle,
InterestingGivens: convertToMapStringInterface(testData.InterestingGivens),
CapturedIO: convertToMapStringInterface(testData.CapturedIO),
GivenWhenThen: testData.GivenWhenThen,
}
}

Expand Down

0 comments on commit ea771f1

Please sign in to comment.