51 | 51 |
})
|
52 | 52 |
|
53 | 53 |
var _ = Describe("PanicWith", func() {
|
54 | |
When("passed a function of the correct type", func() {
|
55 | |
It("should call the function and pass if the function panics with the expected value", func() {
|
56 | |
Expect(func() { panic("ack!") }).To(PanicWith("ack!"))
|
57 | |
Expect(func() {}).NotTo(PanicWith("ack!"))
|
|
54 |
When("a specific panic value is expected", func() {
|
|
55 |
matcher := PanicWith("ack!")
|
|
56 |
|
|
57 |
When("no panic occurs", func() {
|
|
58 |
actual := func() {}
|
|
59 |
|
|
60 |
It("prints a message that includes the expected value", func() {
|
|
61 |
failuresMessages := InterceptGomegaFailures(func() {
|
|
62 |
Expect(actual).To(matcher)
|
|
63 |
})
|
|
64 |
Expect(failuresMessages).To(ConsistOf(
|
|
65 |
MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nto panic with\\s+<string>: ack!"),
|
|
66 |
))
|
|
67 |
})
|
|
68 |
|
|
69 |
It("passes when negated", func() {
|
|
70 |
Expect(actual).NotTo(matcher)
|
|
71 |
})
|
|
72 |
})
|
|
73 |
|
|
74 |
When("the panic value matches", func() {
|
|
75 |
actual := func() { panic("ack!") }
|
|
76 |
|
|
77 |
It("passes", func() {
|
|
78 |
Expect(actual).To(matcher)
|
|
79 |
})
|
|
80 |
|
|
81 |
It("prints a message that includes the (un)expected value when negated", func() {
|
|
82 |
failuresMessages := InterceptGomegaFailures(func() {
|
|
83 |
Expect(actual).NotTo(matcher)
|
|
84 |
})
|
|
85 |
Expect(failuresMessages).To(ConsistOf(
|
|
86 |
MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nnot to panic with\\s+<string>: ack!"),
|
|
87 |
))
|
|
88 |
})
|
|
89 |
})
|
|
90 |
|
|
91 |
When("the panic value does not match", func() {
|
|
92 |
actual := func() { panic("unexpected!") }
|
|
93 |
|
|
94 |
It("prints a message that includes both the actual and expected values", func() {
|
|
95 |
failuresMessages := InterceptGomegaFailures(func() {
|
|
96 |
Expect(actual).To(matcher)
|
|
97 |
})
|
|
98 |
Expect(failuresMessages).To(ConsistOf(
|
|
99 |
MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nto panic with\\s+<string>: ack!\nbut panicked with\n\\s+<string>: unexpected!"),
|
|
100 |
))
|
|
101 |
})
|
|
102 |
|
|
103 |
It("passes when negated", func() {
|
|
104 |
Expect(actual).NotTo(matcher)
|
|
105 |
})
|
58 | 106 |
})
|
59 | 107 |
})
|
60 | 108 |
|
61 | |
When("assertion fails", func() {
|
62 | |
It("prints simple message when positive", func() {
|
63 | |
failuresMessages := InterceptGomegaFailures(func() {
|
64 | |
Expect(func() {}).To(PanicWith("ack!"))
|
|
109 |
When("the expected value is actually a matcher", func() {
|
|
110 |
matcher := PanicWith(MatchRegexp("ack"))
|
|
111 |
|
|
112 |
When("no panic occurs", func() {
|
|
113 |
actual := func() {}
|
|
114 |
|
|
115 |
It("prints a message that includes the expected value", func() {
|
|
116 |
failuresMessages := InterceptGomegaFailures(func() {
|
|
117 |
Expect(actual).To(matcher)
|
|
118 |
})
|
|
119 |
Expect(failuresMessages).To(ConsistOf(
|
|
120 |
MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nto panic with a value matching\n.+MatchRegexpMatcher.+ack"),
|
|
121 |
))
|
65 | 122 |
})
|
66 | |
Expect(failuresMessages).To(ConsistOf(MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nto panic with\\s+<string>: ack!")))
|
|
123 |
|
|
124 |
It("passes when negated", func() {
|
|
125 |
Expect(actual).NotTo(matcher)
|
|
126 |
})
|
67 | 127 |
})
|
68 | 128 |
|
69 | |
It("prints simple message when negative", func() {
|
70 | |
failuresMessages := InterceptGomegaFailures(func() {
|
71 | |
Expect(func() { panic("ack!") }).NotTo(PanicWith("ack!"))
|
|
129 |
When("the panic value matches", func() {
|
|
130 |
actual := func() { panic("ack!") }
|
|
131 |
|
|
132 |
It("passes", func() {
|
|
133 |
Expect(actual).To(matcher)
|
72 | 134 |
})
|
73 | |
Expect(failuresMessages).To(ConsistOf(MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nnot to panic with\\s+<string>: ack!")))
|
|
135 |
|
|
136 |
It("prints a message that includes the (un)expected value when negated", func() {
|
|
137 |
failuresMessages := InterceptGomegaFailures(func() {
|
|
138 |
Expect(actual).NotTo(matcher)
|
|
139 |
})
|
|
140 |
Expect(failuresMessages).To(ConsistOf(
|
|
141 |
MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nnot to panic with a value matching\n.+MatchRegexpMatcher.+ack"),
|
|
142 |
))
|
|
143 |
})
|
74 | 144 |
})
|
75 | 145 |
|
76 | |
When("the expected value is actually a matcher", func() {
|
77 | |
It("prints simple message when positive", func() {
|
|
146 |
When("the panic value does not match", func() {
|
|
147 |
actual := func() { panic("unexpected!") }
|
|
148 |
|
|
149 |
It("prints a message that includes both the actual and expected values", func() {
|
78 | 150 |
failuresMessages := InterceptGomegaFailures(func() {
|
79 | |
Expect(func() {}).To(PanicWith(Equal("ack!")))
|
|
151 |
Expect(actual).To(matcher)
|
80 | 152 |
})
|
81 | |
Expect(failuresMessages).To(ConsistOf(MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nto panic with a value matching\n.+EqualMatcher.+ack!")))
|
|
153 |
Expect(failuresMessages).To(ConsistOf(
|
|
154 |
MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nto panic with a value matching\n.+MatchRegexpMatcher.+ack.+\nbut panicked with\n\\s+<string>: unexpected!"),
|
|
155 |
))
|
82 | 156 |
})
|
83 | 157 |
|
84 | |
It("prints the object passed to panic() when negative", func() {
|
85 | |
failuresMessages := InterceptGomegaFailures(func() {
|
86 | |
Expect(func() { panic("ack!") }).NotTo(PanicWith(MatchRegexp("ack")))
|
87 | |
})
|
88 | |
Expect(failuresMessages).To(ConsistOf(
|
89 | |
MatchRegexp("Expected\n\\s+<func\\(\\)>: .+\nnot to panic with a value matching\n.+MatchRegexpMatcher.+ack.+\nbut panicked with\n <string>: ack!"),
|
90 | |
))
|
|
158 |
It("passes when negated", func() {
|
|
159 |
Expect(actual).NotTo(matcher)
|
91 | 160 |
})
|
92 | 161 |
})
|
93 | 162 |
})
|