github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/api/apiMessageHandler_test.go (about)

     1  // Copyright 2015 ThoughtWorks, Inc.
     2  
     3  // This file is part of Gauge.
     4  
     5  // Gauge is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  
    10  // Gauge is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  
    15  // You should have received a copy of the GNU General Public License
    16  // along with Gauge.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package api
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/getgauge/gauge/api/infoGatherer"
    24  	"github.com/getgauge/gauge/gauge"
    25  	"github.com/getgauge/gauge/gauge_messages"
    26  	"github.com/getgauge/gauge/parser"
    27  	. "gopkg.in/check.v1"
    28  )
    29  
    30  func Test(t *testing.T) { TestingT(t) }
    31  
    32  type MySuite struct{}
    33  
    34  var _ = Suite(&MySuite{})
    35  
    36  func (s *MySuite) TestCreateSpecsResponseMessageFor(c *C) {
    37  	h := &gaugeAPIMessageHandler{}
    38  	m := h.createSpecsResponseMessageFor([]*infoGatherer.SpecDetail{
    39  		{
    40  			Spec: &gauge.Specification{Heading: &gauge.Heading{Value: "Spec heading 1"}},
    41  			Errs: []parser.ParseError{{Message: "Scenario1 not found"}, {Message: "Scenario2 not found"}},
    42  		},
    43  		{
    44  			Spec: &gauge.Specification{},
    45  			Errs: []parser.ParseError{{Message: "Scenarios not found"}},
    46  		},
    47  		{
    48  			Spec: &gauge.Specification{Heading: &gauge.Heading{Value: "Spec heading 2"}},
    49  		},
    50  	})
    51  
    52  	var nilSpec *gauge_messages.ProtoSpec
    53  
    54  	c.Assert(len(m.GetDetails()), Equals, 3)
    55  	c.Assert(len(m.GetDetails()[0].ParseErrors), Equals, 2)
    56  	c.Assert(m.GetDetails()[0].Spec.GetSpecHeading(), Equals, "Spec heading 1")
    57  	c.Assert(len(m.GetDetails()[1].ParseErrors), Equals, 1)
    58  	c.Assert(m.GetDetails()[1].GetSpec(), Equals, nilSpec)
    59  	c.Assert(len(m.GetDetails()[2].ParseErrors), Equals, 0)
    60  	c.Assert(m.GetDetails()[2].Spec.GetSpecHeading(), Equals, "Spec heading 2")
    61  }