From 59c2cd36b3c6b42b210df5d26f0ec0e455799d66 Mon Sep 17 00:00:00 2001 From: Matt Corby Date: Wed, 24 Jan 2018 22:27:15 +0000 Subject: [PATCH] updateing based on latest gogivens --- generator_test.go | 7 +++++-- htmlgenerator.go | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/generator_test.go b/generator_test.go index 7ea97c4..41fd14f 100644 --- a/generator_test.go +++ b/generator_test.go @@ -6,6 +6,7 @@ import ( "github.com/corbym/gogiven/generator" "github.com/corbym/htmlspec" "testing" + "bytes" ) var html string @@ -43,7 +44,7 @@ func TestTestOutputGenerator_GenerateConcurrently(testing *testing.T) { } func TestTestOutputGenerator_FileExtension(t *testing.T) { - AssertThat(t, underTest.FileExtension(), is.EqualTo(".html")) + AssertThat(t, underTest.ContentType(), is.EqualTo("text/html")) } func TestTestOutputGenerator_Panics(t *testing.T) { @@ -56,7 +57,9 @@ func TestTestOutputGenerator_Panics(t *testing.T) { } func fileIsConvertedToHtml() { - html = underTest.Generate(newPageData(true, true)) + buffer := new(bytes.Buffer) + buffer.ReadFrom(underTest.Generate(newPageData(true, true))) + html = buffer.String() } func newPageData(skipped bool, failed bool) *generator.PageData { diff --git a/htmlgenerator.go b/htmlgenerator.go index 096ab4c..cdbc6d2 100644 --- a/htmlgenerator.go +++ b/htmlgenerator.go @@ -6,6 +6,7 @@ import ( "html/template" "os" "path/filepath" + "io" ) const goPathEnvKey = "GOPATH" @@ -36,18 +37,18 @@ func NewTestOutputGenerator() *TestOutputGenerator { } // FileExtension for the output generated. -func (outputGenerator *TestOutputGenerator) FileExtension() string { - return ".html" +func (outputGenerator *TestOutputGenerator) ContentType() string { + return "text/html" } // Generate generates html output for a test. The return string contains the html // that goes into the output file generated in gogivens.GenerateTestOutput(). // The function panics if the template cannot be generated. -func (outputGenerator *TestOutputGenerator) Generate(pageData *generator.PageData) string { +func (outputGenerator *TestOutputGenerator) Generate(pageData *generator.PageData) io.Reader { var buffer = new(bytes.Buffer) err := outputGenerator.template.ExecuteTemplate(buffer, baseTemplateName, pageData) if err != nil { panic(err.Error()) } - return buffer.String() + return buffer }