Repository: getgauge/gauge (go)

Issue:
Before spec messages not rendered for multi-row table-driven specs
### Expected behavior
Calls to `Gauge.writeMessage`  in a before spec hook should always result in a message at the top of the spec

### Actual behavior
For table driven specs, the message is only rendered when the table has a single row

**Multi-item table**
<img width="698" alt="image" src="https://user-images.githubusercontent.com/41190821/84746609-26e60300-afae-11ea-8543-50b1e8d7567b.png">

**Single-item table**
<img width="793" alt="image" src="https://user-images.githubusercontent.com/41190821/84746675-42510e00-afae-11ea-9d96-ec6a18822ae8.png">

### Steps to reproduce
1. Create a before spec hook which calls `Gauge.writeMessage`
```java
    @BeforeSpec
    public void beforeSpec() {
        Gauge.writeMessage("Before spec message");
    }

```
2. Create a spec with a multiple table items (and create the dummy step referenced)
```markdown
# Demo the bug with tables
Tags: demo, demo-bug

  | text |
  |------|
  | foo  |
  | bar  |

## Print scenario
* Print the text <text>
```
3. Inspect the report, the message does not appear

### Gauge version
```
Gauge version: 1.0.8
Commit Hash: 28617ea

Plugins
-------
html-report (4.0.10)
java (0.7.7)
```


Pull request description:
Add pre/post spec messages to result when merging tables #1676
Fixes #1676 

Patch:
diff --git a/execution/merge.go b/execution/merge.go
index 5d02ba1c..4df5cf1a 100644
--- a/execution/merge.go
+++ b/execution/merge.go
@@ -62,7 +62,11 @@ func hasTableDrivenSpec(results []*result.SpecResult) bool {
 }
 
 func mergeResults(results []*result.SpecResult) *result.SpecResult {
-	specResult := &result.SpecResult{ProtoSpec: &m.ProtoSpec{IsTableDriven: hasTableDrivenSpec(results)}}
+	specResult := &result.SpecResult{ProtoSpec: &m.ProtoSpec{
+		IsTableDriven:    hasTableDrivenSpec(results),
+		PreHookMessages:  results[0].ProtoSpec.PreHookMessages,
+		PostHookMessages: results[len(results)-1].ProtoSpec.PostHookMessages,
+	}}
 	var scnResults []*m.ProtoItem
 	table := &m.ProtoTable{}
 	dataTableScnResults := make(map[string][]*m.ProtoTableDrivenScenario)


Test patch:
diff --git a/execution/merge_test.go b/execution/merge_test.go
index a8dcd332..bfe11840 100644
--- a/execution/merge_test.go
+++ b/execution/merge_test.go
@@ -203,7 +203,7 @@ func TestMergeSkippedResults(t *testing.T) {
 	got := mergeResults([]*result.SpecResult{
 		{
 			ProtoSpec: &gm.ProtoSpec{
-				SpecHeading:     "heading", FileName: "filename", Tags: []string{"tags"},
+				SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},
 				Items: []*gm.ProtoItem{
 					{ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}}}},
 					{ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, ScenarioHeading: "scenario Heading1", SkipErrors: []string{"error"}}},
@@ -219,7 +219,7 @@ func TestMergeSkippedResults(t *testing.T) {
 		},
 		{
 			ProtoSpec: &gm.ProtoSpec{
-				SpecHeading:     "heading", FileName: "filename", Tags: []string{"tags"},
+				SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},
 				Items: []*gm.ProtoItem{
 					{ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"c"}}}}},
 					{
@@ -235,7 +235,7 @@ func TestMergeSkippedResults(t *testing.T) {
 	})
 	want := &result.SpecResult{
 		ProtoSpec: &gm.ProtoSpec{
-			SpecHeading:     "heading", FileName: "filename", Tags: []string{"tags"},
+			SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},
 			Items: []*gm.ProtoItem{
 				{ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}, {Cells: []string{"c"}}}}},
 				{ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, SkipErrors: []string{"error"}, ScenarioHeading: "scenario Heading1"}},
@@ -392,3 +392,54 @@ func TestHasTableDrivenSpec(t *testing.T) {
 		}
 	}
 }
+
+func TestMergeResultWithMesages(t *testing.T) {
+	got := mergeResults([]*result.SpecResult{
+		{
+			ProtoSpec: &gm.ProtoSpec{
+				PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}},
+				SpecHeading:     "heading", FileName: "filename", Tags: []string{"tags"},
+				Items: []*gm.ProtoItem{
+					{ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}}}},
+				},
+				PreHookMessages: []string{"Hello"},
+			}, ExecutionTime: int64(1),
+		},
+		{
+			ProtoSpec: &gm.ProtoSpec{
+				PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace1"}},
+				SpecHeading:     "heading", FileName: "filename", Tags: []string{"tags"},
+				Items: []*gm.ProtoItem{
+					{ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"d"}}}}},
+				},
+			}, ExecutionTime: int64(2),
+		},
+		{
+			ProtoSpec: &gm.ProtoSpec{
+				PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace2"}},
+				SpecHeading:     "heading", FileName: "filename", Tags: []string{"tags"},
+				Items: []*gm.ProtoItem{
+					{ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"c"}}}}},
+				},
+				PostHookMessages: []string{"Bye"},
+			}, ExecutionTime: int64(2),
+		},
+	})
+	want := &result.SpecResult{
+		ProtoSpec: &gm.ProtoSpec{
+			PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}, {StackTrace: "stacktrace1", TableRowIndex: 1}, {StackTrace: "stacktrace2", TableRowIndex: 2}},
+			SpecHeading:     "heading", FileName: "filename", Tags: []string{"tags"},
+			Items: []*gm.ProtoItem{
+				{ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}, {Cells: []string{"d"}}, {Cells: []string{"c"}}}}},
+			},
+			PreHookMessages:  []string{"Hello"},
+			PostHookMessages: []string{"Bye"},
+			IsTableDriven: false,
+		},
+		ScenarioCount: 0, ScenarioSkippedCount: 0, ScenarioFailedCount: 0, IsFailed: false, Skipped: false, ExecutionTime: int64(5),
+	}
+
+	if !reflect.DeepEqual(got, want) {
+		t.Errorf("Merge data table spec results failed.\n\tWant: %v\n\tGot: %v", want, got)
+	}
+}