rsanheim-micronaut 0.1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +45 -0
- data/README +17 -0
- data/RSPEC-LICENSE +23 -0
- data/Rakefile +83 -0
- data/bin/micronaut +4 -0
- data/examples/example_helper.rb +36 -0
- data/examples/lib/micronaut/behaviour_example.rb +188 -0
- data/examples/lib/micronaut/configuration_example.rb +70 -0
- data/examples/lib/micronaut/example_example.rb +46 -0
- data/examples/lib/micronaut/expectations/extensions/object_example.rb +72 -0
- data/examples/lib/micronaut/expectations/fail_with_example.rb +17 -0
- data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +31 -0
- data/examples/lib/micronaut/formatters/base_formatter_example.rb +107 -0
- data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
- data/examples/lib/micronaut/formatters/progress_formatter_example.rb +74 -0
- data/examples/lib/micronaut/kernel_extensions_example.rb +13 -0
- data/examples/lib/micronaut/matchers/be_close_example.rb +52 -0
- data/examples/lib/micronaut/matchers/be_example.rb +298 -0
- data/examples/lib/micronaut/matchers/change_example.rb +360 -0
- data/examples/lib/micronaut/matchers/description_generation_example.rb +175 -0
- data/examples/lib/micronaut/matchers/eql_example.rb +35 -0
- data/examples/lib/micronaut/matchers/equal_example.rb +35 -0
- data/examples/lib/micronaut/matchers/handler_example.rb +153 -0
- data/examples/lib/micronaut/matchers/has_example.rb +71 -0
- data/examples/lib/micronaut/matchers/have_example.rb +575 -0
- data/examples/lib/micronaut/matchers/include_example.rb +103 -0
- data/examples/lib/micronaut/matchers/match_example.rb +43 -0
- data/examples/lib/micronaut/matchers/matcher_methods_example.rb +66 -0
- data/examples/lib/micronaut/matchers/operator_matcher_example.rb +189 -0
- data/examples/lib/micronaut/matchers/raise_error_example.rb +346 -0
- data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
- data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
- data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
- data/examples/lib/micronaut/matchers/throw_symbol_example.rb +96 -0
- data/examples/lib/micronaut/runner_example.rb +5 -0
- data/examples/lib/micronaut/runner_options_example.rb +5 -0
- data/examples/lib/micronaut/world_example.rb +102 -0
- data/examples/lib/micronaut_example.rb +23 -0
- data/examples/resources/example_classes.rb +67 -0
- data/lib/autotest/discover.rb +3 -0
- data/lib/autotest/micronaut.rb +47 -0
- data/lib/micronaut/behaviour.rb +211 -0
- data/lib/micronaut/configuration.rb +133 -0
- data/lib/micronaut/example.rb +28 -0
- data/lib/micronaut/expectations/extensions/object.rb +62 -0
- data/lib/micronaut/expectations/extensions/string_and_symbol.rb +19 -0
- data/lib/micronaut/expectations/handler.rb +52 -0
- data/lib/micronaut/expectations/wrap_expectation.rb +57 -0
- data/lib/micronaut/expectations.rb +46 -0
- data/lib/micronaut/formatters/base_formatter.rb +82 -0
- data/lib/micronaut/formatters/base_text_formatter.rb +148 -0
- data/lib/micronaut/formatters/documentation_formatter.rb +62 -0
- data/lib/micronaut/formatters/progress_formatter.rb +36 -0
- data/lib/micronaut/formatters.rb +12 -0
- data/lib/micronaut/kernel_extensions.rb +11 -0
- data/lib/micronaut/matchers/be.rb +204 -0
- data/lib/micronaut/matchers/be_close.rb +22 -0
- data/lib/micronaut/matchers/change.rb +148 -0
- data/lib/micronaut/matchers/eql.rb +26 -0
- data/lib/micronaut/matchers/equal.rb +26 -0
- data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
- data/lib/micronaut/matchers/has.rb +19 -0
- data/lib/micronaut/matchers/have.rb +153 -0
- data/lib/micronaut/matchers/include.rb +80 -0
- data/lib/micronaut/matchers/match.rb +22 -0
- data/lib/micronaut/matchers/method_missing.rb +9 -0
- data/lib/micronaut/matchers/operator_matcher.rb +50 -0
- data/lib/micronaut/matchers/raise_error.rb +128 -0
- data/lib/micronaut/matchers/respond_to.rb +50 -0
- data/lib/micronaut/matchers/satisfy.rb +50 -0
- data/lib/micronaut/matchers/simple_matcher.rb +135 -0
- data/lib/micronaut/matchers/throw_symbol.rb +108 -0
- data/lib/micronaut/matchers.rb +148 -0
- data/lib/micronaut/mocking/with_absolutely_nothing.rb +11 -0
- data/lib/micronaut/mocking/with_mocha.rb +13 -0
- data/lib/micronaut/mocking/with_rr.rb +24 -0
- data/lib/micronaut/mocking.rb +7 -0
- data/lib/micronaut/runner.rb +57 -0
- data/lib/micronaut/runner_options.rb +33 -0
- data/lib/micronaut/world.rb +75 -0
- data/lib/micronaut.rb +37 -0
- metadata +149 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe Micronaut::Matchers do
|
4
|
+
|
5
|
+
describe "should match(expected)" do
|
6
|
+
|
7
|
+
it "should pass when target (String) matches expected (Regexp)" do
|
8
|
+
"string".should match(/tri/)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should fail when target (String) does not match expected (Regexp)" do
|
12
|
+
lambda { "string".should match(/rings/) }.should fail
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should provide message, expected and actual on failure" do
|
16
|
+
matcher = match(/rings/)
|
17
|
+
matcher.matches?("string")
|
18
|
+
matcher.failure_message.should == ["expected \"string\" to match /rings/", /rings/, "string"]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "should_not match(expected)" do
|
24
|
+
|
25
|
+
it "should pass when target (String) matches does not match (Regexp)" do
|
26
|
+
"string".should_not match(/rings/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should fail when target (String) matches expected (Regexp)" do
|
30
|
+
lambda {
|
31
|
+
"string".should_not match(/tri/)
|
32
|
+
}.should fail
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should provide message, expected and actual on failure" do
|
36
|
+
matcher = match(/tri/)
|
37
|
+
matcher.matches?("string")
|
38
|
+
matcher.negative_failure_message.should == ["expected \"string\" not to match /tri/", /tri/, "string"]
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
module Micronaut
|
4
|
+
module Matchers
|
5
|
+
describe %Q{The Micronaut::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 "include" do
|
35
|
+
include(:value).should be_an_instance_of(Include)
|
36
|
+
end
|
37
|
+
it "raise_error" do
|
38
|
+
raise_error.should be_an_instance_of(RaiseError)
|
39
|
+
raise_error(NoMethodError).should be_an_instance_of(RaiseError)
|
40
|
+
raise_error(NoMethodError, "message").should be_an_instance_of(RaiseError)
|
41
|
+
end
|
42
|
+
it "satisfy" do
|
43
|
+
satisfy{}.should be_an_instance_of(Satisfy)
|
44
|
+
end
|
45
|
+
it "throw_symbol" do
|
46
|
+
throw_symbol.should be_an_instance_of(ThrowSymbol)
|
47
|
+
throw_symbol(:sym).should be_an_instance_of(ThrowSymbol)
|
48
|
+
end
|
49
|
+
it "respond_to" do
|
50
|
+
respond_to(:sym).should be_an_instance_of(RespondTo)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "Micronaut::Matchers#method_missing" do
|
55
|
+
it "should convert be_xyz to Be(:be_xyz)" do
|
56
|
+
Be.expects(:new).with(:be_whatever)
|
57
|
+
be_whatever
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should convert have_xyz to Has(:have_xyz)" do
|
61
|
+
self.expects(:has).with(:have_whatever)
|
62
|
+
have_whatever
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe "should ==" do
|
4
|
+
|
5
|
+
it "should delegate message to target" do
|
6
|
+
subject = "apple"
|
7
|
+
subject.expects(:==).with("apple").returns(true)
|
8
|
+
subject.should == "apple"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return true on success" do
|
12
|
+
subject = "apple"
|
13
|
+
(subject.should == "apple").should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should fail when target.==(actual) returns false" do
|
17
|
+
subject = "apple"
|
18
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected: "orange",\n got: "apple" (using ==)], "orange", "apple")
|
19
|
+
subject.should == "orange"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "should_not ==" do
|
25
|
+
|
26
|
+
it "should delegate message to target" do
|
27
|
+
subject = "orange"
|
28
|
+
subject.expects(:==).with("apple").returns(false)
|
29
|
+
subject.should_not == "apple"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return true on success" do
|
33
|
+
subject = "apple"
|
34
|
+
(subject.should_not == "orange").should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should fail when target.==(actual) returns false" do
|
38
|
+
subject = "apple"
|
39
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected not: == "apple",\n got: "apple"], "apple", "apple")
|
40
|
+
subject.should_not == "apple"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "should ===" do
|
46
|
+
|
47
|
+
it "should delegate message to target" do
|
48
|
+
subject = "apple"
|
49
|
+
subject.expects(:===).with("apple").returns(true)
|
50
|
+
subject.should === "apple"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should fail when target.===(actual) returns false" do
|
54
|
+
subject = "apple"
|
55
|
+
subject.expects(:===).with("orange").returns(false)
|
56
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected: "orange",\n got: "apple" (using ===)], "orange", "apple")
|
57
|
+
subject.should === "orange"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "should_not ===" do
|
63
|
+
|
64
|
+
it "should delegate message to target" do
|
65
|
+
subject = "orange"
|
66
|
+
subject.expects(:===).with("apple").returns(false)
|
67
|
+
subject.should_not === "apple"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should fail when target.===(actual) returns false" do
|
71
|
+
subject = "apple"
|
72
|
+
subject.expects(:===).with("apple").returns(true)
|
73
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected not: === "apple",\n got: "apple"], "apple", "apple")
|
74
|
+
subject.should_not === "apple"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "should =~" do
|
80
|
+
|
81
|
+
it "should delegate message to target" do
|
82
|
+
subject = "foo"
|
83
|
+
subject.expects(:=~).with(/oo/).returns(true)
|
84
|
+
subject.should =~ /oo/
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should fail when target.=~(actual) returns false" do
|
88
|
+
subject = "fu"
|
89
|
+
subject.expects(:=~).with(/oo/).returns(false)
|
90
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected: /oo/,\n got: "fu" (using =~)], /oo/, "fu")
|
91
|
+
subject.should =~ /oo/
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "should_not =~" do
|
97
|
+
|
98
|
+
it "should delegate message to target" do
|
99
|
+
subject = "fu"
|
100
|
+
subject.expects(:=~).with(/oo/).returns(false)
|
101
|
+
subject.should_not =~ /oo/
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should fail when target.=~(actual) returns false" do
|
105
|
+
subject = "foo"
|
106
|
+
subject.expects(:=~).with(/oo/).returns(true)
|
107
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected not: =~ /oo/,\n got: "foo"], /oo/, "foo")
|
108
|
+
subject.should_not =~ /oo/
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "should >" do
|
114
|
+
|
115
|
+
it "should pass if > passes" do
|
116
|
+
4.should > 3
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should fail if > fails" do
|
120
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected: > 5,\n got: 4], 5, 4)
|
121
|
+
4.should > 5
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "should >=" do
|
127
|
+
|
128
|
+
it "should pass if >= passes" do
|
129
|
+
4.should > 3
|
130
|
+
4.should >= 4
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should fail if > fails" do
|
134
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected: >= 5,\n got: 4], 5, 4)
|
135
|
+
4.should >= 5
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "should <" do
|
141
|
+
|
142
|
+
it "should pass if < passes" do
|
143
|
+
4.should < 5
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should fail if > fails" do
|
147
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected: < 3,\n got: 4], 3, 4)
|
148
|
+
4.should < 3
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "should <=" do
|
154
|
+
|
155
|
+
it "should pass if <= passes" do
|
156
|
+
4.should <= 5
|
157
|
+
4.should <= 4
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should fail if > fails" do
|
161
|
+
Micronaut::Expectations.expects(:fail_with).with(%[expected: <= 3,\n got: 4], 3, 4)
|
162
|
+
4.should <= 3
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
describe Micronaut::Matchers::PositiveOperatorMatcher do
|
168
|
+
|
169
|
+
it "should work when the target has implemented #send" do
|
170
|
+
o = Object.new
|
171
|
+
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
172
|
+
lambda {
|
173
|
+
o.should == o
|
174
|
+
}.should_not raise_error
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe Micronaut::Matchers::NegativeOperatorMatcher do
|
180
|
+
|
181
|
+
it "should work when the target has implemented #send" do
|
182
|
+
o = Object.new
|
183
|
+
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
184
|
+
lambda {
|
185
|
+
o.should_not == :foo
|
186
|
+
}.should_not raise_error
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
@@ -0,0 +1,346 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe "should raise_error" do
|
4
|
+
|
5
|
+
it "should pass if anything is raised" do
|
6
|
+
lambda {raise}.should raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should fail if nothing is raised" do
|
10
|
+
lambda {
|
11
|
+
lambda {}.should raise_error
|
12
|
+
}.should fail_with("expected Exception but nothing was raised")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "should_not raise_error" do
|
18
|
+
|
19
|
+
it "should pass if nothing is raised" do
|
20
|
+
lambda {}.should_not raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fail if anything is raised" do
|
24
|
+
lambda {
|
25
|
+
lambda {raise}.should_not raise_error
|
26
|
+
}.should fail_with("expected no Exception, got RuntimeError")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "should raise_error(message)" do
|
32
|
+
|
33
|
+
it "should pass if RuntimeError is raised with the right message" do
|
34
|
+
lambda {raise 'blah'}.should raise_error('blah')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should pass if RuntimeError is raised with a matching message" do
|
38
|
+
lambda {raise 'blah'}.should raise_error(/blah/)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should pass if any other error is raised with the right message" do
|
42
|
+
lambda {raise NameError.new('blah')}.should raise_error('blah')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should fail if RuntimeError error is raised with the wrong message" do
|
46
|
+
lambda do
|
47
|
+
lambda {raise 'blarg'}.should raise_error('blah')
|
48
|
+
end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should fail if any other error is raised with the wrong message" do
|
52
|
+
lambda do
|
53
|
+
lambda {raise NameError.new('blarg')}.should raise_error('blah')
|
54
|
+
end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "should_not raise_error(message)" do
|
60
|
+
|
61
|
+
it "should pass if RuntimeError error is raised with the different message" do
|
62
|
+
lambda {raise 'blarg'}.should_not raise_error('blah')
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should pass if any other error is raised with the wrong message" do
|
66
|
+
lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should fail if RuntimeError is raised with message" do
|
70
|
+
lambda do
|
71
|
+
lambda {raise 'blah'}.should_not raise_error('blah')
|
72
|
+
end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should fail if any other error is raised with message" do
|
76
|
+
lambda do
|
77
|
+
lambda {raise NameError.new('blah')}.should_not raise_error('blah')
|
78
|
+
end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "should raise_error(NamedError)" do
|
84
|
+
|
85
|
+
it "should pass if named error is raised" do
|
86
|
+
lambda { non_existent_method }.should raise_error(NameError)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should fail if nothing is raised" do
|
90
|
+
lambda {
|
91
|
+
lambda { }.should raise_error(NameError)
|
92
|
+
}.should fail_with("expected NameError but nothing was raised")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should fail if another error is raised (NameError)" do
|
96
|
+
lambda {
|
97
|
+
lambda { raise }.should raise_error(NameError)
|
98
|
+
}.should fail_with("expected NameError, got RuntimeError")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should fail if another error is raised (NameError)" do
|
102
|
+
lambda {
|
103
|
+
lambda { load "non/existent/file" }.should raise_error(NameError)
|
104
|
+
}.should fail_with(/expected NameError, got #<LoadError/)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "should_not raise_error(NamedError)" do
|
110
|
+
|
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 { non_existent_method }.should_not raise_error(NameError)
|
122
|
+
}.should fail_with(/expected no NameError, got #<NameError: undefined/)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "should raise_error(NamedError, error_message) with String" do
|
128
|
+
|
129
|
+
it "should pass if named error is raised with same message" do
|
130
|
+
lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should fail if nothing is raised" do
|
134
|
+
lambda {
|
135
|
+
lambda {}.should raise_error(RuntimeError, "example message")
|
136
|
+
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should fail if incorrect error is raised" do
|
140
|
+
lambda {
|
141
|
+
lambda { raise }.should raise_error(NameError, "example message")
|
142
|
+
}.should fail_with("expected NameError with \"example message\", got RuntimeError")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should fail if correct error is raised with incorrect message" do
|
146
|
+
lambda {
|
147
|
+
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
|
148
|
+
}.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "should raise_error(NamedError, error_message) { |err| ... }" do
|
154
|
+
|
155
|
+
it "should yield exception if named error is raised with same message" do
|
156
|
+
ran = false
|
157
|
+
|
158
|
+
lambda {
|
159
|
+
raise "example message"
|
160
|
+
}.should raise_error(RuntimeError, "example message") { |err|
|
161
|
+
ran = true
|
162
|
+
err.class.should == RuntimeError
|
163
|
+
err.message.should == "example message"
|
164
|
+
}
|
165
|
+
|
166
|
+
ran.should == true
|
167
|
+
end
|
168
|
+
|
169
|
+
it "yielded block should be able to fail on it's own right" do
|
170
|
+
ran, passed = false, false
|
171
|
+
|
172
|
+
lambda {
|
173
|
+
lambda {
|
174
|
+
raise "example message"
|
175
|
+
}.should raise_error(RuntimeError, "example message") { |err|
|
176
|
+
ran = true
|
177
|
+
5.should == 4
|
178
|
+
passed = true
|
179
|
+
}
|
180
|
+
}.should fail_with(/expected: 4/m)
|
181
|
+
|
182
|
+
ran.should == true
|
183
|
+
passed.should == false
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should NOT yield exception if no error was thrown" do
|
187
|
+
ran = false
|
188
|
+
|
189
|
+
lambda {
|
190
|
+
lambda {}.should raise_error(RuntimeError, "example message") { |err|
|
191
|
+
ran = true
|
192
|
+
}
|
193
|
+
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
194
|
+
|
195
|
+
ran.should == false
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should not yield exception if error class is not matched" do
|
199
|
+
ran = false
|
200
|
+
|
201
|
+
lambda {
|
202
|
+
lambda {
|
203
|
+
raise "example message"
|
204
|
+
}.should raise_error(SyntaxError, "example message") { |err|
|
205
|
+
ran = true
|
206
|
+
}
|
207
|
+
}.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
|
208
|
+
|
209
|
+
ran.should == false
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should NOT yield exception if error message is not matched" do
|
213
|
+
ran = false
|
214
|
+
|
215
|
+
lambda {
|
216
|
+
lambda {
|
217
|
+
raise "example message"
|
218
|
+
}.should raise_error(RuntimeError, "different message") { |err|
|
219
|
+
ran = true
|
220
|
+
}
|
221
|
+
}.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
|
222
|
+
|
223
|
+
ran.should == false
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
|
229
|
+
|
230
|
+
it "should pass if nothing is raised" do
|
231
|
+
ran = false
|
232
|
+
|
233
|
+
lambda {}.should_not raise_error(RuntimeError, "example message") { |err|
|
234
|
+
ran = true
|
235
|
+
}
|
236
|
+
|
237
|
+
ran.should == false
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should pass if a different error is raised" do
|
241
|
+
ran = false
|
242
|
+
|
243
|
+
lambda { raise }.should_not raise_error(NameError, "example message") { |err|
|
244
|
+
ran = true
|
245
|
+
}
|
246
|
+
|
247
|
+
ran.should == false
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should pass if same error is raised with different message" do
|
251
|
+
ran = false
|
252
|
+
|
253
|
+
lambda {
|
254
|
+
raise RuntimeError.new("not the example message")
|
255
|
+
}.should_not raise_error(RuntimeError, "example message") { |err|
|
256
|
+
ran = true
|
257
|
+
}
|
258
|
+
|
259
|
+
ran.should == false
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should fail if named error is raised with same message" do
|
263
|
+
ran = false
|
264
|
+
|
265
|
+
lambda {
|
266
|
+
lambda {
|
267
|
+
raise "example message"
|
268
|
+
}.should_not raise_error(RuntimeError, "example message") { |err|
|
269
|
+
ran = true
|
270
|
+
}
|
271
|
+
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
272
|
+
|
273
|
+
ran.should == false
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
describe "should_not raise_error(NamedError, error_message) with String" do
|
279
|
+
|
280
|
+
it "should pass if nothing is raised" do
|
281
|
+
lambda {}.should_not raise_error(RuntimeError, "example message")
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should pass if a different error is raised" do
|
285
|
+
lambda { raise }.should_not raise_error(NameError, "example message")
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should pass if same error is raised with different message" do
|
289
|
+
lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should fail if named error is raised with same message" do
|
293
|
+
lambda {
|
294
|
+
lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
|
295
|
+
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
describe "should raise_error(NamedError, error_message) with Regexp" do
|
301
|
+
|
302
|
+
it "should pass if named error is raised with matching message" do
|
303
|
+
lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
|
304
|
+
end
|
305
|
+
|
306
|
+
it "should fail if nothing is raised" do
|
307
|
+
lambda {
|
308
|
+
lambda {}.should raise_error(RuntimeError, /ample mess/)
|
309
|
+
}.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should fail if incorrect error is raised" do
|
313
|
+
lambda {
|
314
|
+
lambda { raise }.should raise_error(NameError, /ample mess/)
|
315
|
+
}.should fail_with("expected NameError with message matching /ample mess/, got RuntimeError")
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should fail if correct error is raised with incorrect message" do
|
319
|
+
lambda {
|
320
|
+
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
|
321
|
+
}.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
|
322
|
+
end
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "should_not raise_error(NamedError, error_message) with Regexp" do
|
327
|
+
|
328
|
+
it "should pass if nothing is raised" do
|
329
|
+
lambda {}.should_not raise_error(RuntimeError, /ample mess/)
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should pass if a different error is raised" do
|
333
|
+
lambda { raise }.should_not raise_error(NameError, /ample mess/)
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should pass if same error is raised with non-matching message" do
|
337
|
+
lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should fail if named error is raised with matching message" do
|
341
|
+
lambda {
|
342
|
+
lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
|
343
|
+
}.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe "should respond_to(:sym)" do
|
4
|
+
|
5
|
+
it "should pass if target responds to :sym" do
|
6
|
+
Object.new.should respond_to(:methods)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should fail target does not respond to :sym" do
|
10
|
+
lambda {
|
11
|
+
"this string".should respond_to(:some_method)
|
12
|
+
}.should fail_with("expected \"this string\" to respond to :some_method")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "should respond_to(message1, message2)" do
|
18
|
+
|
19
|
+
it "should pass if target responds to both messages" do
|
20
|
+
Object.new.should respond_to('methods', 'inspect')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fail target does not respond to first message" do
|
24
|
+
lambda {
|
25
|
+
Object.new.should respond_to('method_one', 'inspect')
|
26
|
+
}.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should fail target does not respond to second message" do
|
30
|
+
lambda {
|
31
|
+
Object.new.should respond_to('inspect', 'method_one')
|
32
|
+
}.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fail target does not respond to either message" do
|
36
|
+
lambda {
|
37
|
+
Object.new.should respond_to('method_one', 'method_two')
|
38
|
+
}.should fail_with(/expected #<Object:.*> to respond to "method_one", "method_two"/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "should_not respond_to(:sym)" do
|
43
|
+
|
44
|
+
it "should pass if target does not respond to :sym" do
|
45
|
+
Object.new.should_not respond_to(:some_method)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should fail target responds to :sym" do
|
49
|
+
lambda {
|
50
|
+
Object.new.should_not respond_to(:methods)
|
51
|
+
}.should fail_with(/expected #<Object:.*> not to respond to :methods/)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|