spicycode-micronaut 0.0.2 → 0.0.3

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.
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,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(:each) 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(:each) 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(:each) 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(:each) 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(:each) 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(:each) 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(:each) 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(:each) 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(:each) 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(:each) 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,88 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe "should include(expected)" do
4
+ it "should pass if target includes expected" do
5
+ [1,2,3].should include(3)
6
+ "abc".should include("a")
7
+ end
8
+
9
+ it 'should pass if target is a Hash and has the expected as a key' do
10
+ {:key => 'value'}.should include(:key)
11
+ end
12
+
13
+ it "should fail if target does not include expected" do
14
+ lambda {
15
+ [1,2,3].should include(4)
16
+ }.should fail_with("expected [1, 2, 3] to include 4")
17
+ lambda {
18
+ "abc".should include("d")
19
+ }.should fail_with("expected \"abc\" to include \"d\"")
20
+ lambda {
21
+ {:key => 'value'}.should include(:other)
22
+ }.should fail_with(%Q|expected {:key=>"value"} to include :other|)
23
+ end
24
+ end
25
+
26
+ describe "should include(with, multiple, args)" do
27
+ it "should pass if target includes all items" do
28
+ [1,2,3].should include(1,2,3)
29
+ end
30
+
31
+ it 'should pass if target is a Hash including all items as keys' do
32
+ {:key => 'value', :other => 'value'}.should include(:key, :other)
33
+ end
34
+
35
+ it "should fail if target does not include any one of the items" do
36
+ lambda {
37
+ [1,2,3].should include(1,2,4)
38
+ }.should fail_with("expected [1, 2, 3] to include 1, 2 and 4")
39
+ end
40
+
41
+ it 'should pass if target is a Hash missing any item as a key' do
42
+ lambda {
43
+ {:key => 'value'}.should include(:key, :other)
44
+ }.should fail_with(%Q|expected {:key=>"value"} to include :key and :other|)
45
+ end
46
+ end
47
+
48
+ describe "should_not include(expected)" do
49
+ it "should pass if target does not include expected" do
50
+ [1,2,3].should_not include(4)
51
+ "abc".should_not include("d")
52
+ end
53
+
54
+ it 'should pass if target is a Hash and does not have the expected as a key' do
55
+ {:other => 'value'}.should_not include(:key)
56
+ end
57
+
58
+ it "should fail if target includes expected" do
59
+ lambda {
60
+ [1,2,3].should_not include(3)
61
+ }.should fail_with("expected [1, 2, 3] not to include 3")
62
+ lambda {
63
+ "abc".should_not include("c")
64
+ }.should fail_with("expected \"abc\" not to include \"c\"")
65
+ lambda {
66
+ {:key => 'value'}.should_not include(:key)
67
+ }.should fail_with(%Q|expected {:key=>"value"} not to include :key|)
68
+ end
69
+ end
70
+
71
+ describe "should include(:key => value)" do
72
+ it "should pass if target is a Hash and includes the key/value pair" do
73
+ {:key => 'value'}.should include(:key => 'value')
74
+ end
75
+ it "should pass if target is a Hash and includes the key/value pair among others" do
76
+ {:key => 'value', :other => 'different'}.should include(:key => 'value')
77
+ end
78
+ it "should fail if target is a Hash and has a different value for key" do
79
+ lambda {
80
+ {:key => 'different'}.should include(:key => 'value')
81
+ }.should fail_with(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
82
+ end
83
+ it "should fail if target is a Hash and has a different key" do
84
+ lambda {
85
+ {:other => 'value'}.should include(:key => 'value')
86
+ }.should fail_with(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
87
+ end
88
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe "should match(expected)" do
4
+
5
+ it "should pass when target (String) matches expected (Regexp)" do
6
+ "string".should match(/tri/)
7
+ end
8
+
9
+ it "should fail when target (String) does not match expected (Regexp)" do
10
+ lambda {
11
+ "string".should match(/rings/)
12
+ }.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