initial commit
[govpp.git] / vendor / github.com / onsi / gomega / matchers / panic_matcher_test.go
1 package matchers_test
2
3 import (
4         . "github.com/onsi/ginkgo"
5         . "github.com/onsi/gomega"
6         . "github.com/onsi/gomega/matchers"
7 )
8
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())
15
16                         success, err = (&PanicMatcher{}).Match(nil)
17                         Ω(success).Should(BeFalse())
18                         Ω(err).Should(HaveOccurred())
19
20                         success, err = (&PanicMatcher{}).Match(func(foo string) {})
21                         Ω(success).Should(BeFalse())
22                         Ω(err).Should(HaveOccurred())
23
24                         success, err = (&PanicMatcher{}).Match(func() string { return "bar" })
25                         Ω(success).Should(BeFalse())
26                         Ω(err).Should(HaveOccurred())
27                 })
28         })
29
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())
34                 })
35         })
36
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())
41                         })
42                         Ω(failuresMessages).Should(ConsistOf(MatchRegexp("not to panic, but panicked with\\s*<string>: ack!")))
43                 })
44         })
45 })