spicycode-micronaut 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/Rakefile +23 -10
  2. data/examples/example_helper.rb +3 -3
  3. data/examples/lib/micronaut/behaviour_group_example.rb +175 -0
  4. data/examples/lib/micronaut/expectations/differs/default_example.rb +1 -2
  5. data/examples/lib/micronaut/expectations/extensions/object_example.rb +15 -8
  6. data/examples/lib/micronaut/expectations/fail_with_example.rb +2 -2
  7. data/examples/lib/micronaut/matchers/be_close_example.rb +42 -0
  8. data/examples/lib/micronaut/matchers/be_example.rb +257 -0
  9. data/examples/lib/micronaut/matchers/change_example.rb +329 -0
  10. data/examples/lib/micronaut/matchers/description_generation_example.rb +167 -0
  11. data/examples/lib/micronaut/matchers/eql_example.rb +29 -0
  12. data/examples/lib/micronaut/matchers/equal_example.rb +29 -0
  13. data/examples/lib/micronaut/matchers/exist_example.rb +69 -0
  14. data/examples/lib/micronaut/matchers/handler_example.rb +146 -0
  15. data/examples/lib/micronaut/matchers/has_example.rb +63 -0
  16. data/examples/lib/micronaut/matchers/have_example.rb +575 -0
  17. data/examples/lib/micronaut/matchers/include_example.rb +88 -0
  18. data/examples/lib/micronaut/matchers/match_example.rb +41 -0
  19. data/examples/lib/micronaut/matchers/matcher_methods_example.rb +66 -0
  20. data/examples/lib/micronaut/matchers/operator_matcher_example.rb +191 -0
  21. data/examples/lib/micronaut/matchers/raise_error_example.rb +315 -0
  22. data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
  23. data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
  24. data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
  25. data/examples/lib/micronaut/matchers/throw_symbol_example.rb +96 -0
  26. data/examples/resources/example_classes.rb +67 -0
  27. data/lib/autotest/micronaut.rb +9 -4
  28. data/lib/micronaut/behaviour_group.rb +43 -0
  29. data/lib/micronaut/behaviour_group_class_methods.rb +134 -0
  30. data/lib/micronaut/example_runner.rb +7 -9
  31. data/lib/micronaut/example_world.rb +11 -7
  32. data/lib/micronaut/expectations/differs/default.rb +6 -15
  33. data/lib/micronaut/expectations/errors.rb +7 -0
  34. data/lib/micronaut/expectations/{object_extensions.rb → extensions/object.rb} +5 -4
  35. data/lib/micronaut/expectations/{string_and_symbol_extensions.rb → extensions/string_and_symbol.rb} +0 -0
  36. data/lib/micronaut/expectations/extensions.rb +2 -0
  37. data/lib/micronaut/expectations/wrap_expectation.rb +5 -0
  38. data/lib/micronaut/expectations.rb +5 -5
  39. data/lib/micronaut/extensions/kernel.rb +2 -4
  40. data/lib/micronaut/matchers/be_close.rb +6 -22
  41. data/lib/micronaut/matchers/eql.rb +7 -25
  42. data/lib/micronaut/matchers/equal.rb +6 -24
  43. data/lib/micronaut/matchers/exist.rb +8 -14
  44. data/lib/micronaut/matchers/has.rb +12 -28
  45. data/lib/micronaut/matchers/include.rb +12 -9
  46. data/lib/micronaut/matchers/match.rb +8 -27
  47. data/lib/micronaut/matchers/method_missing.rb +1 -1
  48. data/lib/micronaut/matchers/operator_matcher.rb +23 -46
  49. data/lib/micronaut/matchers/raise_error.rb +4 -8
  50. data/lib/micronaut/matchers/respond_to.rb +2 -1
  51. data/lib/micronaut/matchers/throw_symbol.rb +9 -3
  52. data/lib/micronaut/matchers.rb +10 -3
  53. data/lib/micronaut/mocking/with_mocha.rb +0 -1
  54. data/lib/micronaut.rb +3 -3
  55. metadata +31 -7
  56. data/examples/lib/micronaut/example_group_example.rb +0 -116
  57. data/lib/micronaut/example_group.rb +0 -100
  58. data/lib/micronaut/exceptions.rb +0 -7
@@ -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,191 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ require 'micronaut/expectations/differs/default'
4
+
5
+ describe "should ==" do
6
+
7
+ it "should delegate message to target" do
8
+ subject = "apple"
9
+ subject.expects(:==).with("apple").returns(true)
10
+ subject.should == "apple"
11
+ end
12
+
13
+ it "should return true on success" do
14
+ subject = "apple"
15
+ (subject.should == "apple").should be_true
16
+ end
17
+
18
+ it "should fail when target.==(actual) returns false" do
19
+ subject = "apple"
20
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: "orange",\n got: "apple" (using ==)], "orange", "apple")
21
+ subject.should == "orange"
22
+ end
23
+
24
+ end
25
+
26
+ describe "should_not ==" do
27
+
28
+ it "should delegate message to target" do
29
+ subject = "orange"
30
+ subject.expects(:==).with("apple").returns(false)
31
+ subject.should_not == "apple"
32
+ end
33
+
34
+ it "should return true on success" do
35
+ subject = "apple"
36
+ (subject.should_not == "orange").should be_true
37
+ end
38
+
39
+ it "should fail when target.==(actual) returns false" do
40
+ subject = "apple"
41
+ Micronaut::Expectations.expects(:fail_with).with(%[expected not: == "apple",\n got: "apple"], "apple", "apple")
42
+ subject.should_not == "apple"
43
+ end
44
+
45
+ end
46
+
47
+ describe "should ===" do
48
+
49
+ it "should delegate message to target" do
50
+ subject = "apple"
51
+ subject.expects(:===).with("apple").returns(true)
52
+ subject.should === "apple"
53
+ end
54
+
55
+ it "should fail when target.===(actual) returns false" do
56
+ subject = "apple"
57
+ subject.expects(:===).with("orange").returns(false)
58
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: "orange",\n got: "apple" (using ===)], "orange", "apple")
59
+ subject.should === "orange"
60
+ end
61
+
62
+ end
63
+
64
+ describe "should_not ===" do
65
+
66
+ it "should delegate message to target" do
67
+ subject = "orange"
68
+ subject.expects(:===).with("apple").returns(false)
69
+ subject.should_not === "apple"
70
+ end
71
+
72
+ it "should fail when target.===(actual) returns false" do
73
+ subject = "apple"
74
+ subject.expects(:===).with("apple").returns(true)
75
+ Micronaut::Expectations.expects(:fail_with).with(%[expected not: === "apple",\n got: "apple"], "apple", "apple")
76
+ subject.should_not === "apple"
77
+ end
78
+
79
+ end
80
+
81
+ describe "should =~" do
82
+
83
+ it "should delegate message to target" do
84
+ subject = "foo"
85
+ subject.expects(:=~).with(/oo/).returns(true)
86
+ subject.should =~ /oo/
87
+ end
88
+
89
+ it "should fail when target.=~(actual) returns false" do
90
+ subject = "fu"
91
+ subject.expects(:=~).with(/oo/).returns(false)
92
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: /oo/,\n got: "fu" (using =~)], /oo/, "fu")
93
+ subject.should =~ /oo/
94
+ end
95
+
96
+ end
97
+
98
+ describe "should_not =~" do
99
+
100
+ it "should delegate message to target" do
101
+ subject = "fu"
102
+ subject.expects(:=~).with(/oo/).returns(false)
103
+ subject.should_not =~ /oo/
104
+ end
105
+
106
+ it "should fail when target.=~(actual) returns false" do
107
+ subject = "foo"
108
+ subject.expects(:=~).with(/oo/).returns(true)
109
+ Micronaut::Expectations.expects(:fail_with).with(%[expected not: =~ /oo/,\n got: "foo"], /oo/, "foo")
110
+ subject.should_not =~ /oo/
111
+ end
112
+
113
+ end
114
+
115
+ describe "should >" do
116
+
117
+ it "should pass if > passes" do
118
+ 4.should > 3
119
+ end
120
+
121
+ it "should fail if > fails" do
122
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: > 5,\n got: 4], 5, 4)
123
+ 4.should > 5
124
+ end
125
+
126
+ end
127
+
128
+ describe "should >=" do
129
+
130
+ it "should pass if >= passes" do
131
+ 4.should > 3
132
+ 4.should >= 4
133
+ end
134
+
135
+ it "should fail if > fails" do
136
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: >= 5,\n got: 4], 5, 4)
137
+ 4.should >= 5
138
+ end
139
+
140
+ end
141
+
142
+ describe "should <" do
143
+
144
+ it "should pass if < passes" do
145
+ 4.should < 5
146
+ end
147
+
148
+ it "should fail if > fails" do
149
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: < 3,\n got: 4], 3, 4)
150
+ 4.should < 3
151
+ end
152
+
153
+ end
154
+
155
+ describe "should <=" do
156
+
157
+ it "should pass if <= passes" do
158
+ 4.should <= 5
159
+ 4.should <= 4
160
+ end
161
+
162
+ it "should fail if > fails" do
163
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: <= 3,\n got: 4], 3, 4)
164
+ 4.should <= 3
165
+ end
166
+
167
+ end
168
+
169
+ describe Micronaut::Matchers::PositiveOperatorMatcher do
170
+
171
+ it "should work when the target has implemented #send" do
172
+ o = Object.new
173
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
174
+ lambda {
175
+ o.should == o
176
+ }.should_not raise_error
177
+ end
178
+
179
+ end
180
+
181
+ describe Micronaut::Matchers::NegativeOperatorMatcher do
182
+
183
+ it "should work when the target has implemented #send" do
184
+ o = Object.new
185
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
186
+ lambda {
187
+ o.should_not == :foo
188
+ }.should_not raise_error
189
+ end
190
+
191
+ end
@@ -0,0 +1,315 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_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_not raise_error" do
16
+ it "should pass if nothing is raised" do
17
+ lambda {}.should_not raise_error
18
+ end
19
+
20
+ it "should fail if anything is raised" do
21
+ lambda {
22
+ lambda {raise}.should_not raise_error
23
+ }.should fail_with("expected no Exception, got RuntimeError")
24
+ end
25
+ end
26
+
27
+ describe "should raise_error(message)" do
28
+ it "should pass if RuntimeError is raised with the right message" do
29
+ lambda {raise 'blah'}.should raise_error('blah')
30
+ end
31
+ it "should pass if RuntimeError is raised with a matching message" do
32
+ lambda {raise 'blah'}.should raise_error(/blah/)
33
+ end
34
+ it "should pass if any other error is raised with the right message" do
35
+ lambda {raise NameError.new('blah')}.should raise_error('blah')
36
+ end
37
+ it "should fail if RuntimeError error is raised with the wrong message" do
38
+ lambda do
39
+ lambda {raise 'blarg'}.should raise_error('blah')
40
+ end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
41
+ end
42
+ it "should fail if any other error is raised with the wrong message" do
43
+ lambda do
44
+ lambda {raise NameError.new('blarg')}.should raise_error('blah')
45
+ end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
46
+ end
47
+ end
48
+
49
+ describe "should_not raise_error(message)" do
50
+ it "should pass if RuntimeError error is raised with the different message" do
51
+ lambda {raise 'blarg'}.should_not raise_error('blah')
52
+ end
53
+ it "should pass if any other error is raised with the wrong message" do
54
+ lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
55
+ end
56
+ it "should fail if RuntimeError is raised with message" do
57
+ lambda do
58
+ lambda {raise 'blah'}.should_not raise_error('blah')
59
+ end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
60
+ end
61
+ it "should fail if any other error is raised with message" do
62
+ lambda do
63
+ lambda {raise NameError.new('blah')}.should_not raise_error('blah')
64
+ end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
65
+ end
66
+ end
67
+
68
+ describe "should raise_error(NamedError)" do
69
+ it "should pass if named error is raised" do
70
+ lambda { non_existent_method }.should raise_error(NameError)
71
+ end
72
+
73
+ it "should fail if nothing is raised" do
74
+ lambda {
75
+ lambda { }.should raise_error(NameError)
76
+ }.should fail_with("expected NameError but nothing was raised")
77
+ end
78
+
79
+ it "should fail if another error is raised (NameError)" do
80
+ lambda {
81
+ lambda { raise }.should raise_error(NameError)
82
+ }.should fail_with("expected NameError, got RuntimeError")
83
+ end
84
+
85
+ it "should fail if another error is raised (NameError)" do
86
+ lambda {
87
+ lambda { load "non/existent/file" }.should raise_error(NameError)
88
+ }.should fail_with(/expected NameError, got #<LoadError/)
89
+ end
90
+ end
91
+
92
+ describe "should_not raise_error(NamedError)" do
93
+ it "should pass if nothing is raised" do
94
+ lambda { }.should_not raise_error(NameError)
95
+ end
96
+
97
+ it "should pass if another error is raised" do
98
+ lambda { raise }.should_not raise_error(NameError)
99
+ end
100
+
101
+ it "should fail if named error is raised" do
102
+ lambda {
103
+ lambda { non_existent_method }.should_not raise_error(NameError)
104
+ }.should fail_with(/expected no NameError, got #<NameError: undefined/)
105
+ end
106
+ end
107
+
108
+ describe "should raise_error(NamedError, error_message) with String" do
109
+ it "should pass if named error is raised with same message" do
110
+ lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
111
+ end
112
+
113
+ it "should fail if nothing is raised" do
114
+ lambda {
115
+ lambda {}.should raise_error(RuntimeError, "example message")
116
+ }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
117
+ end
118
+
119
+ it "should fail if incorrect error is raised" do
120
+ lambda {
121
+ lambda { raise }.should raise_error(NameError, "example message")
122
+ }.should fail_with("expected NameError with \"example message\", got RuntimeError")
123
+ end
124
+
125
+ it "should fail if correct error is raised with incorrect message" do
126
+ lambda {
127
+ lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
128
+ }.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
129
+ end
130
+ end
131
+
132
+ describe "should raise_error(NamedError, error_message) { |err| ... }" do
133
+ it "should yield exception if named error is raised with same message" do
134
+ ran = false
135
+
136
+ lambda {
137
+ raise "example message"
138
+ }.should raise_error(RuntimeError, "example message") { |err|
139
+ ran = true
140
+ err.class.should == RuntimeError
141
+ err.message.should == "example message"
142
+ }
143
+
144
+ ran.should == true
145
+ end
146
+
147
+ it "yielded block should be able to fail on it's own right" do
148
+ ran, passed = false, false
149
+
150
+ lambda {
151
+ lambda {
152
+ raise "example message"
153
+ }.should raise_error(RuntimeError, "example message") { |err|
154
+ ran = true
155
+ 5.should == 4
156
+ passed = true
157
+ }
158
+ }.should fail_with(/expected: 4/m)
159
+
160
+ ran.should == true
161
+ passed.should == false
162
+ end
163
+
164
+ it "should NOT yield exception if no error was thrown" do
165
+ ran = false
166
+
167
+ lambda {
168
+ lambda {}.should raise_error(RuntimeError, "example message") { |err|
169
+ ran = true
170
+ }
171
+ }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
172
+
173
+ ran.should == false
174
+ end
175
+
176
+ it "should not yield exception if error class is not matched" do
177
+ ran = false
178
+
179
+ lambda {
180
+ lambda {
181
+ raise "example message"
182
+ }.should raise_error(SyntaxError, "example message") { |err|
183
+ ran = true
184
+ }
185
+ }.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
186
+
187
+ ran.should == false
188
+ end
189
+
190
+ it "should NOT yield exception if error message is not matched" do
191
+ ran = false
192
+
193
+ lambda {
194
+ lambda {
195
+ raise "example message"
196
+ }.should raise_error(RuntimeError, "different message") { |err|
197
+ ran = true
198
+ }
199
+ }.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
200
+
201
+ ran.should == false
202
+ end
203
+ end
204
+
205
+ describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
206
+ it "should pass if nothing is raised" do
207
+ ran = false
208
+
209
+ lambda {}.should_not raise_error(RuntimeError, "example message") { |err|
210
+ ran = true
211
+ }
212
+
213
+ ran.should == false
214
+ end
215
+
216
+ it "should pass if a different error is raised" do
217
+ ran = false
218
+
219
+ lambda { raise }.should_not raise_error(NameError, "example message") { |err|
220
+ ran = true
221
+ }
222
+
223
+ ran.should == false
224
+ end
225
+
226
+ it "should pass if same error is raised with different message" do
227
+ ran = false
228
+
229
+ lambda {
230
+ raise RuntimeError.new("not the example message")
231
+ }.should_not raise_error(RuntimeError, "example message") { |err|
232
+ ran = true
233
+ }
234
+
235
+ ran.should == false
236
+ end
237
+
238
+ it "should fail if named error is raised with same message" do
239
+ ran = false
240
+
241
+ lambda {
242
+ lambda {
243
+ raise "example message"
244
+ }.should_not raise_error(RuntimeError, "example message") { |err|
245
+ ran = true
246
+ }
247
+ }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
248
+
249
+ ran.should == false
250
+ end
251
+ end
252
+
253
+ describe "should_not raise_error(NamedError, error_message) with String" do
254
+ it "should pass if nothing is raised" do
255
+ lambda {}.should_not raise_error(RuntimeError, "example message")
256
+ end
257
+
258
+ it "should pass if a different error is raised" do
259
+ lambda { raise }.should_not raise_error(NameError, "example message")
260
+ end
261
+
262
+ it "should pass if same error is raised with different message" do
263
+ lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
264
+ end
265
+
266
+ it "should fail if named error is raised with same message" do
267
+ lambda {
268
+ lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
269
+ }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
270
+ end
271
+ end
272
+
273
+ describe "should raise_error(NamedError, error_message) with Regexp" do
274
+ it "should pass if named error is raised with matching message" do
275
+ lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
276
+ end
277
+
278
+ it "should fail if nothing is raised" do
279
+ lambda {
280
+ lambda {}.should raise_error(RuntimeError, /ample mess/)
281
+ }.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
282
+ end
283
+
284
+ it "should fail if incorrect error is raised" do
285
+ lambda {
286
+ lambda { raise }.should raise_error(NameError, /ample mess/)
287
+ }.should fail_with("expected NameError with message matching /ample mess/, got RuntimeError")
288
+ end
289
+
290
+ it "should fail if correct error is raised with incorrect message" do
291
+ lambda {
292
+ lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
293
+ }.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
294
+ end
295
+ end
296
+
297
+ describe "should_not raise_error(NamedError, error_message) with Regexp" do
298
+ it "should pass if nothing is raised" do
299
+ lambda {}.should_not raise_error(RuntimeError, /ample mess/)
300
+ end
301
+
302
+ it "should pass if a different error is raised" do
303
+ lambda { raise }.should_not raise_error(NameError, /ample mess/)
304
+ end
305
+
306
+ it "should pass if same error is raised with non-matching message" do
307
+ lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
308
+ end
309
+
310
+ it "should fail if named error is raised with matching message" do
311
+ lambda {
312
+ lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
313
+ }.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
314
+ end
315
+ 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
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe "should satisfy { block }" do
4
+ it "should pass if block returns true" do
5
+ true.should satisfy { |val| val }
6
+ true.should satisfy do |val|
7
+ val
8
+ end
9
+ end
10
+
11
+ it "should fail if block returns false" do
12
+ lambda {
13
+ false.should satisfy { |val| val }
14
+ }.should fail_with("expected false to satisfy block")
15
+ lambda do
16
+ false.should satisfy do |val|
17
+ val
18
+ end
19
+ end.should fail_with("expected false to satisfy block")
20
+ end
21
+ end
22
+
23
+ describe "should_not satisfy { block }" do
24
+ it "should pass if block returns false" do
25
+ false.should_not satisfy { |val| val }
26
+ false.should_not satisfy do |val|
27
+ val
28
+ end
29
+ end
30
+
31
+ it "should fail if block returns true" do
32
+ lambda {
33
+ true.should_not satisfy { |val| val }
34
+ }.should fail_with("expected true not to satisfy block")
35
+ end
36
+ end