rr 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/{README → README.rdoc} +14 -6
- data/Rakefile +2 -2
- data/lib/rr.rb +11 -3
- data/lib/rr/adapters/rr_methods.rb +12 -12
- data/lib/rr/adapters/rspec.rb +3 -3
- data/lib/rr/adapters/test_unit.rb +3 -3
- data/lib/rr/double.rb +12 -10
- data/lib/rr/double_creator.rb +48 -45
- data/lib/rr/double_definition.rb +17 -149
- data/lib/rr/double_definition_builder.rb +11 -11
- data/lib/rr/double_definition_creator.rb +156 -0
- data/lib/rr/{double_method_proxy.rb → double_definition_creator_proxy.rb} +2 -2
- data/lib/rr/double_injection.rb +6 -6
- data/lib/rr/double_matches.rb +40 -40
- data/lib/rr/errors/rr_error.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/space.rb +9 -30
- data/spec/high_level_spec.rb +140 -143
- data/spec/rr/adapters/rr_methods_creator_spec.rb +21 -21
- data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
- data/spec/rr/double/double_injection_dispatching_spec.rb +15 -15
- data/spec/rr/double/double_injection_reset_spec.rb +1 -1
- data/spec/rr/double/double_injection_verify_spec.rb +5 -4
- data/spec/rr/{double_method_proxy_spec.rb → double_definition_creator_proxy_spec.rb} +12 -10
- data/spec/rr/{double_creator_spec.rb → double_definition_creator_spec.rb} +166 -124
- data/spec/rr/double_definition_spec.rb +637 -642
- data/spec/rr/double_spec.rb +44 -43
- data/spec/rr/errors/rr_error_spec.rb +6 -6
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +3 -3
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +8 -8
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +11 -13
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +19 -19
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +7 -11
- data/spec/rr/rspec/rspec_adapter_spec.rb +10 -10
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +372 -18
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +3 -3
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +3 -3
- data/spec/spec_helper.rb +14 -3
- data/spec/spec_suite.rb +2 -2
- metadata +47 -45
- data/spec/rr/double/double_injection_register_scenario_spec.rb +0 -24
- data/spec/rr/space/space_create_spec.rb +0 -268
- data/spec/rr/space/space_helper.rb +0 -7
- data/spec/rr/space/space_register_spec.rb +0 -32
- data/spec/rr/space/space_reset_spec.rb +0 -131
- data/spec/rr/space/space_verify_spec.rb +0 -181
data/spec/rr/double_spec.rb
CHANGED
@@ -2,15 +2,22 @@ require "spec/spec_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
describe Double do
|
5
|
+
it_should_behave_like "Swapped Space"
|
5
6
|
attr_reader :space, :object, :double_injection, :double
|
6
7
|
before do
|
7
|
-
@space = Space.
|
8
|
+
@space = Space.instance
|
8
9
|
@object = Object.new
|
9
10
|
def object.foobar(a, b)
|
10
11
|
[b, a]
|
11
12
|
end
|
12
13
|
@double_injection = space.double_injection(object, :foobar)
|
13
|
-
@double =
|
14
|
+
@double = Double.new(double_injection)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#initialize" do
|
18
|
+
it "registers self with associated DoubleInjection" do
|
19
|
+
double_injection.doubles.should include(double)
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
describe "#with" do
|
@@ -74,12 +81,12 @@ module RR
|
|
74
81
|
|
75
82
|
it "sets up a Times Called Expectation with 0" do
|
76
83
|
double.never
|
77
|
-
|
84
|
+
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
78
85
|
end
|
79
86
|
|
80
87
|
it "sets return value when block passed in" do
|
81
88
|
double.with_any_args.never
|
82
|
-
|
89
|
+
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
83
90
|
end
|
84
91
|
end
|
85
92
|
|
@@ -91,7 +98,7 @@ module RR
|
|
91
98
|
it "sets up a Times Called Expectation with 1" do
|
92
99
|
double.once
|
93
100
|
double.call(double_injection)
|
94
|
-
|
101
|
+
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
95
102
|
end
|
96
103
|
|
97
104
|
it "sets return value when block passed in" do
|
@@ -109,7 +116,7 @@ module RR
|
|
109
116
|
double.twice
|
110
117
|
double.call(double_injection)
|
111
118
|
double.call(double_injection)
|
112
|
-
|
119
|
+
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
113
120
|
end
|
114
121
|
|
115
122
|
it "sets return value when block passed in" do
|
@@ -143,7 +150,7 @@ module RR
|
|
143
150
|
double.at_most(2)
|
144
151
|
double.call(double_injection)
|
145
152
|
double.call(double_injection)
|
146
|
-
|
153
|
+
lambda do
|
147
154
|
double.call(double_injection)
|
148
155
|
end.should raise_error(
|
149
156
|
Errors::TimesCalledError,
|
@@ -167,7 +174,7 @@ module RR
|
|
167
174
|
double.call(double_injection)
|
168
175
|
double.call(double_injection)
|
169
176
|
double.call(double_injection)
|
170
|
-
|
177
|
+
lambda {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
|
171
178
|
end
|
172
179
|
|
173
180
|
it "sets return value when block passed in" do
|
@@ -285,7 +292,7 @@ module RR
|
|
285
292
|
end
|
286
293
|
|
287
294
|
it "raises an error when not passed a block" do
|
288
|
-
|
295
|
+
lambda do
|
289
296
|
double.after_call
|
290
297
|
end.should raise_error(ArgumentError, "after_call expects a block")
|
291
298
|
end
|
@@ -303,7 +310,7 @@ module RR
|
|
303
310
|
end
|
304
311
|
|
305
312
|
it "sets return value when block passed in" do
|
306
|
-
(class << double; self; end).
|
313
|
+
(class << double; self; end).__send__(:define_method, :puts) {|value|}
|
307
314
|
double.with().verbose {:return_value}
|
308
315
|
object.foobar.should == :return_value
|
309
316
|
end
|
@@ -331,7 +338,7 @@ module RR
|
|
331
338
|
end
|
332
339
|
|
333
340
|
it "raises an error when both argument and block is passed in" do
|
334
|
-
|
341
|
+
lambda do
|
335
342
|
double.returns(:baz) {:another}
|
336
343
|
end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
|
337
344
|
end
|
@@ -339,11 +346,11 @@ module RR
|
|
339
346
|
|
340
347
|
describe "#implemented_by" do
|
341
348
|
it "returns the DoubleDefinition" do
|
342
|
-
double.implemented_by(
|
349
|
+
double.implemented_by(lambda{:baz}).should === double.definition
|
343
350
|
end
|
344
351
|
|
345
|
-
it "sets the implementation to the passed in
|
346
|
-
double.implemented_by(
|
352
|
+
it "sets the implementation to the passed in lambda" do
|
353
|
+
double.implemented_by(lambda{:baz})
|
347
354
|
double.call(double_injection).should == :baz
|
348
355
|
end
|
349
356
|
|
@@ -356,13 +363,13 @@ module RR
|
|
356
363
|
end
|
357
364
|
end
|
358
365
|
|
359
|
-
describe "#
|
366
|
+
describe "#proxy" do
|
360
367
|
it "returns the DoubleDefinition object" do
|
361
|
-
double.
|
368
|
+
double.proxy.should === double.definition
|
362
369
|
end
|
363
370
|
|
364
371
|
it "sets the implementation to the original method" do
|
365
|
-
double.
|
372
|
+
double.proxy
|
366
373
|
double.call(double_injection, 1, 2).should == [2, 1]
|
367
374
|
end
|
368
375
|
|
@@ -384,9 +391,9 @@ module RR
|
|
384
391
|
end
|
385
392
|
|
386
393
|
double_injection = space.double_injection(object, :foobar)
|
387
|
-
double =
|
394
|
+
double = Double.new(double_injection)
|
388
395
|
double.with_any_args
|
389
|
-
double.
|
396
|
+
double.proxy
|
390
397
|
|
391
398
|
object.foobar(1, 2).should == [2, 1]
|
392
399
|
end
|
@@ -398,9 +405,9 @@ module RR
|
|
398
405
|
end
|
399
406
|
end
|
400
407
|
double_injection = space.double_injection(object, :does_not_exist)
|
401
|
-
double =
|
408
|
+
double = Double.new(double_injection)
|
402
409
|
double.with_any_args
|
403
|
-
double.
|
410
|
+
double.proxy
|
404
411
|
|
405
412
|
return_value = object.does_not_exist(1, 2)
|
406
413
|
return_value.should == "method_missing for does_not_exist([1, 2])"
|
@@ -412,7 +419,7 @@ module RR
|
|
412
419
|
it "prints the message call" do
|
413
420
|
double.verbose
|
414
421
|
output = nil
|
415
|
-
(class << double; self; end).
|
422
|
+
(class << double; self; end).__send__(:define_method, :puts) do |output|
|
416
423
|
output = output
|
417
424
|
end
|
418
425
|
double.call(double_injection, 1, 2)
|
@@ -423,7 +430,7 @@ module RR
|
|
423
430
|
describe "when not verbose" do
|
424
431
|
it "does not print the message call" do
|
425
432
|
output = nil
|
426
|
-
(class << double; self; end).
|
433
|
+
(class << double; self; end).__send__(:define_method, :puts) do |output|
|
427
434
|
output = output
|
428
435
|
end
|
429
436
|
double.call(double_injection, 1, 2)
|
@@ -431,8 +438,8 @@ module RR
|
|
431
438
|
end
|
432
439
|
end
|
433
440
|
|
434
|
-
describe "when implemented by a
|
435
|
-
it "calls the return
|
441
|
+
describe "when implemented by a lambda" do
|
442
|
+
it "calls the return lambda when implemented by a lambda" do
|
436
443
|
double.returns {|arg| "returning #{arg}"}
|
437
444
|
double.call(double_injection, :foobar).should == "returning foobar"
|
438
445
|
end
|
@@ -458,17 +465,17 @@ module RR
|
|
458
465
|
|
459
466
|
double.call(double_injection, :foobar)
|
460
467
|
double.call(double_injection, :foobar)
|
461
|
-
|
468
|
+
lambda {double.call(double_injection, :foobar)}.should raise_error(Errors::TimesCalledError)
|
462
469
|
end
|
463
470
|
|
464
471
|
it "raises DoubleOrderError when ordered and called out of order" do
|
465
472
|
double1 = double
|
466
|
-
double2 =
|
473
|
+
double2 = Double.new(double_injection)
|
467
474
|
|
468
475
|
double1.with(1).returns {:return_1}.ordered.once
|
469
476
|
double2.with(2).returns {:return_2}.ordered.once
|
470
477
|
|
471
|
-
|
478
|
+
lambda do
|
472
479
|
object.foobar(2)
|
473
480
|
end.should raise_error(
|
474
481
|
Errors::DoubleOrderError,
|
@@ -482,10 +489,7 @@ module RR
|
|
482
489
|
verify_ordered_double_called = false
|
483
490
|
passed_in_double = nil
|
484
491
|
space.method(:verify_ordered_double).arity.should == 1
|
485
|
-
(
|
486
|
-
class << space;
|
487
|
-
self;
|
488
|
-
end).class_eval do
|
492
|
+
(class << space; self; end).class_eval do
|
489
493
|
define_method :verify_ordered_double do |double|
|
490
494
|
passed_in_double = double
|
491
495
|
verify_ordered_double_called = true
|
@@ -501,10 +505,7 @@ module RR
|
|
501
505
|
it "does not dispatche to Space#verify_ordered_double when not ordered" do
|
502
506
|
verify_ordered_double_called = false
|
503
507
|
space.method(:verify_ordered_double).arity.should == 1
|
504
|
-
(
|
505
|
-
class << space;
|
506
|
-
self;
|
507
|
-
end).class_eval do
|
508
|
+
(class << space; self; end).class_eval do
|
508
509
|
define_method :verify_ordered_double do |double|
|
509
510
|
verify_ordered_double_called = true
|
510
511
|
end
|
@@ -532,7 +533,7 @@ module RR
|
|
532
533
|
it "raises ArgumentError when yields was called and no block passed in" do
|
533
534
|
double.with(1, 2).yields(55)
|
534
535
|
|
535
|
-
|
536
|
+
lambda do
|
536
537
|
object.foobar(1, 2)
|
537
538
|
end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
|
538
539
|
end
|
@@ -628,20 +629,20 @@ module RR
|
|
628
629
|
it "verifies that times called expectation was met" do
|
629
630
|
double.twice.returns {:return_value}
|
630
631
|
|
631
|
-
|
632
|
+
lambda {double.verify}.should raise_error(Errors::TimesCalledError)
|
632
633
|
double.call(double_injection)
|
633
|
-
|
634
|
+
lambda {double.verify}.should raise_error(Errors::TimesCalledError)
|
634
635
|
double.call(double_injection)
|
635
636
|
|
636
|
-
|
637
|
+
lambda {double.verify}.should_not raise_error
|
637
638
|
end
|
638
639
|
|
639
640
|
it "does not raise an error when there is no times called expectation" do
|
640
|
-
|
641
|
+
lambda {double.verify}.should_not raise_error
|
641
642
|
double.call(double_injection)
|
642
|
-
|
643
|
+
lambda {double.verify}.should_not raise_error
|
643
644
|
double.call(double_injection)
|
644
|
-
|
645
|
+
lambda {double.verify}.should_not raise_error
|
645
646
|
end
|
646
647
|
end
|
647
648
|
|
@@ -4,20 +4,20 @@ module RR
|
|
4
4
|
module Errors
|
5
5
|
describe RRError, "#backtrace" do
|
6
6
|
before do
|
7
|
-
@original_trim_backtrace = RR
|
7
|
+
@original_trim_backtrace = RR.trim_backtrace
|
8
8
|
end
|
9
9
|
after do
|
10
|
-
RR
|
10
|
+
RR.trim_backtrace = @original_trim_backtrace
|
11
11
|
end
|
12
12
|
|
13
13
|
it "does not include the rr library files when trim_backtrace is true" do
|
14
|
-
RR
|
14
|
+
RR.trim_backtrace = true
|
15
15
|
|
16
16
|
error = nil
|
17
17
|
begin
|
18
18
|
obj = Object.new
|
19
19
|
mock(obj).foobar
|
20
|
-
RR
|
20
|
+
RR.verify_double(obj, :foobar)
|
21
21
|
rescue RRError=> e
|
22
22
|
error = e
|
23
23
|
end
|
@@ -27,13 +27,13 @@ module RR
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "includes the rr library files when trim_backtrace is false" do
|
30
|
-
RR
|
30
|
+
RR.trim_backtrace = false
|
31
31
|
|
32
32
|
error = nil
|
33
33
|
begin
|
34
34
|
obj = Object.new
|
35
35
|
mock(obj).foobar
|
36
|
-
RR
|
36
|
+
RR.verify_double(obj, :foobar)
|
37
37
|
rescue RRError=> e
|
38
38
|
error = e
|
39
39
|
end
|
data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb
CHANGED
@@ -14,7 +14,7 @@ module RR
|
|
14
14
|
describe "#verify!" do
|
15
15
|
it "always passes" do
|
16
16
|
expectation.verify!
|
17
|
-
10.times {expectation.attempt
|
17
|
+
10.times {expectation.attempt}
|
18
18
|
expectation.verify!
|
19
19
|
end
|
20
20
|
end
|
@@ -22,14 +22,14 @@ module RR
|
|
22
22
|
describe "#attempt?" do
|
23
23
|
it "always returns true" do
|
24
24
|
expectation.should be_attempt
|
25
|
-
10.times {expectation.attempt
|
25
|
+
10.times {expectation.attempt}
|
26
26
|
expectation.should be_attempt
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#attempt!" do
|
31
31
|
it "always passes" do
|
32
|
-
10.times {expectation.attempt
|
32
|
+
10.times {expectation.attempt}
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb
CHANGED
@@ -14,18 +14,18 @@ module Expectations
|
|
14
14
|
|
15
15
|
describe "#verify!" do
|
16
16
|
it "passes when times called > times" do
|
17
|
-
4.times {expectation.attempt
|
17
|
+
4.times {expectation.attempt}
|
18
18
|
expectation.verify!
|
19
19
|
end
|
20
20
|
|
21
21
|
it "passes when times called == times" do
|
22
|
-
3.times {expectation.attempt
|
22
|
+
3.times {expectation.attempt}
|
23
23
|
expectation.verify!
|
24
24
|
end
|
25
25
|
|
26
26
|
it "raises error when times called < times" do
|
27
|
-
expectation.attempt
|
28
|
-
|
27
|
+
expectation.attempt
|
28
|
+
lambda do
|
29
29
|
expectation.verify!
|
30
30
|
end.should raise_error(
|
31
31
|
RR::Errors::TimesCalledError,
|
@@ -37,22 +37,22 @@ module Expectations
|
|
37
37
|
describe "#attempt?" do
|
38
38
|
it "always returns true" do
|
39
39
|
expectation.should be_attempt
|
40
|
-
10.times {expectation.attempt
|
40
|
+
10.times {expectation.attempt}
|
41
41
|
expectation.should be_attempt
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#attempt!" do
|
46
46
|
it "passes when times called more than times" do
|
47
|
-
4.times {expectation.attempt
|
47
|
+
4.times {expectation.attempt}
|
48
48
|
end
|
49
49
|
|
50
50
|
it "passes when times called == times" do
|
51
|
-
3.times {expectation.attempt
|
51
|
+
3.times {expectation.attempt}
|
52
52
|
end
|
53
53
|
|
54
54
|
it "passes when times called < times" do
|
55
|
-
expectation.attempt
|
55
|
+
expectation.attempt
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -14,49 +14,47 @@ module RR
|
|
14
14
|
|
15
15
|
describe "#verify!" do
|
16
16
|
it "returns true when times called == times" do
|
17
|
-
3.times {expectation.attempt
|
17
|
+
3.times {expectation.attempt}
|
18
18
|
expectation.verify!
|
19
19
|
end
|
20
20
|
|
21
21
|
it "raises error when times called < times" do
|
22
|
-
2.times {expectation.attempt
|
22
|
+
2.times {expectation.attempt}
|
23
23
|
expectation.verify!
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#attempt?" do
|
28
28
|
it "returns true when attempted less than expected times" do
|
29
|
-
2.times {expectation.attempt
|
29
|
+
2.times {expectation.attempt}
|
30
30
|
expectation.should be_attempt
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns false when attempted expected times" do
|
34
|
-
3.times {expectation.attempt
|
34
|
+
3.times {expectation.attempt}
|
35
35
|
expectation.should_not be_attempt
|
36
36
|
end
|
37
37
|
|
38
38
|
it "raises error before attempted more than expected times" do
|
39
|
-
3.times {expectation.attempt
|
40
|
-
|
41
|
-
Errors::TimesCalledError
|
42
|
-
)
|
39
|
+
3.times {expectation.attempt}
|
40
|
+
lambda {expectation.attempt}.should raise_error( Errors::TimesCalledError )
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
describe "#attempt!" do
|
47
45
|
it "fails when times called more than times" do
|
48
|
-
3.times {expectation.attempt
|
49
|
-
|
50
|
-
expectation.attempt
|
46
|
+
3.times {expectation.attempt}
|
47
|
+
lambda do
|
48
|
+
expectation.attempt
|
51
49
|
end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
|
52
50
|
end
|
53
51
|
|
54
52
|
it "passes when times called == times" do
|
55
|
-
3.times {expectation.attempt
|
53
|
+
3.times {expectation.attempt}
|
56
54
|
end
|
57
55
|
|
58
56
|
it "passes when times called < times" do
|
59
|
-
expectation.attempt
|
57
|
+
expectation.attempt
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -9,12 +9,12 @@ module RR
|
|
9
9
|
@object = Object.new
|
10
10
|
@method_name = :foobar
|
11
11
|
@double_injection = space.double_injection(object, method_name)
|
12
|
-
@double =
|
12
|
+
@double = Double.new(double_injection)
|
13
13
|
double.with_any_args
|
14
14
|
end
|
15
15
|
|
16
16
|
def raises_expectation_error(&block)
|
17
|
-
|
17
|
+
lambda {block.call}.should raise_error(Errors::TimesCalledError)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|