jordi-xml_struct 0.2.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/README.rdoc +152 -0
  2. data/WHATSNEW +10 -0
  3. data/lib/xml_struct/adapters/hpricot.rb +47 -0
  4. data/lib/xml_struct/adapters/rexml.rb +34 -0
  5. data/lib/xml_struct/array_notation.rb +44 -0
  6. data/lib/xml_struct/blankish_slate.rb +1 -1
  7. data/lib/xml_struct/collection_proxy.rb +7 -3
  8. data/lib/xml_struct/default_adapter.rb +15 -0
  9. data/lib/xml_struct/method_missing_dispatchers.rb +43 -0
  10. data/lib/xml_struct/string.rb +6 -2
  11. data/lib/xml_struct.rb +31 -52
  12. data/xml_struct.gemspec +38 -0
  13. metadata +17 -49
  14. data/README.markdown +0 -151
  15. data/Rakefile +0 -36
  16. data/lib/xml_struct/common_behaviours.rb +0 -53
  17. data/test/samples/lorem.xml +0 -63
  18. data/test/samples/recipe.xml +0 -16
  19. data/test/samples/weird_characters.xml +0 -2
  20. data/test/test_helper.rb +0 -39
  21. data/test/vendor/test-spec/README +0 -378
  22. data/test/vendor/test-spec/ROADMAP +0 -1
  23. data/test/vendor/test-spec/Rakefile +0 -146
  24. data/test/vendor/test-spec/SPECS +0 -161
  25. data/test/vendor/test-spec/TODO +0 -2
  26. data/test/vendor/test-spec/bin/specrb +0 -107
  27. data/test/vendor/test-spec/examples/stack.rb +0 -38
  28. data/test/vendor/test-spec/examples/stack_spec.rb +0 -119
  29. data/test/vendor/test-spec/lib/test/spec/dox.rb +0 -148
  30. data/test/vendor/test-spec/lib/test/spec/rdox.rb +0 -25
  31. data/test/vendor/test-spec/lib/test/spec/should-output.rb +0 -49
  32. data/test/vendor/test-spec/lib/test/spec/version.rb +0 -8
  33. data/test/vendor/test-spec/lib/test/spec.rb +0 -660
  34. data/test/vendor/test-spec/test/spec_dox.rb +0 -39
  35. data/test/vendor/test-spec/test/spec_flexmock.rb +0 -209
  36. data/test/vendor/test-spec/test/spec_mocha.rb +0 -104
  37. data/test/vendor/test-spec/test/spec_nestedcontexts.rb +0 -26
  38. data/test/vendor/test-spec/test/spec_new_style.rb +0 -80
  39. data/test/vendor/test-spec/test/spec_should-output.rb +0 -26
  40. data/test/vendor/test-spec/test/spec_testspec.rb +0 -699
  41. data/test/vendor/test-spec/test/spec_testspec_order.rb +0 -26
  42. data/test/vendor/test-spec/test/test_testunit.rb +0 -22
  43. data/test/xml_struct_test.rb +0 -185
@@ -1,26 +0,0 @@
1
- $: << File.dirname(__FILE__) + '/../lib/'
2
- require 'test/spec'
3
- require 'test/spec/should-output'
4
-
5
- context "should.output" do
6
- specify "works for print" do
7
- lambda { print "foo" }.should.output "foo"
8
- lambda { print "foo" }.should.output(/oo/)
9
- end
10
-
11
- specify "works for puts" do
12
- lambda { puts "foo" }.should.output "foo\n"
13
- lambda { puts "foo" }.should.output(/foo/)
14
- end
15
-
16
- specify "works with readline" do
17
- lambda { require 'readline' }.should.not.raise(LoadError)
18
- lambda { puts "foo" }.should.output "foo\n"
19
- lambda { puts "foo" }.should.output(/foo/)
20
-
21
- File.should.not.exist(File.join(Dir.tmpdir, "should_output_#{$$}"))
22
- end
23
- end
24
-
25
-
26
-
@@ -1,699 +0,0 @@
1
- $: << File.dirname(__FILE__) + '/../lib/'
2
- require 'test/spec'
3
-
4
- $WARNING = ""
5
- class Object
6
- def warn(msg)
7
- $WARNING << msg.to_s
8
- super msg
9
- end
10
- end
11
-
12
- class Test::Spec::Should
13
- def _warn
14
- _wrap_assertion {
15
- begin
16
- old, $-w = $-w, nil
17
- $WARNING = ""
18
- self.not.raise
19
- $WARNING.should.blaming("no warning printed").not.be.empty
20
- ensure
21
- $-w = old
22
- end
23
- }
24
- end
25
- end
26
-
27
- # Hooray for meta-testing.
28
- module MetaTests
29
- class ShouldFail < Test::Spec::CustomShould
30
- def initialize
31
- end
32
-
33
- def assumptions(block)
34
- block.should.raise(Test::Unit::AssertionFailedError)
35
- end
36
-
37
- def failure_message
38
- "Block did not fail."
39
- end
40
- end
41
-
42
- class ShouldSucceed < Test::Spec::CustomShould
43
- def initialize
44
- end
45
-
46
- def assumptions(block)
47
- block.should.not.raise(Test::Unit::AssertionFailedError)
48
- end
49
-
50
- def failure_message
51
- "Block raised Test::Unit::AssertionFailedError."
52
- end
53
- end
54
-
55
- class ShouldBeDeprecated < Test::Spec::CustomShould
56
- def initialize
57
- end
58
-
59
- def assumptions(block)
60
- block.should._warn
61
- $WARNING.should =~ /deprecated/
62
- end
63
-
64
- def failure_message
65
- "warning was not a deprecation"
66
- end
67
- end
68
-
69
-
70
- def fail
71
- ShouldFail.new
72
- end
73
-
74
- def succeed
75
- ShouldSucceed.new
76
- end
77
-
78
- def deprecated
79
- ShouldBeDeprecated.new
80
- end
81
- end
82
-
83
- module TestShoulds
84
- class EmptyShould < Test::Spec::CustomShould
85
- end
86
-
87
- class EqualString < Test::Spec::CustomShould
88
- def matches?(other)
89
- object == other.to_s
90
- end
91
- end
92
-
93
- class EqualString2 < Test::Spec::CustomShould
94
- def matches?(other)
95
- object == other.to_s
96
- end
97
-
98
- def failure_message
99
- "yada yada yada"
100
- end
101
- end
102
-
103
- def empty_should(obj)
104
- EmptyShould.new(obj)
105
- end
106
-
107
- def equal_string(str)
108
- EqualString.new(str)
109
- end
110
-
111
- def equal_string2(str)
112
- EqualString2.new(str)
113
- end
114
- end
115
-
116
- context "test/spec" do
117
- include MetaTests
118
-
119
- specify "has should.satisfy" do
120
- lambda { should.satisfy { 1 == 1 } }.should succeed
121
- lambda { should.satisfy { 1 } }.should succeed
122
-
123
- lambda { should.satisfy { 1 == 2 } }.should fail
124
- lambda { should.satisfy { false } }.should fail
125
- lambda { should.satisfy { false } }.should fail
126
-
127
- lambda { 1.should.satisfy { |n| n % 2 == 0 } }.should fail
128
- lambda { 2.should.satisfy { |n| n % 2 == 0 } }.should succeed
129
- end
130
-
131
- specify "has should.equal" do
132
- lambda { "string1".should.equal "string1" }.should succeed
133
- lambda { "string1".should.equal "string2" }.should fail
134
- lambda { "1".should.equal 1 }.should fail
135
-
136
- lambda { "string1".should == "string1" }.should succeed
137
- lambda { "string1".should == "string2" }.should fail
138
- lambda { "1".should == 1 }.should fail
139
- end
140
-
141
- specify "has should.raise" do
142
- lambda { lambda { raise "Error" }.should.raise }.should succeed
143
- lambda { lambda { raise "Error" }.should.raise RuntimeError }.should succeed
144
- lambda { lambda { raise "Error" }.should.not.raise }.should fail
145
- lambda { lambda { raise "Error" }.should.not.raise(RuntimeError) }.should fail
146
-
147
- lambda { lambda { 1 + 1 }.should.raise }.should fail
148
- lambda { lambda { raise "Error" }.should.raise(Interrupt) }.should fail
149
- end
150
-
151
- specify "has should.raise with a block" do
152
- lambda { should.raise { raise "Error" } }.should succeed
153
- lambda { should.raise(RuntimeError) { raise "Error" } }.should succeed
154
- lambda { should.not.raise { raise "Error" } }.should fail
155
- lambda { should.not.raise(RuntimeError) { raise "Error" } }.should fail
156
-
157
- lambda { should.raise { 1 + 1 } }.should fail
158
- lambda { should.raise(Interrupt) { raise "Error" } }.should fail
159
- end
160
-
161
- specify "should.raise should return the exception" do
162
- ex = lambda { raise "foo!" }.should.raise
163
- ex.should.be.kind_of RuntimeError
164
- ex.message.should.match(/foo/)
165
- end
166
-
167
- specify "has should.be.an.instance_of" do
168
- lambda {
169
- lambda { "string".should.be_an_instance_of String }.should succeed
170
- }.should.be deprecated
171
- lambda {
172
- lambda { "string".should.be_an_instance_of Hash }.should fail
173
- }.should.be deprecated
174
-
175
- lambda { "string".should.be.instance_of String }.should succeed
176
- lambda { "string".should.be.instance_of Hash }.should fail
177
-
178
- lambda { "string".should.be.an.instance_of String }.should succeed
179
- lambda { "string".should.be.an.instance_of Hash }.should fail
180
- end
181
-
182
- specify "has should.be.nil" do
183
- lambda { nil.should.be.nil }.should succeed
184
- lambda { nil.should.be nil }.should succeed
185
- lambda { nil.should.be_nil }.should.be deprecated
186
-
187
- lambda { nil.should.not.be.nil }.should fail
188
- lambda { nil.should.not.be nil }.should fail
189
- lambda { lambda { nil.should.not.be_nil }.should fail }.should.be deprecated
190
-
191
- lambda { "foo".should.be.nil }.should fail
192
- lambda { "bar".should.be nil }.should fail
193
-
194
- lambda { "foo".should.not.be.nil }.should succeed
195
- lambda { "bar".should.not.be nil }.should succeed
196
- end
197
-
198
- specify "has should.include" do
199
- lambda { [1,2,3].should.include 2 }.should succeed
200
- lambda { [1,2,3].should.include 4 }.should fail
201
-
202
- lambda { {1=>2, 3=>4}.should.include 1 }.should succeed
203
- lambda { {1=>2, 3=>4}.should.include 2 }.should fail
204
- end
205
-
206
- specify "has should.be.a.kind_of" do
207
- lambda { Array.should.be.kind_of Module }.should succeed
208
- lambda { "string".should.be.kind_of Object }.should succeed
209
- lambda { 1.should.be.kind_of Comparable }.should succeed
210
-
211
- lambda { Array.should.be.a.kind_of Module }.should succeed
212
-
213
- lambda { "string".should.be.a.kind_of Class }.should fail
214
- lambda {
215
- lambda { "string".should.be_a_kind_of Class }.should fail
216
- }.should.be deprecated
217
-
218
- lambda { Array.should.be_a_kind_of Module }.should.be deprecated
219
- lambda { "string".should.be_a_kind_of Object }.should.be deprecated
220
- lambda { 1.should.be_a_kind_of Comparable }.should.be deprecated
221
- end
222
-
223
- specify "has should.match" do
224
- lambda { "string".should.match(/strin./) }.should succeed
225
- lambda { "string".should.match("strin") }.should succeed
226
- lambda { "string".should =~ /strin./ }.should succeed
227
- lambda { "string".should =~ "strin" }.should succeed
228
-
229
- lambda { "string".should.match(/slin./) }.should fail
230
- lambda { "string".should.match("slin") }.should fail
231
- lambda { "string".should =~ /slin./ }.should fail
232
- lambda { "string".should =~ "slin" }.should fail
233
- end
234
-
235
- specify "has should.be" do
236
- thing = "thing"
237
- lambda { thing.should.be thing }.should succeed
238
- lambda { thing.should.be "thing" }.should fail
239
-
240
- lambda { 1.should.be(2, 3) }.should.raise(ArgumentError)
241
- end
242
-
243
- specify "has should.not.raise" do
244
- lambda { lambda { 1 + 1 }.should.not.raise }.should succeed
245
- lambda { lambda { 1 + 1 }.should.not.raise(Interrupt) }.should succeed
246
-
247
- lambda {
248
- begin
249
- lambda {
250
- raise ZeroDivisionError.new("ArgumentError")
251
- }.should.not.raise(RuntimeError, StandardError, Comparable)
252
- rescue ZeroDivisionError
253
- end
254
- }.should succeed
255
-
256
- lambda { lambda { raise "Error" }.should.not.raise }.should fail
257
- end
258
-
259
- specify "has should.not.satisfy" do
260
- lambda { should.not.satisfy { 1 == 2 } }.should succeed
261
- lambda { should.not.satisfy { 1 == 1 } }.should fail
262
- end
263
-
264
- specify "has should.not.be" do
265
- thing = "thing"
266
- lambda { thing.should.not.be "thing" }.should succeed
267
- lambda { thing.should.not.be thing }.should fail
268
-
269
- lambda { thing.should.not.be thing, thing }.should.raise(ArgumentError)
270
- end
271
-
272
- specify "has should.not.equal" do
273
- lambda { "string1".should.not.equal "string2" }.should succeed
274
- lambda { "string1".should.not.equal "string1" }.should fail
275
- end
276
-
277
- specify "has should.not.match" do
278
- lambda { "string".should.not.match(/sling/) }.should succeed
279
- lambda { "string".should.not.match(/string/) }.should fail
280
- lambda { "string".should.not.match("strin") }.should fail
281
-
282
- lambda { "string".should.not =~ /sling/ }.should succeed
283
- lambda { "string".should.not =~ /string/ }.should fail
284
- lambda { "string".should.not =~ "strin" }.should fail
285
- end
286
-
287
- specify "has should.throw" do
288
- lambda { lambda { throw :thing }.should.throw(:thing) }.should succeed
289
-
290
- lambda { lambda { throw :thing2 }.should.throw(:thing) }.should fail
291
- lambda { lambda { 1 + 1 }.should.throw(:thing) }.should fail
292
- end
293
-
294
- specify "has should.not.throw" do
295
- lambda { lambda { 1 + 1 }.should.not.throw }.should succeed
296
- lambda { lambda { throw :thing }.should.not.throw }.should fail
297
- end
298
-
299
- specify "has should.respond_to" do
300
- lambda { "foo".should.respond_to :to_s }.should succeed
301
- lambda { 5.should.respond_to :to_str }.should fail
302
- lambda { :foo.should.respond_to :nx }.should fail
303
- end
304
-
305
- specify "has should.be_close" do
306
- lambda { 1.4.should.be.close 1.4, 0 }.should succeed
307
- lambda { 0.4.should.be.close 0.5, 0.1 }.should succeed
308
-
309
- lambda {
310
- lambda { 1.4.should.be_close 1.4, 0 }.should succeed
311
- }.should.be deprecated
312
- lambda {
313
- lambda { 0.4.should.be_close 0.5, 0.1 }.should succeed
314
- }.should.be deprecated
315
-
316
- lambda {
317
- float_thing = Object.new
318
- def float_thing.to_f
319
- 0.2
320
- end
321
- float_thing.should.be.close 0.1, 0.1
322
- }.should succeed
323
-
324
- lambda { 0.4.should.be.close 0.5, 0.05 }.should fail
325
- lambda { 0.4.should.be.close Object.new, 0.1 }.should fail
326
- lambda { 0.4.should.be.close 0.5, -0.1 }.should fail
327
- end
328
-
329
- specify "multiple negation works" do
330
- lambda { 1.should.equal 1 }.should succeed
331
- lambda { 1.should.not.equal 1 }.should fail
332
- lambda { 1.should.not.not.equal 1 }.should succeed
333
- lambda { 1.should.not.not.not.equal 1 }.should fail
334
-
335
- lambda { 1.should.equal 2 }.should fail
336
- lambda { 1.should.not.equal 2 }.should succeed
337
- lambda { 1.should.not.not.equal 2 }.should fail
338
- lambda { 1.should.not.not.not.equal 2 }.should succeed
339
- end
340
-
341
- specify "has should.<predicate>" do
342
- lambda { [].should.be.empty }.should succeed
343
- lambda { [1,2,3].should.not.be.empty }.should succeed
344
-
345
- lambda { [].should.not.be.empty }.should fail
346
- lambda { [1,2,3].should.be.empty }.should fail
347
-
348
- lambda { {1=>2, 3=>4}.should.has_key 1 }.should succeed
349
- lambda { {1=>2, 3=>4}.should.not.has_key 2 }.should succeed
350
-
351
- lambda { nil.should.bla }.should.raise(NoMethodError)
352
- lambda { nil.should.not.bla }.should.raise(NoMethodError)
353
- end
354
-
355
- specify "has should.<predicate>?" do
356
- lambda { [].should.be.empty? }.should succeed
357
- lambda { [1,2,3].should.not.be.empty? }.should succeed
358
-
359
- lambda { [].should.not.be.empty? }.should fail
360
- lambda { [1,2,3].should.be.empty? }.should fail
361
-
362
- lambda { {1=>2, 3=>4}.should.has_key? 1 }.should succeed
363
- lambda { {1=>2, 3=>4}.should.not.has_key? 2 }.should succeed
364
-
365
- lambda { nil.should.bla? }.should.raise(NoMethodError)
366
- lambda { nil.should.not.bla? }.should.raise(NoMethodError)
367
- end
368
-
369
- specify "has should <operator> (>, >=, <, <=, ===)" do
370
- lambda { 2.should.be > 1 }.should succeed
371
- lambda { 1.should.be > 2 }.should fail
372
-
373
- lambda { 1.should.be < 2 }.should succeed
374
- lambda { 2.should.be < 1 }.should fail
375
-
376
- lambda { 2.should.be >= 1 }.should succeed
377
- lambda { 2.should.be >= 2 }.should succeed
378
- lambda { 2.should.be >= 2.1 }.should fail
379
-
380
- lambda { 2.should.be <= 1 }.should fail
381
- lambda { 2.should.be <= 2 }.should succeed
382
- lambda { 2.should.be <= 2.1 }.should succeed
383
-
384
- lambda { Array.should === [1,2,3] }.should succeed
385
- lambda { Integer.should === [1,2,3] }.should fail
386
-
387
- lambda { /foo/.should === "foobar" }.should succeed
388
- lambda { "foobar".should === /foo/ }.should fail
389
- end
390
-
391
- $contextscope = self
392
- specify "is robust against careless users" do
393
- lambda {
394
- $contextscope.specify
395
- }.should.raise(ArgumentError)
396
- lambda {
397
- $contextscope.specify "foo"
398
- }.should.raise(ArgumentError)
399
- lambda {
400
- $contextscope.xspecify
401
- }.should.raise(ArgumentError)
402
- lambda {
403
- $contextscope.xspecify "foo"
404
- }.should.not.raise(ArgumentError) # allow empty xspecifys
405
- lambda {
406
- Kernel.send(:context, "foo")
407
- }.should.raise(ArgumentError)
408
- lambda {
409
- context "foo" do
410
- end
411
- }.should.raise(Test::Spec::DefinitionError)
412
- end
413
-
414
- specify "should detect warnings" do
415
- lambda { lambda { 0 }.should._warn }.should fail
416
- lambda { lambda { warn "just a test" }.should._warn }.should succeed
417
- end
418
-
419
- specify "should message/blame faults" do
420
- begin
421
- 2.should.blaming("Two is not two anymore!").equal 3
422
- rescue Test::Unit::AssertionFailedError => e
423
- e.message.should =~ /Two/
424
- end
425
-
426
- begin
427
- 2.should.messaging("Two is not two anymore!").equal 3
428
- rescue Test::Unit::AssertionFailedError => e
429
- e.message.should =~ /Two/
430
- end
431
-
432
- begin
433
- 2.should.blaming("I thought two was three").not.equal 2
434
- rescue Test::Unit::AssertionFailedError => e
435
- e.message.should =~ /three/
436
- end
437
-
438
- begin
439
- 2.should.blaming("I thought two was three").not.not.not.equal 3
440
- rescue Test::Unit::AssertionFailedError => e
441
- e.message.should =~ /three/
442
- end
443
-
444
- lambda {
445
- lambda { raise "Error" }.should.messaging("Duh.").not.raise
446
- }.should.raise(Test::Unit::AssertionFailedError).message.should =~ /Duh/
447
- end
448
-
449
- include TestShoulds
450
- specify "should allow for custom shoulds" do
451
- lambda { (1+1).should equal_string("2") }.should succeed
452
- lambda { (1+2).should equal_string("2") }.should fail
453
-
454
- lambda { (1+1).should.pass equal_string("2") }.should succeed
455
- lambda { (1+2).should.pass equal_string("2") }.should fail
456
-
457
- lambda { (1+1).should.be equal_string("2") }.should succeed
458
- lambda { (1+2).should.be equal_string("2") }.should fail
459
-
460
- lambda { (1+1).should.not equal_string("2") }.should fail
461
- lambda { (1+2).should.not equal_string("2") }.should succeed
462
- lambda { (1+2).should.not.not equal_string("2") }.should fail
463
-
464
- lambda { (1+1).should.not.pass equal_string("2") }.should fail
465
- lambda { (1+2).should.not.pass equal_string("2") }.should succeed
466
-
467
- lambda { (1+1).should.not.be equal_string("2") }.should fail
468
- lambda { (1+2).should.not.be equal_string("2") }.should succeed
469
-
470
- lambda {
471
- (1+2).should equal_string("2")
472
- }.should.raise(Test::Unit::AssertionFailedError).message.should =~ /EqualString/
473
-
474
- lambda { (1+1).should equal_string2("2") }.should succeed
475
- lambda { (1+2).should equal_string2("2") }.should fail
476
-
477
- lambda {
478
- (1+2).should equal_string2("2")
479
- }.should.raise(Test::Unit::AssertionFailedError).message.should =~ /yada/
480
-
481
- lambda {
482
- (1+2).should.blaming("foo").pass equal_string2("2")
483
- }.should.raise(Test::Unit::AssertionFailedError).message.should =~ /foo/
484
-
485
- lambda {
486
- nil.should empty_should(nil)
487
- }.should.raise(NotImplementedError)
488
-
489
- lambda { nil.should :break, :now }.should.raise(ArgumentError)
490
- lambda { nil.should.not :pass, :now }.should.raise(ArgumentError)
491
- lambda { nil.should.not.not :break, :now }.should.raise(ArgumentError)
492
- end
493
-
494
- xspecify "disabled specification" do
495
- # just trying
496
- end
497
-
498
- xspecify "empty specification"
499
-
500
- context "more disabled" do
501
- xspecify "this is intentional" do
502
- # ...
503
- end
504
-
505
- specify "an empty specification" do
506
- # ...
507
- end
508
-
509
- xcontext "even more disabled" do
510
- specify "we can cut out" do
511
- # ...
512
- end
513
-
514
- specify "entire contexts, now" do
515
- # ...
516
- end
517
- end
518
- end
519
- end
520
-
521
- context "setup/teardown" do
522
- setup do
523
- @a = 1
524
- @b = 2
525
- end
526
-
527
- setup do
528
- @a = 2
529
- end
530
-
531
- teardown do
532
- @a.should.equal 2
533
- @a = 3
534
- end
535
-
536
- teardown do
537
- @a.should.equal 3
538
- end
539
-
540
- specify "run in the right order" do
541
- @a.should.equal 2
542
- @b.should.equal 2
543
- end
544
- end
545
-
546
- context "before all" do
547
- before(:all) { @a = 1 }
548
-
549
- specify "runs parent before all" do
550
- @a.should == 1
551
- end
552
- end
553
-
554
- context "nested teardown" do
555
- context "nested" do
556
- specify "should call local teardown then parent teardown" do
557
- @a = 3
558
- end
559
-
560
- teardown do
561
- @a = 2
562
- end
563
- end
564
-
565
- teardown do
566
- @a.should.equal 2
567
- @a = 1
568
- end
569
-
570
- after(:all) do
571
- @a.should.equal 1
572
- end
573
- end
574
-
575
- context "before all" do
576
- context "nested" do
577
- before(:all) do
578
- @a = 2
579
- end
580
-
581
- specify "should call parent then local" do
582
- @a.should.equal 2
583
- @b.should.equal 2
584
- end
585
- end
586
-
587
- before(:all) do
588
- @a = 1
589
- @b = 2
590
- end
591
- end
592
-
593
- context "after all" do
594
- context "after nested" do
595
- after(:all) do
596
- @a = 2
597
- end
598
-
599
- specify "should call local then parent" do
600
- self.after_all
601
- @a.should.equal 1
602
- @b.should.equal 2
603
- end
604
- end
605
-
606
- after(:all) do
607
- @b = @a
608
- @a = 1
609
- end
610
- end
611
-
612
-
613
- module ContextHelper
614
- def foo
615
- 42
616
- end
617
- end
618
-
619
- context "contexts" do
620
- include ContextHelper
621
-
622
- FOO = 42
623
- $class = self.class
624
-
625
- specify "are defined in class scope" do
626
- lambda { FOO }.should.not.raise(NameError)
627
- FOO.should.equal 42
628
- $class.should.equal Class
629
- end
630
-
631
- specify "can include modules" do
632
- lambda { foo }.should.not.raise(NameError)
633
- foo.should.equal 42
634
- end
635
- end
636
-
637
- class CustomTestUnitSubclass < Test::Unit::TestCase
638
- def test_truth
639
- assert true
640
- end
641
- end
642
-
643
- context "contexts with subclasses", CustomTestUnitSubclass do
644
- specify "use the supplied class as the superclass" do
645
- self.should.be.a.kind_of CustomTestUnitSubclass
646
- end
647
- end
648
-
649
- xcontext "xcontexts with subclasses", CustomTestUnitSubclass do
650
- specify "work great!" do
651
- self.should.be.a.kind_of CustomTestUnitSubclass
652
- end
653
- end
654
-
655
- shared_context "a shared context" do
656
- specify "can be included several times" do
657
- true.should.be true
658
- end
659
-
660
- behaves_like "yet another shared context"
661
- end
662
-
663
- shared_context "another shared context" do
664
- specify "can access data" do
665
- @answer.should.be 42
666
- end
667
- end
668
-
669
- shared_context "yet another shared context" do
670
- specify "can include other shared contexts" do
671
- true.should.be true
672
- end
673
- end
674
-
675
- context "Shared contexts" do
676
- shared_context "a nested context" do
677
- specify "can be nested" do
678
- true.should.be true
679
- end
680
- end
681
-
682
- setup do
683
- @answer = 42
684
- end
685
-
686
- behaves_like "a shared context"
687
- it_should_behave_like "a shared context"
688
-
689
- behaves_like "a nested context"
690
-
691
- behaves_like "another shared context"
692
-
693
- ctx = self
694
- specify "should raise when the context cannot be found" do
695
- should.raise(NameError) {
696
- ctx.behaves_like "no such context"
697
- }
698
- end
699
- end