parser.On("ParseV1_0_0", data).Return(mockSchema, expectedError) }) Context("when the ParseV1_0_0 will not be called", func() { It("should not call it when passing in 1.0", func() { Parse(parser, []byte(`schema_version: "1.0"`)) parser.AssertNotCalled(GinkgoT(), "ParseV1_0_0", data) }) }) Context("when the ParseV1_0_0 will is called", func() { BeforeEach(func() { data = []byte(`schema_version: "1.0.0"`) }) Context("when ParseV1_0_0 is passed valid data", func() { It("should call ParseV1_0_0", func() { _, err = Parse(parser, data) parser.AssertCalled(GinkgoT(), "ParseV1_0_0", data) assert.Equal(GinkgoT(), expectedError, err) }) }) Context("when ParseV1_0_0 is passed invalid data", func() { BeforeEach(func() { expectedError = errors.New("can't parse yaml") }) It("should call ParseV1_0_0 but return an error", func() { _, err = Parse(parser, data) parser.AssertCalled(GinkgoT(), "ParseV1_0_0", data) assert.Equal(GinkgoT(), expectedError, err) }) }) }) })