rr 0.4.5 → 0.4.6
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.
- data/CHANGES +3 -0
- data/Rakefile +1 -1
- data/lib/rr/double.rb +16 -0
- data/lib/rr/double_definition.rb +15 -0
- data/spec/rr/double_definition_spec.rb +597 -587
- data/spec/rr/double_spec.rb +133 -90
- metadata +2 -2
data/spec/rr/double_spec.rb
CHANGED
@@ -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
|
393
|
-
|
394
|
-
|
395
|
-
|
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
|
-
|
399
|
-
|
400
|
-
|
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
|
-
|
406
|
-
|
407
|
-
|
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
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
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
|
-
|
415
|
-
|
447
|
+
it "returns nil when to returns is not set" do
|
448
|
+
double.call(double_injection).should be_nil
|
449
|
+
end
|
416
450
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
451
|
+
it "works when times_called is not set" do
|
452
|
+
double.returns {:value}
|
453
|
+
double.call(double_injection)
|
454
|
+
end
|
421
455
|
|
422
|
-
|
423
|
-
|
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
|
-
|
427
|
-
|
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
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
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
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
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
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
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
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
513
|
+
double.returns {:value}
|
514
|
+
double.call(double_injection, :foobar)
|
515
|
+
verify_ordered_double_called.should be_false
|
516
|
+
end
|
475
517
|
|
476
|
-
|
477
|
-
|
518
|
+
it "does not add block argument if no block passed in" do
|
519
|
+
double.with(1, 2).returns {|*args| args}
|
478
520
|
|
479
|
-
|
480
|
-
|
481
|
-
|
521
|
+
args = object.foobar(1, 2)
|
522
|
+
args.should == [1, 2]
|
523
|
+
end
|
482
524
|
|
483
|
-
|
484
|
-
|
525
|
+
it "makes the block the last argument" do
|
526
|
+
double.with(1, 2).returns {|a, b, blk| blk}
|
485
527
|
|
486
|
-
|
487
|
-
|
488
|
-
|
528
|
+
block = object.foobar(1, 2) {|a, b| [b, a]}
|
529
|
+
block.call(3, 4).should == [4, 3]
|
530
|
+
end
|
489
531
|
|
490
|
-
|
491
|
-
|
532
|
+
it "raises ArgumentError when yields was called and no block passed in" do
|
533
|
+
double.with(1, 2).yields(55)
|
492
534
|
|
493
|
-
|
494
|
-
|
495
|
-
|
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
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
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
|
-
|
547
|
+
double.with(1, 2).implemented_by(object.method(:foobar))
|
506
548
|
|
507
|
-
|
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.
|
7
|
-
date: 2008-01-
|
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
|