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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RSpec Development Team
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-11 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -23,14 +23,14 @@ dependencies:
|
|
23
23
|
version: "0.3"
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
26
|
+
name: fakefs
|
27
27
|
type: :development
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.2.1
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: syntax
|
@@ -155,6 +155,8 @@ files:
|
|
155
155
|
- features/expectations/expect_error.feature
|
156
156
|
- features/extensions/custom_example_group.feature
|
157
157
|
- features/formatters/custom_formatter.feature
|
158
|
+
- features/formatters/nested_formatter.feature
|
159
|
+
- features/interop/cucumber_stubs_dont_leak.feature
|
158
160
|
- features/interop/examples_and_tests_together.feature
|
159
161
|
- features/interop/rspec_output.feature
|
160
162
|
- features/interop/test_but_not_test_unit.feature
|
@@ -166,19 +168,24 @@ files:
|
|
166
168
|
- features/matchers/define_matcher_outside_rspec.feature
|
167
169
|
- features/matchers/define_matcher_with_fluent_interface.feature
|
168
170
|
- features/matchers/define_wrapped_matcher.feature
|
171
|
+
- features/matchers/match_unless_raises.feature
|
172
|
+
- features/matchers/match_unless_raises_unexpected_error.feature
|
169
173
|
- features/mock_framework_integration/use_flexmock.feature
|
170
174
|
- features/mock_framework_integration/use_mocha.feature
|
171
175
|
- features/mock_framework_integration/use_rr.feature
|
176
|
+
- features/mocks/block_local_expectations.feature
|
172
177
|
- features/mocks/mix_stubs_and_mocks.feature
|
173
178
|
- features/mocks/stub_implementation.feature
|
174
179
|
- features/pending/pending_examples.feature
|
175
180
|
- features/runner/specify_line_number.feature
|
176
181
|
- features/spec_helper/spec_helper.feature
|
177
182
|
- features/step_definitions/running_rspec_steps.rb
|
183
|
+
- features/step_definitions/stubbing_steps.rb
|
178
184
|
- features/subject/explicit_subject.feature
|
179
185
|
- features/subject/implicit_subject.feature
|
180
186
|
- features/support/env.rb
|
181
187
|
- features/support/matchers/smart_match.rb
|
188
|
+
- geminstaller.yml
|
182
189
|
- init.rb
|
183
190
|
- lib/autotest/discover.rb
|
184
191
|
- lib/autotest/rspec.rb
|
@@ -214,6 +221,7 @@ files:
|
|
214
221
|
- lib/spec/expectations/extensions/kernel.rb
|
215
222
|
- lib/spec/expectations/fail_with.rb
|
216
223
|
- lib/spec/expectations/handler.rb
|
224
|
+
- lib/spec/extensions/instance_exec.rb
|
217
225
|
- lib/spec/interop/test.rb
|
218
226
|
- lib/spec/interop/test/unit/autorunner.rb
|
219
227
|
- lib/spec/interop/test/unit/testcase.rb
|
@@ -232,7 +240,6 @@ files:
|
|
232
240
|
- lib/spec/matchers/equal.rb
|
233
241
|
- lib/spec/matchers/errors.rb
|
234
242
|
- lib/spec/matchers/exist.rb
|
235
|
-
- lib/spec/matchers/extensions/instance_exec.rb
|
236
243
|
- lib/spec/matchers/generated_descriptions.rb
|
237
244
|
- lib/spec/matchers/has.rb
|
238
245
|
- lib/spec/matchers/have.rb
|
@@ -243,7 +250,7 @@ files:
|
|
243
250
|
- lib/spec/matchers/method_missing.rb
|
244
251
|
- lib/spec/matchers/operator_matcher.rb
|
245
252
|
- lib/spec/matchers/pretty.rb
|
246
|
-
- lib/spec/matchers/
|
253
|
+
- lib/spec/matchers/raise_exception.rb
|
247
254
|
- lib/spec/matchers/respond_to.rb
|
248
255
|
- lib/spec/matchers/satisfy.rb
|
249
256
|
- lib/spec/matchers/simple_matcher.rb
|
@@ -362,15 +369,15 @@ files:
|
|
362
369
|
- spec/spec/matchers/include_spec.rb
|
363
370
|
- spec/spec/matchers/match_array_spec.rb
|
364
371
|
- spec/spec/matchers/match_spec.rb
|
365
|
-
- spec/spec/matchers/matcher_methods_spec.rb
|
366
372
|
- spec/spec/matchers/matcher_spec.rb
|
367
373
|
- spec/spec/matchers/matchers_spec.rb
|
368
374
|
- spec/spec/matchers/operator_matcher_spec.rb
|
369
|
-
- spec/spec/matchers/
|
375
|
+
- spec/spec/matchers/raise_exception_spec.rb
|
370
376
|
- spec/spec/matchers/respond_to_spec.rb
|
371
377
|
- spec/spec/matchers/satisfy_spec.rb
|
372
378
|
- spec/spec/matchers/simple_matcher_spec.rb
|
373
379
|
- spec/spec/matchers/throw_symbol_spec.rb
|
380
|
+
- spec/spec/mocks/and_yield_spec.rb
|
374
381
|
- spec/spec/mocks/any_number_of_times_spec.rb
|
375
382
|
- spec/spec/mocks/argument_expectation_spec.rb
|
376
383
|
- spec/spec/mocks/argument_matchers_spec.rb
|
@@ -470,7 +477,7 @@ licenses: []
|
|
470
477
|
post_install_message: |
|
471
478
|
**************************************************
|
472
479
|
|
473
|
-
Thank you for installing rspec-1.
|
480
|
+
Thank you for installing rspec-1.3.0
|
474
481
|
|
475
482
|
Please be sure to read History.rdoc and Upgrade.rdoc
|
476
483
|
for useful information about this release.
|
@@ -500,6 +507,6 @@ rubyforge_project: rspec
|
|
500
507
|
rubygems_version: 1.3.5
|
501
508
|
signing_key:
|
502
509
|
specification_version: 3
|
503
|
-
summary: rspec 1.
|
510
|
+
summary: rspec 1.3.0
|
504
511
|
test_files: []
|
505
512
|
|
@@ -1,129 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Matchers
|
3
|
-
class RaiseError #:nodoc:
|
4
|
-
def initialize(expected_error_or_message=Exception, expected_message=nil, &block)
|
5
|
-
@block = block
|
6
|
-
@actual_error = nil
|
7
|
-
case expected_error_or_message
|
8
|
-
when String, Regexp
|
9
|
-
@expected_error, @expected_message = Exception, expected_error_or_message
|
10
|
-
else
|
11
|
-
@expected_error, @expected_message = expected_error_or_message, expected_message
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def matches?(given_proc)
|
16
|
-
@raised_expected_error = false
|
17
|
-
@with_expected_message = false
|
18
|
-
@eval_block = false
|
19
|
-
@eval_block_passed = false
|
20
|
-
begin
|
21
|
-
given_proc.call
|
22
|
-
rescue @expected_error => @actual_error
|
23
|
-
@raised_expected_error = true
|
24
|
-
@with_expected_message = verify_message
|
25
|
-
rescue Exception => @actual_error
|
26
|
-
# This clause should be empty, but rcov will not report it as covered
|
27
|
-
# unless something (anything) is executed within the clause
|
28
|
-
rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
|
29
|
-
end
|
30
|
-
|
31
|
-
unless negative_expectation?
|
32
|
-
eval_block if @raised_expected_error && @with_expected_message && @block
|
33
|
-
end
|
34
|
-
ensure
|
35
|
-
return (@raised_expected_error & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
|
36
|
-
end
|
37
|
-
|
38
|
-
def eval_block
|
39
|
-
@eval_block = true
|
40
|
-
begin
|
41
|
-
@block[@actual_error]
|
42
|
-
@eval_block_passed = true
|
43
|
-
rescue Exception => err
|
44
|
-
@actual_error = err
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def verify_message
|
49
|
-
case @expected_message
|
50
|
-
when nil
|
51
|
-
true
|
52
|
-
when Regexp
|
53
|
-
@expected_message =~ @actual_error.message
|
54
|
-
else
|
55
|
-
@expected_message == @actual_error.message
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def failure_message_for_should
|
60
|
-
@eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
|
61
|
-
end
|
62
|
-
|
63
|
-
def failure_message_for_should_not
|
64
|
-
"expected no #{expected_error}#{given_error}"
|
65
|
-
end
|
66
|
-
|
67
|
-
def description
|
68
|
-
"raise #{expected_error}"
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
def expected_error
|
73
|
-
case @expected_message
|
74
|
-
when nil
|
75
|
-
@expected_error
|
76
|
-
when Regexp
|
77
|
-
"#{@expected_error} with message matching #{@expected_message.inspect}"
|
78
|
-
else
|
79
|
-
"#{@expected_error} with #{@expected_message.inspect}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def given_error
|
84
|
-
@actual_error.nil? ? " but nothing was raised" : ", got #{@actual_error.inspect}"
|
85
|
-
end
|
86
|
-
|
87
|
-
def negative_expectation?
|
88
|
-
# YES - I'm a bad person... help me find a better way - ryand
|
89
|
-
caller.first(3).find { |s| s =~ /should_not/ }
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# :call-seq:
|
94
|
-
# should raise_error()
|
95
|
-
# should raise_error(NamedError)
|
96
|
-
# should raise_error(NamedError, String)
|
97
|
-
# should raise_error(NamedError, Regexp)
|
98
|
-
# should raise_error() { |error| ... }
|
99
|
-
# should raise_error(NamedError) { |error| ... }
|
100
|
-
# should raise_error(NamedError, String) { |error| ... }
|
101
|
-
# should raise_error(NamedError, Regexp) { |error| ... }
|
102
|
-
# should_not raise_error()
|
103
|
-
# should_not raise_error(NamedError)
|
104
|
-
# should_not raise_error(NamedError, String)
|
105
|
-
# should_not raise_error(NamedError, Regexp)
|
106
|
-
#
|
107
|
-
# With no args, matches if any error is raised.
|
108
|
-
# With a named error, matches only if that specific error is raised.
|
109
|
-
# With a named error and messsage specified as a String, matches only if both match.
|
110
|
-
# With a named error and messsage specified as a Regexp, matches only if both match.
|
111
|
-
# Pass an optional block to perform extra verifications on the exception matched
|
112
|
-
#
|
113
|
-
# == Examples
|
114
|
-
#
|
115
|
-
# lambda { do_something_risky }.should raise_error
|
116
|
-
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError)
|
117
|
-
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError) { |error| error.data.should == 42 }
|
118
|
-
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, "that was too risky")
|
119
|
-
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, /oo ri/)
|
120
|
-
#
|
121
|
-
# lambda { do_something_risky }.should_not raise_error
|
122
|
-
# lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError)
|
123
|
-
# lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, "that was too risky")
|
124
|
-
# lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, /oo ri/)
|
125
|
-
def raise_error(error=Exception, message=nil, &block)
|
126
|
-
Matchers::RaiseError.new(error, message, &block)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Matchers
|
5
|
-
context %Q{The Spec::Matchers module gets included in the execution context of every spec.
|
6
|
-
This module should provide the following methods, each of which returns a Matcher object.} do
|
7
|
-
it "be_true" do
|
8
|
-
be_true.should be_an_instance_of(Be)
|
9
|
-
end
|
10
|
-
it "be_false" do
|
11
|
-
be_false.should be_an_instance_of(Be)
|
12
|
-
end
|
13
|
-
it "be_nil" do
|
14
|
-
be_nil.should be_an_instance_of(Be)
|
15
|
-
end
|
16
|
-
it "be_arbitrary_predicate" do
|
17
|
-
be_arbitrary_predicate.should be_an_instance_of(Be)
|
18
|
-
end
|
19
|
-
it "change" do
|
20
|
-
change("target", :message).should be_an_instance_of(Change)
|
21
|
-
end
|
22
|
-
it "have" do
|
23
|
-
have(0).should be_an_instance_of(Have)
|
24
|
-
end
|
25
|
-
it "have_exactly" do
|
26
|
-
have_exactly(0).should be_an_instance_of(Have)
|
27
|
-
end
|
28
|
-
it "have_at_least" do
|
29
|
-
have_at_least(0).should be_an_instance_of(Have)
|
30
|
-
end
|
31
|
-
it "have_at_most" do
|
32
|
-
have_at_most(0).should be_an_instance_of(Have)
|
33
|
-
end
|
34
|
-
it "raise_error" do
|
35
|
-
raise_error.should be_an_instance_of(RaiseError)
|
36
|
-
raise_error(NoMethodError).should be_an_instance_of(RaiseError)
|
37
|
-
raise_error(NoMethodError, "message").should be_an_instance_of(RaiseError)
|
38
|
-
end
|
39
|
-
it "satisfy" do
|
40
|
-
satisfy{}.should be_an_instance_of(Satisfy)
|
41
|
-
end
|
42
|
-
it "throw_symbol" do
|
43
|
-
throw_symbol.should be_an_instance_of(ThrowSymbol)
|
44
|
-
throw_symbol(:sym).should be_an_instance_of(ThrowSymbol)
|
45
|
-
end
|
46
|
-
it "respond_to" do
|
47
|
-
respond_to(:sym).should be_an_instance_of(RespondTo)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "Spec::Matchers#method_missing" do
|
52
|
-
it "should convert be_xyz to Be(:be_xyz)" do
|
53
|
-
Be.should_receive(:new).with(:be_whatever)
|
54
|
-
be_whatever
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should convert have_xyz to Has(:have_xyz)" do
|
58
|
-
Has.should_receive(:new).with(:have_whatever)
|
59
|
-
have_whatever
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,333 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "should raise_error" do
|
4
|
-
it "should pass if anything is raised" do
|
5
|
-
lambda {raise}.should raise_error
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should fail if nothing is raised" do
|
9
|
-
lambda {
|
10
|
-
lambda {}.should raise_error
|
11
|
-
}.should fail_with("expected Exception but nothing was raised")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "should raise_error {|err| ... }" do
|
16
|
-
it "passes if there is an error" do
|
17
|
-
ran = false
|
18
|
-
lambda { non_existent_method }.should raise_error {|e|
|
19
|
-
ran = true
|
20
|
-
}
|
21
|
-
ran.should be_true
|
22
|
-
end
|
23
|
-
|
24
|
-
it "passes the error to the block" do
|
25
|
-
error = nil
|
26
|
-
lambda { non_existent_method }.should raise_error {|e|
|
27
|
-
error = e
|
28
|
-
}
|
29
|
-
error.should be_kind_of(NameError)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "should_not raise_error" do
|
34
|
-
it "should pass if nothing is raised" do
|
35
|
-
lambda {}.should_not raise_error
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should fail if anything is raised" do
|
39
|
-
lambda {
|
40
|
-
lambda {raise}.should_not raise_error
|
41
|
-
}.should fail_with("expected no Exception, got RuntimeError")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "should raise_error(message)" do
|
46
|
-
it "should pass if RuntimeError is raised with the right message" do
|
47
|
-
lambda {raise 'blah'}.should raise_error('blah')
|
48
|
-
end
|
49
|
-
it "should pass if RuntimeError is raised with a matching message" do
|
50
|
-
lambda {raise 'blah'}.should raise_error(/blah/)
|
51
|
-
end
|
52
|
-
it "should pass if any other error is raised with the right message" do
|
53
|
-
lambda {raise NameError.new('blah')}.should raise_error('blah')
|
54
|
-
end
|
55
|
-
it "should fail if RuntimeError error is raised with the wrong message" do
|
56
|
-
lambda do
|
57
|
-
lambda {raise 'blarg'}.should raise_error('blah')
|
58
|
-
end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
|
59
|
-
end
|
60
|
-
it "should fail if any other error is raised with the wrong message" do
|
61
|
-
lambda do
|
62
|
-
lambda {raise NameError.new('blarg')}.should raise_error('blah')
|
63
|
-
end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "should_not raise_error(message)" do
|
68
|
-
it "should pass if RuntimeError error is raised with the different message" do
|
69
|
-
lambda {raise 'blarg'}.should_not raise_error('blah')
|
70
|
-
end
|
71
|
-
it "should pass if any other error is raised with the wrong message" do
|
72
|
-
lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
|
73
|
-
end
|
74
|
-
it "should fail if RuntimeError is raised with message" do
|
75
|
-
lambda do
|
76
|
-
lambda {raise 'blah'}.should_not raise_error('blah')
|
77
|
-
end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
|
78
|
-
end
|
79
|
-
it "should fail if any other error is raised with message" do
|
80
|
-
lambda do
|
81
|
-
lambda {raise NameError.new('blah')}.should_not raise_error('blah')
|
82
|
-
end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "should raise_error(NamedError)" do
|
87
|
-
it "should pass if named error is raised" do
|
88
|
-
lambda { non_existent_method }.should raise_error(NameError)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should fail if nothing is raised" do
|
92
|
-
lambda {
|
93
|
-
lambda { }.should raise_error(NameError)
|
94
|
-
}.should fail_with("expected NameError but nothing was raised")
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should fail if another error is raised (NameError)" do
|
98
|
-
lambda {
|
99
|
-
lambda { raise }.should raise_error(NameError)
|
100
|
-
}.should fail_with("expected NameError, got RuntimeError")
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should fail if another error is raised (NameError)" do
|
104
|
-
lambda {
|
105
|
-
lambda { load "non/existent/file" }.should raise_error(NameError)
|
106
|
-
}.should fail_with(/expected NameError, got #<LoadError/)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "should_not raise_error(NamedError)" do
|
111
|
-
it "should pass if nothing is raised" do
|
112
|
-
lambda { }.should_not raise_error(NameError)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should pass if another error is raised" do
|
116
|
-
lambda { raise }.should_not raise_error(NameError)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should fail if named error is raised" do
|
120
|
-
lambda {
|
121
|
-
lambda { 1 + 'b' }.should_not raise_error(TypeError)
|
122
|
-
}.should fail_with(/expected no TypeError, got #<TypeError: String can't be/)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "should raise_error(NamedError, error_message) with String" do
|
127
|
-
it "should pass if named error is raised with same message" do
|
128
|
-
lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should fail if nothing is raised" do
|
132
|
-
lambda {
|
133
|
-
lambda {}.should raise_error(RuntimeError, "example message")
|
134
|
-
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should fail if incorrect error is raised" do
|
138
|
-
lambda {
|
139
|
-
lambda { raise }.should raise_error(NameError, "example message")
|
140
|
-
}.should fail_with("expected NameError with \"example message\", got RuntimeError")
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should fail if correct error is raised with incorrect message" do
|
144
|
-
lambda {
|
145
|
-
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
|
146
|
-
}.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "should raise_error(NamedError, error_message) { |err| ... }" do
|
151
|
-
it "should yield exception if named error is raised with same message" do
|
152
|
-
ran = false
|
153
|
-
|
154
|
-
lambda {
|
155
|
-
raise "example message"
|
156
|
-
}.should raise_error(RuntimeError, "example message") { |err|
|
157
|
-
ran = true
|
158
|
-
err.class.should == RuntimeError
|
159
|
-
err.message.should == "example message"
|
160
|
-
}
|
161
|
-
|
162
|
-
ran.should == true
|
163
|
-
end
|
164
|
-
|
165
|
-
it "yielded block should be able to fail on it's own right" do
|
166
|
-
ran, passed = false, false
|
167
|
-
|
168
|
-
lambda {
|
169
|
-
lambda {
|
170
|
-
raise "example message"
|
171
|
-
}.should raise_error(RuntimeError, "example message") { |err|
|
172
|
-
ran = true
|
173
|
-
5.should == 4
|
174
|
-
passed = true
|
175
|
-
}
|
176
|
-
}.should fail_with(/expected: 4/m)
|
177
|
-
|
178
|
-
ran.should == true
|
179
|
-
passed.should == false
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should NOT yield exception if no error was thrown" do
|
183
|
-
ran = false
|
184
|
-
|
185
|
-
lambda {
|
186
|
-
lambda {}.should raise_error(RuntimeError, "example message") { |err|
|
187
|
-
ran = true
|
188
|
-
}
|
189
|
-
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
190
|
-
|
191
|
-
ran.should == false
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should not yield exception if error class is not matched" do
|
195
|
-
ran = false
|
196
|
-
|
197
|
-
lambda {
|
198
|
-
lambda {
|
199
|
-
raise "example message"
|
200
|
-
}.should raise_error(SyntaxError, "example message") { |err|
|
201
|
-
ran = true
|
202
|
-
}
|
203
|
-
}.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
|
204
|
-
|
205
|
-
ran.should == false
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should NOT yield exception if error message is not matched" do
|
209
|
-
ran = false
|
210
|
-
|
211
|
-
lambda {
|
212
|
-
lambda {
|
213
|
-
raise "example message"
|
214
|
-
}.should raise_error(RuntimeError, "different message") { |err|
|
215
|
-
ran = true
|
216
|
-
}
|
217
|
-
}.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
|
218
|
-
|
219
|
-
ran.should == false
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
|
224
|
-
it "should pass if nothing is raised" do
|
225
|
-
ran = false
|
226
|
-
|
227
|
-
lambda {}.should_not raise_error(RuntimeError, "example message") { |err|
|
228
|
-
ran = true
|
229
|
-
}
|
230
|
-
|
231
|
-
ran.should == false
|
232
|
-
end
|
233
|
-
|
234
|
-
it "should pass if a different error is raised" do
|
235
|
-
ran = false
|
236
|
-
|
237
|
-
lambda { raise }.should_not raise_error(NameError, "example message") { |err|
|
238
|
-
ran = true
|
239
|
-
}
|
240
|
-
|
241
|
-
ran.should == false
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should pass if same error is raised with different message" do
|
245
|
-
ran = false
|
246
|
-
|
247
|
-
lambda {
|
248
|
-
raise RuntimeError.new("not the example message")
|
249
|
-
}.should_not raise_error(RuntimeError, "example message") { |err|
|
250
|
-
ran = true
|
251
|
-
}
|
252
|
-
|
253
|
-
ran.should == false
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should fail if named error is raised with same message" do
|
257
|
-
ran = false
|
258
|
-
|
259
|
-
lambda {
|
260
|
-
lambda {
|
261
|
-
raise "example message"
|
262
|
-
}.should_not raise_error(RuntimeError, "example message") { |err|
|
263
|
-
ran = true
|
264
|
-
}
|
265
|
-
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
266
|
-
|
267
|
-
ran.should == false
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe "should_not raise_error(NamedError, error_message) with String" do
|
272
|
-
it "should pass if nothing is raised" do
|
273
|
-
lambda {}.should_not raise_error(RuntimeError, "example message")
|
274
|
-
end
|
275
|
-
|
276
|
-
it "should pass if a different error is raised" do
|
277
|
-
lambda { raise }.should_not raise_error(NameError, "example message")
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should pass if same error is raised with different message" do
|
281
|
-
lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
|
282
|
-
end
|
283
|
-
|
284
|
-
it "should fail if named error is raised with same message" do
|
285
|
-
lambda {
|
286
|
-
lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
|
287
|
-
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
describe "should raise_error(NamedError, error_message) with Regexp" do
|
292
|
-
it "should pass if named error is raised with matching message" do
|
293
|
-
lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
|
294
|
-
end
|
295
|
-
|
296
|
-
it "should fail if nothing is raised" do
|
297
|
-
lambda {
|
298
|
-
lambda {}.should raise_error(RuntimeError, /ample mess/)
|
299
|
-
}.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should fail if incorrect error is raised" do
|
303
|
-
lambda {
|
304
|
-
lambda { raise }.should raise_error(NameError, /ample mess/)
|
305
|
-
}.should fail_with("expected NameError with message matching /ample mess/, got RuntimeError")
|
306
|
-
end
|
307
|
-
|
308
|
-
it "should fail if correct error is raised with incorrect message" do
|
309
|
-
lambda {
|
310
|
-
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
|
311
|
-
}.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
describe "should_not raise_error(NamedError, error_message) with Regexp" do
|
316
|
-
it "should pass if nothing is raised" do
|
317
|
-
lambda {}.should_not raise_error(RuntimeError, /ample mess/)
|
318
|
-
end
|
319
|
-
|
320
|
-
it "should pass if a different error is raised" do
|
321
|
-
lambda { raise }.should_not raise_error(NameError, /ample mess/)
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should pass if same error is raised with non-matching message" do
|
325
|
-
lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should fail if named error is raised with matching message" do
|
329
|
-
lambda {
|
330
|
-
lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
|
331
|
-
}.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
|
332
|
-
end
|
333
|
-
end
|