func (matcher *MatchYAMLMatcher) equal(expected interface{}, actual interface{}) (bool, string, error) {
	actualString, err := matcher.prettyPrint(actual)
	if err != nil {
		return false, "", err
	}

	expectedString, err := matcher.prettyPrint(expected)
	if err != nil {
		return false, "", err
	}

	var actualValue interface{}
	var expectedValue interface{}

	// this is guarded by prettyPrint
	yaml.Unmarshal([]byte(actualString), &actualValue)
	yaml.Unmarshal([]byte(expectedString), &expectedValue)

	equal, difference := deepequal.Compare(expectedValue, actualValue)

	return equal, prettyprint.ExpectationFailure(difference), nil
}
import (
	"reflect"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-cf-experimental/gomegamatchers/internal/diff"
	"github.com/pivotal-cf-experimental/gomegamatchers/internal/prettyprint"
)

var _ = Describe("ExpectationFailure", func() {
	It("formats complex diffs correctly", func() {
		failure := prettyprint.ExpectationFailure(diff.MapNested{
			Key: "colors",
			NestedDifference: diff.SliceNested{
				Index: 2,
				NestedDifference: diff.PrimitiveValueMismatch{
					ExpectedValue: "blue",
					ActualValue:   "red",
				},
			},
		})

		Expect(failure).To(ContainSubstring("error at [colors][2]:"))
		Expect(failure).To(ContainSubstring("  value mismatch:"))
		Expect(failure).To(ContainSubstring("    Expected"))
		Expect(failure).To(ContainSubstring("        <string> red"))
		Expect(failure).To(ContainSubstring("    to equal"))
		Expect(failure).To(ContainSubstring("        <string> blue"))
	})

	It("returns an empty string when there is no difference", func() {
		failure := prettyprint.ExpectationFailure(diff.NoDifference{})