rsanheim-micronaut 0.1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/LICENSE +45 -0
  2. data/README +17 -0
  3. data/RSPEC-LICENSE +23 -0
  4. data/Rakefile +83 -0
  5. data/bin/micronaut +4 -0
  6. data/examples/example_helper.rb +36 -0
  7. data/examples/lib/micronaut/behaviour_example.rb +188 -0
  8. data/examples/lib/micronaut/configuration_example.rb +70 -0
  9. data/examples/lib/micronaut/example_example.rb +46 -0
  10. data/examples/lib/micronaut/expectations/extensions/object_example.rb +72 -0
  11. data/examples/lib/micronaut/expectations/fail_with_example.rb +17 -0
  12. data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +31 -0
  13. data/examples/lib/micronaut/formatters/base_formatter_example.rb +107 -0
  14. data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
  15. data/examples/lib/micronaut/formatters/progress_formatter_example.rb +74 -0
  16. data/examples/lib/micronaut/kernel_extensions_example.rb +13 -0
  17. data/examples/lib/micronaut/matchers/be_close_example.rb +52 -0
  18. data/examples/lib/micronaut/matchers/be_example.rb +298 -0
  19. data/examples/lib/micronaut/matchers/change_example.rb +360 -0
  20. data/examples/lib/micronaut/matchers/description_generation_example.rb +175 -0
  21. data/examples/lib/micronaut/matchers/eql_example.rb +35 -0
  22. data/examples/lib/micronaut/matchers/equal_example.rb +35 -0
  23. data/examples/lib/micronaut/matchers/handler_example.rb +153 -0
  24. data/examples/lib/micronaut/matchers/has_example.rb +71 -0
  25. data/examples/lib/micronaut/matchers/have_example.rb +575 -0
  26. data/examples/lib/micronaut/matchers/include_example.rb +103 -0
  27. data/examples/lib/micronaut/matchers/match_example.rb +43 -0
  28. data/examples/lib/micronaut/matchers/matcher_methods_example.rb +66 -0
  29. data/examples/lib/micronaut/matchers/operator_matcher_example.rb +189 -0
  30. data/examples/lib/micronaut/matchers/raise_error_example.rb +346 -0
  31. data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
  32. data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
  33. data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
  34. data/examples/lib/micronaut/matchers/throw_symbol_example.rb +96 -0
  35. data/examples/lib/micronaut/runner_example.rb +5 -0
  36. data/examples/lib/micronaut/runner_options_example.rb +5 -0
  37. data/examples/lib/micronaut/world_example.rb +102 -0
  38. data/examples/lib/micronaut_example.rb +23 -0
  39. data/examples/resources/example_classes.rb +67 -0
  40. data/lib/autotest/discover.rb +3 -0
  41. data/lib/autotest/micronaut.rb +47 -0
  42. data/lib/micronaut/behaviour.rb +211 -0
  43. data/lib/micronaut/configuration.rb +133 -0
  44. data/lib/micronaut/example.rb +28 -0
  45. data/lib/micronaut/expectations/extensions/object.rb +62 -0
  46. data/lib/micronaut/expectations/extensions/string_and_symbol.rb +19 -0
  47. data/lib/micronaut/expectations/handler.rb +52 -0
  48. data/lib/micronaut/expectations/wrap_expectation.rb +57 -0
  49. data/lib/micronaut/expectations.rb +46 -0
  50. data/lib/micronaut/formatters/base_formatter.rb +82 -0
  51. data/lib/micronaut/formatters/base_text_formatter.rb +148 -0
  52. data/lib/micronaut/formatters/documentation_formatter.rb +62 -0
  53. data/lib/micronaut/formatters/progress_formatter.rb +36 -0
  54. data/lib/micronaut/formatters.rb +12 -0
  55. data/lib/micronaut/kernel_extensions.rb +11 -0
  56. data/lib/micronaut/matchers/be.rb +204 -0
  57. data/lib/micronaut/matchers/be_close.rb +22 -0
  58. data/lib/micronaut/matchers/change.rb +148 -0
  59. data/lib/micronaut/matchers/eql.rb +26 -0
  60. data/lib/micronaut/matchers/equal.rb +26 -0
  61. data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
  62. data/lib/micronaut/matchers/has.rb +19 -0
  63. data/lib/micronaut/matchers/have.rb +153 -0
  64. data/lib/micronaut/matchers/include.rb +80 -0
  65. data/lib/micronaut/matchers/match.rb +22 -0
  66. data/lib/micronaut/matchers/method_missing.rb +9 -0
  67. data/lib/micronaut/matchers/operator_matcher.rb +50 -0
  68. data/lib/micronaut/matchers/raise_error.rb +128 -0
  69. data/lib/micronaut/matchers/respond_to.rb +50 -0
  70. data/lib/micronaut/matchers/satisfy.rb +50 -0
  71. data/lib/micronaut/matchers/simple_matcher.rb +135 -0
  72. data/lib/micronaut/matchers/throw_symbol.rb +108 -0
  73. data/lib/micronaut/matchers.rb +148 -0
  74. data/lib/micronaut/mocking/with_absolutely_nothing.rb +11 -0
  75. data/lib/micronaut/mocking/with_mocha.rb +13 -0
  76. data/lib/micronaut/mocking/with_rr.rb +24 -0
  77. data/lib/micronaut/mocking.rb +7 -0
  78. data/lib/micronaut/runner.rb +57 -0
  79. data/lib/micronaut/runner_options.rb +33 -0
  80. data/lib/micronaut/world.rb +75 -0
  81. data/lib/micronaut.rb +37 -0
  82. metadata +149 -0
@@ -0,0 +1,575 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ # share_as :HaveMicronautHelper do
4
+ # def create_collection_owner_with(n)
5
+ # owner = Micronaut::Expectations::Helper::CollectionOwner.new
6
+ # (1..n).each do |n|
7
+ # owner.add_to_collection_with_length_method(n)
8
+ # owner.add_to_collection_with_size_method(n)
9
+ # end
10
+ # owner
11
+ # end
12
+ # before do
13
+ # unless defined?(ActiveSupport::Inflector)
14
+ # @active_support_was_not_defined
15
+ # module ActiveSupport
16
+ # class Inflector
17
+ # def self.pluralize(string)
18
+ # string.to_s + 's'
19
+ # end
20
+ # end
21
+ # end
22
+ # end
23
+ # end
24
+ # end
25
+
26
+
27
+ describe "should have(n).items" do
28
+ # include HaveMicronautHelper
29
+
30
+ def create_collection_owner_with(n)
31
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
32
+ (1..n).each do |n|
33
+ owner.add_to_collection_with_length_method(n)
34
+ owner.add_to_collection_with_size_method(n)
35
+ end
36
+ owner
37
+ end
38
+
39
+ before do
40
+ unless defined?(ActiveSupport::Inflector)
41
+ @active_support_was_not_defined
42
+ module ActiveSupport
43
+ class Inflector
44
+ def self.pluralize(string)
45
+ string.to_s + 's'
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ it "should pass if target has a collection of items with n members" do
53
+ owner = create_collection_owner_with(3)
54
+ owner.should have(3).items_in_collection_with_length_method
55
+ owner.should have(3).items_in_collection_with_size_method
56
+ end
57
+
58
+ it "should convert :no to 0" do
59
+ owner = create_collection_owner_with(0)
60
+ owner.should have(:no).items_in_collection_with_length_method
61
+ owner.should have(:no).items_in_collection_with_size_method
62
+ end
63
+
64
+ it "should fail if target has a collection of items with < n members" do
65
+ owner = create_collection_owner_with(3)
66
+ lambda {
67
+ owner.should have(4).items_in_collection_with_length_method
68
+ }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
69
+ lambda {
70
+ owner.should have(4).items_in_collection_with_size_method
71
+ }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
72
+ end
73
+
74
+ it "should fail if target has a collection of items with > n members" do
75
+ owner = create_collection_owner_with(3)
76
+ lambda {
77
+ owner.should have(2).items_in_collection_with_length_method
78
+ }.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
79
+ lambda {
80
+ owner.should have(2).items_in_collection_with_size_method
81
+ }.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
82
+ end
83
+ end
84
+
85
+ describe 'should have(1).item when ActiveSupport::Inflector is defined' do
86
+ # include HaveMicronautHelper
87
+
88
+ def create_collection_owner_with(n)
89
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
90
+ (1..n).each do |n|
91
+ owner.add_to_collection_with_length_method(n)
92
+ owner.add_to_collection_with_size_method(n)
93
+ end
94
+ owner
95
+ end
96
+
97
+ before do
98
+ unless defined?(ActiveSupport::Inflector)
99
+ @active_support_was_not_defined
100
+ module ActiveSupport
101
+ class Inflector
102
+ def self.pluralize(string)
103
+ string.to_s + 's'
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ it 'should pluralize the collection name' do
111
+ owner = create_collection_owner_with(1)
112
+ owner.should have(1).item
113
+ end
114
+
115
+ after do
116
+ if @active_support_was_not_defined
117
+ Object.__send__ :remove_const, :ActiveSupport
118
+ end
119
+ end
120
+ end
121
+
122
+ describe 'should have(1).item when Inflector is defined' do
123
+ # include HaveMicronautHelper
124
+
125
+ def create_collection_owner_with(n)
126
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
127
+ (1..n).each do |n|
128
+ owner.add_to_collection_with_length_method(n)
129
+ owner.add_to_collection_with_size_method(n)
130
+ end
131
+ owner
132
+ end
133
+
134
+ before do
135
+ unless defined?(ActiveSupport::Inflector)
136
+ @active_support_was_not_defined
137
+ module ActiveSupport
138
+ class Inflector
139
+ def self.pluralize(string)
140
+ string.to_s + 's'
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ before do
148
+ unless defined?(Inflector)
149
+ @inflector_was_not_defined
150
+ class Inflector
151
+ def self.pluralize(string)
152
+ string.to_s + 's'
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ it 'should pluralize the collection name' do
159
+ owner = create_collection_owner_with(1)
160
+ owner.should have(1).item
161
+ end
162
+
163
+ after do
164
+ if @inflector_was_not_defined
165
+ Object.__send__ :remove_const, :Inflector
166
+ end
167
+ end
168
+ end
169
+
170
+ describe "should have(n).items where result responds to items but returns something other than a collection" do
171
+ it "should provide a meaningful error" do
172
+ owner = Class.new do
173
+ def items
174
+ Object.new
175
+ end
176
+ end.new
177
+ lambda do
178
+ owner.should have(3).items
179
+ end.should raise_error("expected items to be a collection but it does not respond to #length or #size")
180
+ end
181
+ end
182
+
183
+ describe "should_not have(n).items" do
184
+ # include HaveMicronautHelper
185
+
186
+ def create_collection_owner_with(n)
187
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
188
+ (1..n).each do |n|
189
+ owner.add_to_collection_with_length_method(n)
190
+ owner.add_to_collection_with_size_method(n)
191
+ end
192
+ owner
193
+ end
194
+
195
+ before do
196
+ unless defined?(ActiveSupport::Inflector)
197
+ @active_support_was_not_defined
198
+ module ActiveSupport
199
+ class Inflector
200
+ def self.pluralize(string)
201
+ string.to_s + 's'
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+ it "should pass if target has a collection of items with < n members" do
209
+ owner = create_collection_owner_with(3)
210
+ owner.should_not have(4).items_in_collection_with_length_method
211
+ owner.should_not have(4).items_in_collection_with_size_method
212
+ end
213
+
214
+ it "should pass if target has a collection of items with > n members" do
215
+ owner = create_collection_owner_with(3)
216
+ owner.should_not have(2).items_in_collection_with_length_method
217
+ owner.should_not have(2).items_in_collection_with_size_method
218
+ end
219
+
220
+ it "should fail if target has a collection of items with n members" do
221
+ owner = create_collection_owner_with(3)
222
+ lambda {
223
+ owner.should_not have(3).items_in_collection_with_length_method
224
+ }.should fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
225
+ lambda {
226
+ owner.should_not have(3).items_in_collection_with_size_method
227
+ }.should fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
228
+ end
229
+ end
230
+
231
+ describe "should have_exactly(n).items" do
232
+ # include HaveMicronautHelper
233
+
234
+ def create_collection_owner_with(n)
235
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
236
+ (1..n).each do |n|
237
+ owner.add_to_collection_with_length_method(n)
238
+ owner.add_to_collection_with_size_method(n)
239
+ end
240
+ owner
241
+ end
242
+
243
+ before do
244
+ unless defined?(ActiveSupport::Inflector)
245
+ @active_support_was_not_defined
246
+ module ActiveSupport
247
+ class Inflector
248
+ def self.pluralize(string)
249
+ string.to_s + 's'
250
+ end
251
+ end
252
+ end
253
+ end
254
+ end
255
+
256
+ it "should pass if target has a collection of items with n members" do
257
+ owner = create_collection_owner_with(3)
258
+ owner.should have_exactly(3).items_in_collection_with_length_method
259
+ owner.should have_exactly(3).items_in_collection_with_size_method
260
+ end
261
+
262
+ it "should convert :no to 0" do
263
+ owner = create_collection_owner_with(0)
264
+ owner.should have_exactly(:no).items_in_collection_with_length_method
265
+ owner.should have_exactly(:no).items_in_collection_with_size_method
266
+ end
267
+
268
+ it "should fail if target has a collection of items with < n members" do
269
+ owner = create_collection_owner_with(3)
270
+ lambda {
271
+ owner.should have_exactly(4).items_in_collection_with_length_method
272
+ }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
273
+ lambda {
274
+ owner.should have_exactly(4).items_in_collection_with_size_method
275
+ }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
276
+ end
277
+
278
+ it "should fail if target has a collection of items with > n members" do
279
+ owner = create_collection_owner_with(3)
280
+ lambda {
281
+ owner.should have_exactly(2).items_in_collection_with_length_method
282
+ }.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
283
+ lambda {
284
+ owner.should have_exactly(2).items_in_collection_with_size_method
285
+ }.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
286
+ end
287
+ end
288
+
289
+ describe "should have_at_least(n).items" do
290
+ # include HaveMicronautHelper
291
+
292
+ def create_collection_owner_with(n)
293
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
294
+ (1..n).each do |n|
295
+ owner.add_to_collection_with_length_method(n)
296
+ owner.add_to_collection_with_size_method(n)
297
+ end
298
+ owner
299
+ end
300
+
301
+ before do
302
+ unless defined?(ActiveSupport::Inflector)
303
+ @active_support_was_not_defined
304
+ module ActiveSupport
305
+ class Inflector
306
+ def self.pluralize(string)
307
+ string.to_s + 's'
308
+ end
309
+ end
310
+ end
311
+ end
312
+ end
313
+
314
+ it "should pass if target has a collection of items with n members" do
315
+ owner = create_collection_owner_with(3)
316
+ owner.should have_at_least(3).items_in_collection_with_length_method
317
+ owner.should have_at_least(3).items_in_collection_with_size_method
318
+ end
319
+
320
+ it "should pass if target has a collection of items with > n members" do
321
+ owner = create_collection_owner_with(3)
322
+ owner.should have_at_least(2).items_in_collection_with_length_method
323
+ owner.should have_at_least(2).items_in_collection_with_size_method
324
+ end
325
+
326
+ it "should fail if target has a collection of items with < n members" do
327
+ owner = create_collection_owner_with(3)
328
+ lambda {
329
+ owner.should have_at_least(4).items_in_collection_with_length_method
330
+ }.should fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
331
+ lambda {
332
+ owner.should have_at_least(4).items_in_collection_with_size_method
333
+ }.should fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
334
+ end
335
+
336
+ it "should provide educational negative failure messages" do
337
+ #given
338
+ owner = create_collection_owner_with(3)
339
+ length_matcher = have_at_least(3).items_in_collection_with_length_method
340
+ size_matcher = have_at_least(3).items_in_collection_with_size_method
341
+
342
+ #when
343
+ length_matcher.matches?(owner)
344
+ size_matcher.matches?(owner)
345
+
346
+ #then
347
+ length_matcher.negative_failure_message.should == <<-EOF
348
+ Isn't life confusing enough?
349
+ Instead of having to figure out the meaning of this:
350
+ should_not have_at_least(3).items_in_collection_with_length_method
351
+ We recommend that you use this instead:
352
+ should have_at_most(2).items_in_collection_with_length_method
353
+ EOF
354
+
355
+ size_matcher.negative_failure_message.should == <<-EOF
356
+ Isn't life confusing enough?
357
+ Instead of having to figure out the meaning of this:
358
+ should_not have_at_least(3).items_in_collection_with_size_method
359
+ We recommend that you use this instead:
360
+ should have_at_most(2).items_in_collection_with_size_method
361
+ EOF
362
+ end
363
+ end
364
+
365
+ describe "should have_at_most(n).items" do
366
+ # include HaveMicronautHelper
367
+
368
+ def create_collection_owner_with(n)
369
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
370
+ (1..n).each do |n|
371
+ owner.add_to_collection_with_length_method(n)
372
+ owner.add_to_collection_with_size_method(n)
373
+ end
374
+ owner
375
+ end
376
+
377
+ before do
378
+ unless defined?(ActiveSupport::Inflector)
379
+ @active_support_was_not_defined
380
+ module ActiveSupport
381
+ class Inflector
382
+ def self.pluralize(string)
383
+ string.to_s + 's'
384
+ end
385
+ end
386
+ end
387
+ end
388
+ end
389
+
390
+ it "should pass if target has a collection of items with n members" do
391
+ owner = create_collection_owner_with(3)
392
+ owner.should have_at_most(3).items_in_collection_with_length_method
393
+ owner.should have_at_most(3).items_in_collection_with_size_method
394
+ end
395
+
396
+ it "should fail if target has a collection of items with > n members" do
397
+ owner = create_collection_owner_with(3)
398
+ lambda {
399
+ owner.should have_at_most(2).items_in_collection_with_length_method
400
+ }.should fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
401
+ lambda {
402
+ owner.should have_at_most(2).items_in_collection_with_size_method
403
+ }.should fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
404
+ end
405
+
406
+ it "should pass if target has a collection of items with < n members" do
407
+ owner = create_collection_owner_with(3)
408
+ owner.should have_at_most(4).items_in_collection_with_length_method
409
+ owner.should have_at_most(4).items_in_collection_with_size_method
410
+ end
411
+
412
+ it "should provide educational negative failure messages" do
413
+ #given
414
+ owner = create_collection_owner_with(3)
415
+ length_matcher = have_at_most(3).items_in_collection_with_length_method
416
+ size_matcher = have_at_most(3).items_in_collection_with_size_method
417
+
418
+ #when
419
+ length_matcher.matches?(owner)
420
+ size_matcher.matches?(owner)
421
+
422
+ #then
423
+ length_matcher.negative_failure_message.should == <<-EOF
424
+ Isn't life confusing enough?
425
+ Instead of having to figure out the meaning of this:
426
+ should_not have_at_most(3).items_in_collection_with_length_method
427
+ We recommend that you use this instead:
428
+ should have_at_least(4).items_in_collection_with_length_method
429
+ EOF
430
+
431
+ size_matcher.negative_failure_message.should == <<-EOF
432
+ Isn't life confusing enough?
433
+ Instead of having to figure out the meaning of this:
434
+ should_not have_at_most(3).items_in_collection_with_size_method
435
+ We recommend that you use this instead:
436
+ should have_at_least(4).items_in_collection_with_size_method
437
+ EOF
438
+ end
439
+ end
440
+
441
+ describe "have(n).items(args, block)" do
442
+ it "should pass args to target" do
443
+ target = mock("target")
444
+ target.expects(:items).with("arg1","arg2").returns([1,2,3])
445
+ target.should have(3).items("arg1","arg2")
446
+ end
447
+
448
+ it "should pass block to target" do
449
+ target = mock("target")
450
+ block = lambda { 5 }
451
+ target.expects(:items).with("arg1","arg2", block).returns([1,2,3])
452
+ target.should have(3).items("arg1","arg2", block)
453
+ end
454
+ end
455
+
456
+ describe "have(n).items where target IS a collection" do
457
+ it "should reference the number of items IN the collection" do
458
+ [1,2,3].should have(3).items
459
+ end
460
+
461
+ it "should fail when the number of items IN the collection is not as expected" do
462
+ lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
463
+ end
464
+ end
465
+
466
+ describe "have(n).characters where target IS a String" do
467
+ it "should pass if the length is correct" do
468
+ "this string".should have(11).characters
469
+ end
470
+
471
+ it "should fail if the length is incorrect" do
472
+ lambda { "this string".should have(12).characters }.should fail_with("expected 12 characters, got 11")
473
+ end
474
+ end
475
+
476
+ describe "have(n).things on an object which is not a collection nor contains one" do
477
+ it "should fail" do
478
+ lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
479
+ end
480
+ end
481
+
482
+ describe Micronaut::Matchers::Have, "for a collection owner that implements #send" do
483
+ # include HaveMicronautHelper
484
+
485
+ def create_collection_owner_with(n)
486
+ owner = Micronaut::Expectations::Helper::CollectionOwner.new
487
+ (1..n).each do |n|
488
+ owner.add_to_collection_with_length_method(n)
489
+ owner.add_to_collection_with_size_method(n)
490
+ end
491
+ owner
492
+ end
493
+
494
+ before do
495
+ unless defined?(ActiveSupport::Inflector)
496
+ @active_support_was_not_defined
497
+ module ActiveSupport
498
+ class Inflector
499
+ def self.pluralize(string)
500
+ string.to_s + 's'
501
+ end
502
+ end
503
+ end
504
+ end
505
+ end
506
+
507
+ before do
508
+ @collection = Object.new
509
+ def @collection.floozles; [1,2] end
510
+ def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
511
+ end
512
+
513
+ it "should work in the straightforward case" do
514
+ lambda {
515
+ @collection.should have(2).floozles
516
+ }.should_not raise_error
517
+ end
518
+
519
+ it "should work when doing automatic pluralization" do
520
+ lambda {
521
+ @collection.should have_at_least(1).floozle
522
+ }.should_not raise_error
523
+ end
524
+
525
+ it "should blow up when the owner doesn't respond to that method" do
526
+ lambda {
527
+ @collection.should have(99).problems
528
+ }.should raise_error(NoMethodError, /problems/)
529
+ end
530
+ end
531
+
532
+ module Micronaut
533
+ module Matchers
534
+ describe Have do
535
+ it "should have method_missing as private" do
536
+ # with_ruby '1.8' do
537
+ Have.private_instance_methods.should include("method_missing")
538
+ # end
539
+ # with_ruby '1.9' do
540
+ # Have.private_instance_methods.should include(:method_missing)
541
+ # end
542
+ end
543
+
544
+ describe "respond_to?" do
545
+ before :each do
546
+ @have = Have.new(:foo)
547
+ @a_method_which_have_defines = Have.instance_methods.first
548
+ @a_method_which_object_defines = Object.instance_methods.first
549
+ end
550
+
551
+ it "should be true for a method which Have defines" do
552
+ @have.should respond_to(@a_method_which_have_defines)
553
+ end
554
+
555
+ it "should be true for a method that it's superclass (Object) defines" do
556
+ @have.should respond_to(@a_method_which_object_defines)
557
+ end
558
+
559
+ it "should be false for a method which neither Object nor nor Have defines" do
560
+ @have.should_not respond_to(:foo_bar_baz)
561
+ end
562
+
563
+ it "should be false if the owner doesn't respond to the method" do
564
+ have = Have.new(99)
565
+ have.should_not respond_to(:problems)
566
+ end
567
+
568
+ it "should be true if the owner responds to the method" do
569
+ have = Have.new(:a_symbol)
570
+ have.should respond_to(:to_sym)
571
+ end
572
+ end
573
+ end
574
+ end
575
+ end
@@ -0,0 +1,103 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers do
4
+
5
+ describe "should include(expected)" do
6
+
7
+ it "should pass if target includes expected" do
8
+ [1,2,3].should include(3)
9
+ "abc".should include("a")
10
+ end
11
+
12
+ it 'should pass if target is a Hash and has the expected as a key' do
13
+ {:key => 'value'}.should include(:key)
14
+ end
15
+
16
+ it "should fail if target does not include expected" do
17
+ lambda do
18
+ [1,2,3].should include(4)
19
+ end.should fail_with("expected [1, 2, 3] to include 4")
20
+ lambda do
21
+ "abc".should include("d")
22
+ end.should fail_with("expected \"abc\" to include \"d\"")
23
+ lambda do
24
+ {:key => 'value'}.should include(:other)
25
+ end.should fail_with(%Q|expected {:key=>"value"} to include :other|)
26
+ end
27
+
28
+ end
29
+
30
+ describe "should include(with, multiple, args)" do
31
+
32
+ it "should pass if target includes all items" do
33
+ [1,2,3].should include(1,2,3)
34
+ end
35
+
36
+ it 'should pass if target is a Hash including all items as keys' do
37
+ {:key => 'value', :other => 'value'}.should include(:key, :other)
38
+ end
39
+
40
+ it "should fail if target does not include any one of the items" do
41
+ lambda do
42
+ [1,2,3].should include(1,2,4)
43
+ end.should fail_with("expected [1, 2, 3] to include 1, 2 and 4")
44
+ end
45
+
46
+ it 'should pass if target is a Hash missing any item as a key' do
47
+ lambda do
48
+ {:key => 'value'}.should include(:key, :other)
49
+ end.should fail_with(%Q|expected {:key=>"value"} to include :key and :other|)
50
+ end
51
+
52
+ end
53
+
54
+ describe "should_not include(expected)" do
55
+
56
+ it "should pass if target does not include expected" do
57
+ [1,2,3].should_not include(4)
58
+ "abc".should_not include("d")
59
+ end
60
+
61
+ it 'should pass if target is a Hash and does not have the expected as a key' do
62
+ {:other => 'value'}.should_not include(:key)
63
+ end
64
+
65
+ it "should fail if target includes expected" do
66
+ lambda {
67
+ [1,2,3].should_not include(3)
68
+ }.should fail_with("expected [1, 2, 3] not to include 3")
69
+ lambda {
70
+ "abc".should_not include("c")
71
+ }.should fail_with("expected \"abc\" not to include \"c\"")
72
+ lambda {
73
+ {:key => 'value'}.should_not include(:key)
74
+ }.should fail_with(%Q|expected {:key=>"value"} not to include :key|)
75
+ end
76
+
77
+ end
78
+
79
+ describe "should include(:key => value)" do
80
+
81
+ it "should pass if target is a Hash and includes the key/value pair" do
82
+ {:key => 'value'}.should include(:key => 'value')
83
+ end
84
+
85
+ it "should pass if target is a Hash and includes the key/value pair among others" do
86
+ {:key => 'value', :other => 'different'}.should include(:key => 'value')
87
+ end
88
+
89
+ it "should fail if target is a Hash and has a different value for key" do
90
+ lambda {
91
+ {:key => 'different'}.should include(:key => 'value')
92
+ }.should fail_with(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
93
+ end
94
+
95
+ it "should fail if target is a Hash and has a different key" do
96
+ lambda {
97
+ {:other => 'value'}.should include(:key => 'value')
98
+ }.should fail_with(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
99
+ end
100
+
101
+ end
102
+
103
+ end