rr 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -291,6 +291,24 @@ module RR
291
291
  end
292
292
  end
293
293
 
294
+ describe "#verbose" do
295
+ it "returns DoubleDefinition" do
296
+ double.verbose.should === double.definition
297
+ end
298
+
299
+ it "sets #verbose? to true" do
300
+ double.should_not be_verbose
301
+ double.verbose
302
+ double.should be_verbose
303
+ end
304
+
305
+ it "sets return value when block passed in" do
306
+ (class << double; self; end).send(:define_method, :puts) {|value|}
307
+ double.with().verbose {:return_value}
308
+ object.foobar.should == :return_value
309
+ end
310
+ end
311
+
294
312
  describe "#returns" do
295
313
  it "returns DoubleDefinition" do
296
314
  double.returns {:baz}.should === double.definition
@@ -389,125 +407,150 @@ module RR
389
407
  end
390
408
  end
391
409
 
392
- describe "#call implemented by a proc" do
393
- it "calls the return proc when implemented by a proc" do
394
- double.returns {|arg| "returning #{arg}"}
395
- double.call(double_injection, :foobar).should == "returning foobar"
410
+ describe "#call" do
411
+ describe "when verbose" do
412
+ it "prints the message call" do
413
+ double.verbose
414
+ output = nil
415
+ (class << double; self; end).send(:define_method, :puts) do |output|
416
+ output = output
417
+ end
418
+ double.call(double_injection, 1, 2)
419
+ output.should == Double.formatted_name(:foobar, [1, 2])
420
+ end
396
421
  end
397
422
 
398
- it "calls and returns the after_call when after_call is set" do
399
- double.returns {|arg| "returning #{arg}"}.after_call do |value|
400
- "#{value} after call"
423
+ describe "when not verbose" do
424
+ it "does not print the message call" do
425
+ output = nil
426
+ (class << double; self; end).send(:define_method, :puts) do |output|
427
+ output = output
428
+ end
429
+ double.call(double_injection, 1, 2)
430
+ output.should be_nil
401
431
  end
402
- double.call(double_injection, :foobar).should == "returning foobar after call"
403
432
  end
404
433
 
405
- it "returns nil when to returns is not set" do
406
- double.call(double_injection).should be_nil
407
- end
434
+ describe "when implemented by a proc" do
435
+ it "calls the return proc when implemented by a proc" do
436
+ double.returns {|arg| "returning #{arg}"}
437
+ double.call(double_injection, :foobar).should == "returning foobar"
438
+ end
408
439
 
409
- it "works when times_called is not set" do
410
- double.returns {:value}
411
- double.call(double_injection)
412
- end
440
+ it "calls and returns the after_call when after_call is set" do
441
+ double.returns {|arg| "returning #{arg}"}.after_call do |value|
442
+ "#{value} after call"
443
+ end
444
+ double.call(double_injection, :foobar).should == "returning foobar after call"
445
+ end
413
446
 
414
- it "verifes the times_called does not exceed the TimesCalledExpectation" do
415
- double.times(2).returns {:value}
447
+ it "returns nil when to returns is not set" do
448
+ double.call(double_injection).should be_nil
449
+ end
416
450
 
417
- double.call(double_injection, :foobar)
418
- double.call(double_injection, :foobar)
419
- proc {double.call(double_injection, :foobar)}.should raise_error(Errors::TimesCalledError)
420
- end
451
+ it "works when times_called is not set" do
452
+ double.returns {:value}
453
+ double.call(double_injection)
454
+ end
421
455
 
422
- it "raises DoubleOrderError when ordered and called out of order" do
423
- double1 = double
424
- double2 = space.double(double_injection)
456
+ it "verifes the times_called does not exceed the TimesCalledExpectation" do
457
+ double.times(2).returns {:value}
425
458
 
426
- double1.with(1).returns {:return_1}.ordered.once
427
- double2.with(2).returns {:return_2}.ordered.once
459
+ double.call(double_injection, :foobar)
460
+ double.call(double_injection, :foobar)
461
+ proc {double.call(double_injection, :foobar)}.should raise_error(Errors::TimesCalledError)
462
+ end
428
463
 
429
- proc do
430
- object.foobar(2)
431
- end.should raise_error(
432
- Errors::DoubleOrderError,
433
- "foobar(2) called out of order in list\n" <<
434
- "- foobar(1)\n" <<
435
- "- foobar(2)"
436
- )
437
- end
464
+ it "raises DoubleOrderError when ordered and called out of order" do
465
+ double1 = double
466
+ double2 = space.double(double_injection)
467
+
468
+ double1.with(1).returns {:return_1}.ordered.once
469
+ double2.with(2).returns {:return_2}.ordered.once
470
+
471
+ proc do
472
+ object.foobar(2)
473
+ end.should raise_error(
474
+ Errors::DoubleOrderError,
475
+ "foobar(2) called out of order in list\n" <<
476
+ "- foobar(1)\n" <<
477
+ "- foobar(2)"
478
+ )
479
+ end
438
480
 
439
- it "dispatches to Space#verify_ordered_double when ordered" do
440
- verify_ordered_double_called = false
441
- passed_in_double = nil
442
- space.method(:verify_ordered_double).arity.should == 1
443
- (
444
- class << space;
445
- self;
446
- end).class_eval do
447
- define_method :verify_ordered_double do |double|
448
- passed_in_double = double
449
- verify_ordered_double_called = true
481
+ it "dispatches to Space#verify_ordered_double when ordered" do
482
+ verify_ordered_double_called = false
483
+ passed_in_double = nil
484
+ space.method(:verify_ordered_double).arity.should == 1
485
+ (
486
+ class << space;
487
+ self;
488
+ end).class_eval do
489
+ define_method :verify_ordered_double do |double|
490
+ passed_in_double = double
491
+ verify_ordered_double_called = true
492
+ end
450
493
  end
494
+
495
+ double.returns {:value}.ordered
496
+ double.call(double_injection, :foobar)
497
+ verify_ordered_double_called.should be_true
498
+ passed_in_double.should === double
451
499
  end
452
500
 
453
- double.returns {:value}.ordered
454
- double.call(double_injection, :foobar)
455
- verify_ordered_double_called.should be_true
456
- passed_in_double.should === double
457
- end
458
-
459
- it "does not dispatche to Space#verify_ordered_double when not ordered" do
460
- verify_ordered_double_called = false
461
- space.method(:verify_ordered_double).arity.should == 1
462
- (
463
- class << space;
464
- self;
465
- end).class_eval do
466
- define_method :verify_ordered_double do |double|
467
- verify_ordered_double_called = true
501
+ it "does not dispatche to Space#verify_ordered_double when not ordered" do
502
+ verify_ordered_double_called = false
503
+ space.method(:verify_ordered_double).arity.should == 1
504
+ (
505
+ class << space;
506
+ self;
507
+ end).class_eval do
508
+ define_method :verify_ordered_double do |double|
509
+ verify_ordered_double_called = true
510
+ end
468
511
  end
469
- end
470
512
 
471
- double.returns {:value}
472
- double.call(double_injection, :foobar)
473
- verify_ordered_double_called.should be_false
474
- end
513
+ double.returns {:value}
514
+ double.call(double_injection, :foobar)
515
+ verify_ordered_double_called.should be_false
516
+ end
475
517
 
476
- it "does not add block argument if no block passed in" do
477
- double.with(1, 2).returns {|*args| args}
518
+ it "does not add block argument if no block passed in" do
519
+ double.with(1, 2).returns {|*args| args}
478
520
 
479
- args = object.foobar(1, 2)
480
- args.should == [1, 2]
481
- end
521
+ args = object.foobar(1, 2)
522
+ args.should == [1, 2]
523
+ end
482
524
 
483
- it "makes the block the last argument" do
484
- double.with(1, 2).returns {|a, b, blk| blk}
525
+ it "makes the block the last argument" do
526
+ double.with(1, 2).returns {|a, b, blk| blk}
485
527
 
486
- block = object.foobar(1, 2) {|a, b| [b, a]}
487
- block.call(3, 4).should == [4, 3]
488
- end
528
+ block = object.foobar(1, 2) {|a, b| [b, a]}
529
+ block.call(3, 4).should == [4, 3]
530
+ end
489
531
 
490
- it "raises ArgumentError when yields was called and no block passed in" do
491
- double.with(1, 2).yields(55)
532
+ it "raises ArgumentError when yields was called and no block passed in" do
533
+ double.with(1, 2).yields(55)
492
534
 
493
- proc do
494
- object.foobar(1, 2)
495
- end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
535
+ proc do
536
+ object.foobar(1, 2)
537
+ end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
538
+ end
496
539
  end
497
- end
498
540
 
499
- describe "#call implemented by a method" do
500
- it "sends block to the method" do
501
- def object.foobar(a, b)
502
- yield(a, b)
503
- end
541
+ describe "when implemented by a method" do
542
+ it "sends block to the method" do
543
+ def object.foobar(a, b)
544
+ yield(a, b)
545
+ end
504
546
 
505
- double.with(1, 2).implemented_by(object.method(:foobar))
547
+ double.with(1, 2).implemented_by(object.method(:foobar))
506
548
 
507
- object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
549
+ object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
550
+ end
508
551
  end
509
552
  end
510
-
553
+
511
554
  describe "#exact_match?" do
512
555
  it "returns false when no expectation set" do
513
556
  double.should_not be_exact_match()
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.5
7
- date: 2008-01-15 00:00:00 -08:00
6
+ version: 0.4.6
7
+ date: 2008-01-23 00:00:00 -08:00
8
8
  summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
9
9
  require_paths:
10
10
  - lib