package util

import (
	"errors"

	. "github.com/onsi/ginkgo"
)

// WithGinkgoRecover wraps an assertion function and returns an error
// if the assertion fails.
//
// WithGinkgoRecover is often used with errgroup to implement fastfail.
// Check out testcase/examples for usage example.
func WithGinkgoRecover(f func()) func() error {
	return func() (err error) {
		defer GinkgoRecover()
		err = errors.New("the wrapped function failed")
		f()
		err = nil
		return
	}
}
