4 . "github.com/onsi/ginkgo"
5 . "github.com/onsi/gomega"
6 . "github.com/onsi/gomega/matchers"
9 var _ = Describe("Panic", func() {
10 Context("when passed something that's not a function that takes zero arguments and returns nothing", func() {
11 It("should error", func() {
12 success, err := (&PanicMatcher{}).Match("foo")
13 Ω(success).Should(BeFalse())
14 Ω(err).Should(HaveOccurred())
16 success, err = (&PanicMatcher{}).Match(nil)
17 Ω(success).Should(BeFalse())
18 Ω(err).Should(HaveOccurred())
20 success, err = (&PanicMatcher{}).Match(func(foo string) {})
21 Ω(success).Should(BeFalse())
22 Ω(err).Should(HaveOccurred())
24 success, err = (&PanicMatcher{}).Match(func() string { return "bar" })
25 Ω(success).Should(BeFalse())
26 Ω(err).Should(HaveOccurred())
30 Context("when passed a function of the correct type", func() {
31 It("should call the function and pass if the function panics", func() {
32 Ω(func() { panic("ack!") }).Should(Panic())
33 Ω(func() {}).ShouldNot(Panic())
37 Context("when assertion fails", func() {
38 It("should print the object passed to Panic", func() {
39 failuresMessages := InterceptGomegaFailures(func() {
40 Ω(func() { panic("ack!") }).ShouldNot(Panic())
42 Ω(failuresMessages).Should(ConsistOf(MatchRegexp("not to panic, but panicked with\\s*<string>: ack!")))