godog icon indicating copy to clipboard operation
godog copied to clipboard

integration with gomega

Open charlierudolph opened this issue 8 years ago • 2 comments

Would love to have this so can have more expressive steps that don't need to reinvent the error logic.

https://github.com/onsi/gomega

I'm happy to work on this if you can give any pointers on where to start

charlierudolph avatar Aug 24 '17 05:08 charlierudolph

Hi @charlierudolph nice to see you using go. regarding matchers, I will not add them as a hard dependency in godog it should be simple as it is, even if it is boring to check errors. Others prefer different libraries and godog should not advocate any and be based only on standard go ways.

Every godog step definition func must either return error or multi steps, you may combine any kind of matchers and nest them as long as they return an error. I think with some of the assertion libraries it is the right flow, but that should be simply an extension which you either prefer or not.

Do you have some specific ideas around integration?

l3pp4rd avatar Aug 24 '17 06:08 l3pp4rd

if anyone else is looking for a way of integrating godog with gomega today, I've found the following to work quite well:

func shouldBeBar(foo string) (err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("%s", r)
        }
    }()

    Expect(foo).Should(Equal("bar"))

    return err
}

where the gomega fail handler is simply registered to panic

gomega.RegisterFailHandler(func(message string, _ ...int) {
	panic(message)
})

matt-simons avatar Feb 19 '21 12:02 matt-simons