rspec 1.2.9 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +34 -1
- data/License.txt +1 -1
- data/Manifest.txt +11 -4
- data/README.rdoc +2 -3
- data/Rakefile +17 -13
- data/Upgrade.rdoc +63 -2
- data/features/formatters/nested_formatter.feature +32 -0
- data/features/interop/cucumber_stubs_dont_leak.feature +11 -0
- data/features/matchers/define_matcher_with_fluent_interface.feature +21 -0
- data/features/matchers/define_wrapped_matcher.feature +28 -1
- data/features/matchers/match_unless_raises.feature +60 -0
- data/features/matchers/match_unless_raises_unexpected_error.feature +39 -0
- data/features/mocks/block_local_expectations.feature +62 -0
- data/features/step_definitions/running_rspec_steps.rb +9 -0
- data/features/step_definitions/stubbing_steps.rb +16 -0
- data/features/support/env.rb +1 -0
- data/features/support/matchers/smart_match.rb +23 -4
- data/geminstaller.yml +28 -0
- data/lib/autotest/rspec.rb +14 -7
- data/lib/spec/dsl/main.rb +1 -1
- data/lib/spec/example/example_methods.rb +4 -0
- data/lib/spec/{matchers/extensions → extensions}/instance_exec.rb +0 -0
- data/lib/spec/interop/test.rb +1 -1
- data/lib/spec/matchers.rb +21 -2
- data/lib/spec/matchers/be.rb +167 -128
- data/lib/spec/matchers/has.rb +3 -3
- data/lib/spec/matchers/have.rb +1 -0
- data/lib/spec/matchers/matcher.rb +55 -10
- data/lib/spec/matchers/method_missing.rb +2 -2
- data/lib/spec/matchers/raise_exception.rb +131 -0
- data/lib/spec/matchers/throw_symbol.rb +16 -20
- data/lib/spec/mocks/message_expectation.rb +63 -48
- data/lib/spec/mocks/methods.rb +13 -8
- data/lib/spec/mocks/proxy.rb +43 -22
- data/lib/spec/runner/differs/default.rb +1 -1
- data/lib/spec/runner/drb_command_line.rb +8 -2
- data/lib/spec/runner/example_group_runner.rb +1 -2
- data/lib/spec/runner/formatter/nested_text_formatter.rb +6 -3
- data/lib/spec/runner/option_parser.rb +2 -0
- data/lib/spec/runner/options.rb +6 -1
- data/lib/spec/stubs/cucumber.rb +2 -2
- data/lib/spec/version.rb +2 -2
- data/spec/autotest/autotest_helper.rb +1 -1
- data/spec/autotest/discover_spec.rb +2 -2
- data/spec/autotest/failed_results_re_spec.rb +2 -2
- data/spec/autotest/rspec_spec.rb +21 -6
- data/spec/spec/example/example_group_methods_spec.rb +2 -1
- data/spec/spec/interop/test/unit/spec_spec.rb +7 -7
- data/spec/spec/interop/test/unit/testcase_spec.rb +7 -7
- data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
- data/spec/spec/matchers/be_spec.rb +159 -10
- data/spec/spec/matchers/has_spec.rb +109 -0
- data/spec/spec/matchers/matcher_spec.rb +70 -9
- data/spec/spec/matchers/raise_exception_spec.rb +345 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +83 -58
- data/spec/spec/mocks/and_yield_spec.rb +117 -0
- data/spec/spec/mocks/mock_spec.rb +2 -2
- data/spec/spec/runner/command_line_spec.rb +26 -5
- data/spec/spec/runner/drb_command_line_spec.rb +39 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +35 -11
- data/spec/spec/runner/option_parser_spec.rb +12 -6
- data/spec/spec/runner/options_spec.rb +7 -0
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +23 -5
- metadata +17 -10
- data/lib/spec/matchers/raise_error.rb +0 -129
- data/spec/spec/matchers/matcher_methods_spec.rb +0 -63
- data/spec/spec/matchers/raise_error_spec.rb +0 -333
@@ -0,0 +1,345 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "should raise_exception" do
|
4
|
+
it "should pass if anything is raised" do
|
5
|
+
lambda {raise}.should raise_exception
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should fail if nothing is raised" do
|
9
|
+
lambda {
|
10
|
+
lambda {}.should raise_exception
|
11
|
+
}.should fail_with("expected Exception but nothing was raised")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "should raise_error" do
|
16
|
+
it "should pass if anything is raised" do
|
17
|
+
lambda {raise}.should raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should fail if nothing is raised" do
|
21
|
+
lambda {
|
22
|
+
lambda {}.should raise_error
|
23
|
+
}.should fail_with("expected Exception but nothing was raised")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "should raise_exception {|e| ... }" do
|
28
|
+
it "passes if there is an exception" do
|
29
|
+
ran = false
|
30
|
+
lambda { non_existent_method }.should raise_exception {|e|
|
31
|
+
ran = true
|
32
|
+
}
|
33
|
+
ran.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "passes the exception to the block" do
|
37
|
+
exception = nil
|
38
|
+
lambda { non_existent_method }.should raise_exception {|e|
|
39
|
+
exception = e
|
40
|
+
}
|
41
|
+
exception.should be_kind_of(NameError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "should_not raise_exception" do
|
46
|
+
it "should pass if nothing is raised" do
|
47
|
+
lambda {}.should_not raise_exception
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should fail if anything is raised" do
|
51
|
+
lambda {
|
52
|
+
lambda {raise}.should_not raise_exception
|
53
|
+
}.should fail_with("expected no Exception, got RuntimeError")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "should raise_exception(message)" do
|
58
|
+
it "should pass if RuntimeError is raised with the right message" do
|
59
|
+
lambda {raise 'blah'}.should raise_exception('blah')
|
60
|
+
end
|
61
|
+
it "should pass if RuntimeError is raised with a matching message" do
|
62
|
+
lambda {raise 'blah'}.should raise_exception(/blah/)
|
63
|
+
end
|
64
|
+
it "should pass if any other exception is raised with the right message" do
|
65
|
+
lambda {raise NameError.new('blah')}.should raise_exception('blah')
|
66
|
+
end
|
67
|
+
it "should fail if RuntimeError exception is raised with the wrong message" do
|
68
|
+
lambda do
|
69
|
+
lambda {raise 'blarg'}.should raise_exception('blah')
|
70
|
+
end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
|
71
|
+
end
|
72
|
+
it "should fail if any other exception is raised with the wrong message" do
|
73
|
+
lambda do
|
74
|
+
lambda {raise NameError.new('blarg')}.should raise_exception('blah')
|
75
|
+
end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "should_not raise_exception(message)" do
|
80
|
+
it "should pass if RuntimeError exception is raised with the different message" do
|
81
|
+
lambda {raise 'blarg'}.should_not raise_exception('blah')
|
82
|
+
end
|
83
|
+
it "should pass if any other exception is raised with the wrong message" do
|
84
|
+
lambda {raise NameError.new('blarg')}.should_not raise_exception('blah')
|
85
|
+
end
|
86
|
+
it "should fail if RuntimeError is raised with message" do
|
87
|
+
lambda do
|
88
|
+
lambda {raise 'blah'}.should_not raise_exception('blah')
|
89
|
+
end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
|
90
|
+
end
|
91
|
+
it "should fail if any other exception is raised with message" do
|
92
|
+
lambda do
|
93
|
+
lambda {raise NameError.new('blah')}.should_not raise_exception('blah')
|
94
|
+
end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "should raise_exception(NamedError)" do
|
99
|
+
it "should pass if named exception is raised" do
|
100
|
+
lambda { non_existent_method }.should raise_exception(NameError)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should fail if nothing is raised" do
|
104
|
+
lambda {
|
105
|
+
lambda { }.should raise_exception(NameError)
|
106
|
+
}.should fail_with("expected NameError but nothing was raised")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should fail if another exception is raised (NameError)" do
|
110
|
+
lambda {
|
111
|
+
lambda { raise }.should raise_exception(NameError)
|
112
|
+
}.should fail_with("expected NameError, got RuntimeError")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should fail if another exception is raised (NameError)" do
|
116
|
+
lambda {
|
117
|
+
lambda { load "non/existent/file" }.should raise_exception(NameError)
|
118
|
+
}.should fail_with(/expected NameError, got #<LoadError/)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "should_not raise_exception(NamedError)" do
|
123
|
+
it "should pass if nothing is raised" do
|
124
|
+
lambda { }.should_not raise_exception(NameError)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should pass if another exception is raised" do
|
128
|
+
lambda { raise }.should_not raise_exception(NameError)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should fail if named exception is raised" do
|
132
|
+
lambda {
|
133
|
+
lambda { 1 + 'b' }.should_not raise_exception(TypeError)
|
134
|
+
}.should fail_with(/expected no TypeError, got #<TypeError: String can't be/)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "should raise_exception(NamedError, exception_message) with String" do
|
139
|
+
it "should pass if named exception is raised with same message" do
|
140
|
+
lambda { raise "example message" }.should raise_exception(RuntimeError, "example message")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should fail if nothing is raised" do
|
144
|
+
lambda {
|
145
|
+
lambda {}.should raise_exception(RuntimeError, "example message")
|
146
|
+
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should fail if incorrect exception is raised" do
|
150
|
+
lambda {
|
151
|
+
lambda { raise }.should raise_exception(NameError, "example message")
|
152
|
+
}.should fail_with("expected NameError with \"example message\", got RuntimeError")
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should fail if correct exception is raised with incorrect message" do
|
156
|
+
lambda {
|
157
|
+
lambda { raise RuntimeError.new("not the example message") }.should raise_exception(RuntimeError, "example message")
|
158
|
+
}.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "should raise_exception(NamedError, exception_message) { |err| ... }" do
|
163
|
+
it "should yield exception if named exception is raised with same message" do
|
164
|
+
ran = false
|
165
|
+
|
166
|
+
lambda {
|
167
|
+
raise "example message"
|
168
|
+
}.should raise_exception(RuntimeError, "example message") { |err|
|
169
|
+
ran = true
|
170
|
+
err.class.should == RuntimeError
|
171
|
+
err.message.should == "example message"
|
172
|
+
}
|
173
|
+
|
174
|
+
ran.should == true
|
175
|
+
end
|
176
|
+
|
177
|
+
it "yielded block should be able to fail on it's own right" do
|
178
|
+
ran, passed = false, false
|
179
|
+
|
180
|
+
lambda {
|
181
|
+
lambda {
|
182
|
+
raise "example message"
|
183
|
+
}.should raise_exception(RuntimeError, "example message") { |err|
|
184
|
+
ran = true
|
185
|
+
5.should == 4
|
186
|
+
passed = true
|
187
|
+
}
|
188
|
+
}.should fail_with(/expected: 4/m)
|
189
|
+
|
190
|
+
ran.should == true
|
191
|
+
passed.should == false
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should NOT yield exception if no exception was thrown" do
|
195
|
+
ran = false
|
196
|
+
|
197
|
+
lambda {
|
198
|
+
lambda {}.should raise_exception(RuntimeError, "example message") { |err|
|
199
|
+
ran = true
|
200
|
+
}
|
201
|
+
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
202
|
+
|
203
|
+
ran.should == false
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should not yield exception if exception class is not matched" do
|
207
|
+
ran = false
|
208
|
+
|
209
|
+
lambda {
|
210
|
+
lambda {
|
211
|
+
raise "example message"
|
212
|
+
}.should raise_exception(SyntaxError, "example message") { |err|
|
213
|
+
ran = true
|
214
|
+
}
|
215
|
+
}.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
|
216
|
+
|
217
|
+
ran.should == false
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should NOT yield exception if exception message is not matched" do
|
221
|
+
ran = false
|
222
|
+
|
223
|
+
lambda {
|
224
|
+
lambda {
|
225
|
+
raise "example message"
|
226
|
+
}.should raise_exception(RuntimeError, "different message") { |err|
|
227
|
+
ran = true
|
228
|
+
}
|
229
|
+
}.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
|
230
|
+
|
231
|
+
ran.should == false
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "should_not raise_exception(NamedError, exception_message) { |err| ... }" do
|
236
|
+
it "should pass if nothing is raised" do
|
237
|
+
ran = false
|
238
|
+
|
239
|
+
lambda {}.should_not raise_exception(RuntimeError, "example message") { |err|
|
240
|
+
ran = true
|
241
|
+
}
|
242
|
+
|
243
|
+
ran.should == false
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should pass if a different exception is raised" do
|
247
|
+
ran = false
|
248
|
+
|
249
|
+
lambda { raise }.should_not raise_exception(NameError, "example message") { |err|
|
250
|
+
ran = true
|
251
|
+
}
|
252
|
+
|
253
|
+
ran.should == false
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should pass if same exception is raised with different message" do
|
257
|
+
ran = false
|
258
|
+
|
259
|
+
lambda {
|
260
|
+
raise RuntimeError.new("not the example message")
|
261
|
+
}.should_not raise_exception(RuntimeError, "example message") { |err|
|
262
|
+
ran = true
|
263
|
+
}
|
264
|
+
|
265
|
+
ran.should == false
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should fail if named exception is raised with same message" do
|
269
|
+
ran = false
|
270
|
+
|
271
|
+
lambda {
|
272
|
+
lambda {
|
273
|
+
raise "example message"
|
274
|
+
}.should_not raise_exception(RuntimeError, "example message") { |err|
|
275
|
+
ran = true
|
276
|
+
}
|
277
|
+
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
278
|
+
|
279
|
+
ran.should == false
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "should_not raise_exception(NamedError, exception_message) with String" do
|
284
|
+
it "should pass if nothing is raised" do
|
285
|
+
lambda {}.should_not raise_exception(RuntimeError, "example message")
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should pass if a different exception is raised" do
|
289
|
+
lambda { raise }.should_not raise_exception(NameError, "example message")
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should pass if same exception is raised with different message" do
|
293
|
+
lambda { raise RuntimeError.new("not the example message") }.should_not raise_exception(RuntimeError, "example message")
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should fail if named exception is raised with same message" do
|
297
|
+
lambda {
|
298
|
+
lambda { raise "example message" }.should_not raise_exception(RuntimeError, "example message")
|
299
|
+
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe "should raise_exception(NamedError, exception_message) with Regexp" do
|
304
|
+
it "should pass if named exception is raised with matching message" do
|
305
|
+
lambda { raise "example message" }.should raise_exception(RuntimeError, /ample mess/)
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should fail if nothing is raised" do
|
309
|
+
lambda {
|
310
|
+
lambda {}.should raise_exception(RuntimeError, /ample mess/)
|
311
|
+
}.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should fail if incorrect exception is raised" do
|
315
|
+
lambda {
|
316
|
+
lambda { raise }.should raise_exception(NameError, /ample mess/)
|
317
|
+
}.should fail_with("expected NameError with message matching /ample mess/, got RuntimeError")
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should fail if correct exception is raised with incorrect message" do
|
321
|
+
lambda {
|
322
|
+
lambda { raise RuntimeError.new("not the example message") }.should raise_exception(RuntimeError, /less than ample mess/)
|
323
|
+
}.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
describe "should_not raise_exception(NamedError, exception_message) with Regexp" do
|
328
|
+
it "should pass if nothing is raised" do
|
329
|
+
lambda {}.should_not raise_exception(RuntimeError, /ample mess/)
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should pass if a different exception is raised" do
|
333
|
+
lambda { raise }.should_not raise_exception(NameError, /ample mess/)
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should pass if same exception is raised with non-matching message" do
|
337
|
+
lambda { raise RuntimeError.new("non matching message") }.should_not raise_exception(RuntimeError, /ample mess/)
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should fail if named exception is raised with matching message" do
|
341
|
+
lambda {
|
342
|
+
lambda { raise "example message" }.should_not raise_exception(RuntimeError, /ample mess/)
|
343
|
+
}.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
|
344
|
+
end
|
345
|
+
end
|
@@ -4,91 +4,116 @@ module Spec
|
|
4
4
|
module Matchers
|
5
5
|
describe ThrowSymbol do
|
6
6
|
describe "with no args" do
|
7
|
-
|
8
|
-
|
9
|
-
it "
|
10
|
-
|
7
|
+
let(:matcher) { ThrowSymbol.new }
|
8
|
+
|
9
|
+
it "matches if any Symbol is thrown" do
|
10
|
+
matcher.matches?(lambda{ throw :sym }).should be_true
|
11
11
|
end
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
it "matches if any Symbol is thrown with an arg" do
|
14
|
+
matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
|
14
15
|
end
|
15
|
-
|
16
|
-
|
16
|
+
|
17
|
+
it "does not match if no Symbol is thrown" do
|
18
|
+
matcher.matches?(lambda{ }).should be_false
|
17
19
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
|
21
|
+
it "provides a failure message" do
|
22
|
+
matcher.matches?(lambda{})
|
23
|
+
matcher.failure_message_for_should.should == "expected a Symbol but nothing was thrown"
|
21
24
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
|
26
|
+
it "provides a negative failure message" do
|
27
|
+
matcher.matches?(lambda{ throw :sym})
|
28
|
+
matcher.failure_message_for_should_not.should == "expected no Symbol, got :sym"
|
25
29
|
end
|
26
30
|
end
|
27
|
-
|
31
|
+
|
28
32
|
describe "with a symbol" do
|
29
|
-
|
30
|
-
|
31
|
-
it "
|
32
|
-
|
33
|
+
let(:matcher) { ThrowSymbol.new(:sym) }
|
34
|
+
|
35
|
+
it "matches if correct Symbol is thrown" do
|
36
|
+
matcher.matches?(lambda{ throw :sym }).should be_true
|
33
37
|
end
|
34
|
-
|
35
|
-
|
38
|
+
|
39
|
+
it "matches if correct Symbol is thrown with an arg" do
|
40
|
+
matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
|
36
41
|
end
|
37
|
-
|
38
|
-
|
42
|
+
|
43
|
+
it "does not match if no Symbol is thrown" do
|
44
|
+
matcher.matches?(lambda{ }).should be_false
|
39
45
|
end
|
40
|
-
|
41
|
-
|
46
|
+
|
47
|
+
it "does not match if correct Symbol is thrown" do
|
48
|
+
matcher.matches?(lambda{ throw :other_sym }).should be_false
|
42
49
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
|
51
|
+
it "provides a failure message when no Symbol is thrown" do
|
52
|
+
matcher.matches?(lambda{})
|
53
|
+
matcher.failure_message_for_should.should == "expected :sym but nothing was thrown"
|
46
54
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
55
|
+
|
56
|
+
it "provides a failure message when wrong Symbol is thrown" do
|
57
|
+
matcher.matches?(lambda{ throw :other_sym })
|
58
|
+
matcher.failure_message_for_should.should == "expected :sym, got :other_sym"
|
50
59
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
60
|
+
|
61
|
+
it "provides a negative failure message" do
|
62
|
+
matcher.matches?(lambda{ throw :sym })
|
63
|
+
matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
|
54
64
|
end
|
65
|
+
|
55
66
|
it "should only match NameErrors raised by uncaught throws" do
|
56
|
-
|
67
|
+
matcher.matches?(lambda{ :sym }).should be_false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "bubbles up errors other than NameError" do
|
71
|
+
lambda do
|
72
|
+
matcher.matches?(lambda{ raise 'foo' })
|
73
|
+
end.should raise_error('foo')
|
57
74
|
end
|
58
75
|
end
|
59
76
|
|
60
77
|
describe "with a symbol and an arg" do
|
61
|
-
|
62
|
-
|
63
|
-
it "
|
64
|
-
|
78
|
+
let(:matcher) { ThrowSymbol.new(:sym, "a") }
|
79
|
+
|
80
|
+
it "matches if correct Symbol and args are thrown" do
|
81
|
+
matcher.matches?(lambda{ throw :sym, "a" }).should be_true
|
65
82
|
end
|
66
|
-
|
67
|
-
|
83
|
+
|
84
|
+
it "does not match if nothing is thrown" do
|
85
|
+
matcher.matches?(lambda{ }).should be_false
|
68
86
|
end
|
69
|
-
|
70
|
-
|
87
|
+
|
88
|
+
it "does not match if other Symbol is thrown" do
|
89
|
+
matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
|
71
90
|
end
|
72
|
-
|
73
|
-
|
91
|
+
|
92
|
+
it "does not match if no arg is thrown" do
|
93
|
+
matcher.matches?(lambda{ throw :sym }).should be_false
|
74
94
|
end
|
75
|
-
|
76
|
-
|
95
|
+
|
96
|
+
it "does not match if wrong arg is thrown" do
|
97
|
+
matcher.matches?(lambda{ throw :sym, "b" }).should be_false
|
77
98
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
99
|
+
|
100
|
+
it "provides a failure message when no Symbol is thrown" do
|
101
|
+
matcher.matches?(lambda{})
|
102
|
+
matcher.failure_message_for_should.should == %q[expected :sym with "a" but nothing was thrown]
|
81
103
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
104
|
+
|
105
|
+
it "provides a failure message when wrong Symbol is thrown" do
|
106
|
+
matcher.matches?(lambda{ throw :other_sym })
|
107
|
+
matcher.failure_message_for_should.should == %q[expected :sym with "a", got :other_sym]
|
85
108
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
109
|
+
|
110
|
+
it "provides a negative failure message" do
|
111
|
+
matcher.matches?(lambda{ throw :sym })
|
112
|
+
matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
|
89
113
|
end
|
90
|
-
|
91
|
-
|
114
|
+
|
115
|
+
it "only matches NameErrors raised by uncaught throws" do
|
116
|
+
matcher.matches?(lambda{ :sym }).should be_false
|
92
117
|
end
|
93
118
|
end
|
94
119
|
end
|