rr 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGES +4 -0
  2. data/README +25 -0
  3. data/Rakefile +1 -1
  4. data/lib/rr/double.rb +10 -10
  5. data/lib/rr/double_creator.rb +5 -5
  6. data/lib/rr/double_injection.rb +7 -7
  7. data/lib/rr/double_method_proxy.rb +1 -2
  8. data/lib/rr/space.rb +21 -21
  9. data/lib/rr/wildcard_matchers/anything.rb +4 -0
  10. data/lib/rr/wildcard_matchers/boolean.rb +4 -0
  11. data/lib/rr/wildcard_matchers/duck_type.rb +7 -0
  12. data/lib/rr/wildcard_matchers/is_a.rb +4 -0
  13. data/lib/rr/wildcard_matchers/numeric.rb +4 -0
  14. data/spec/high_level_spec.rb +14 -0
  15. data/spec/rr/adapters/rr_methods_space_spec.rb +16 -16
  16. data/spec/rr/double/double_injection_bind_spec.rb +47 -20
  17. data/spec/rr/double/double_injection_dispatching_spec.rb +26 -20
  18. data/spec/rr/double/double_injection_has_original_method_spec.rb +10 -11
  19. data/spec/rr/double/double_injection_register_scenario_spec.rb +6 -6
  20. data/spec/rr/double/double_injection_reset_spec.rb +11 -14
  21. data/spec/rr/double/double_injection_spec.rb +18 -12
  22. data/spec/rr/double/double_injection_verify_spec.rb +5 -5
  23. data/spec/rr/double_definition_spec.rb +5 -5
  24. data/spec/rr/double_method_proxy_spec.rb +5 -5
  25. data/spec/rr/double_spec.rb +48 -48
  26. data/spec/rr/expectations/anything_spec.rb +14 -0
  27. data/spec/rr/expectations/boolean_spec.rb +14 -0
  28. data/spec/rr/expectations/duck_type_spec.rb +14 -0
  29. data/spec/rr/expectations/is_a_spec.rb +14 -0
  30. data/spec/rr/expectations/numeric_spec.rb +14 -0
  31. data/spec/rr/expectations/range_spec.rb +10 -0
  32. data/spec/rr/expectations/regexp_spec.rb +10 -0
  33. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +3 -3
  34. data/spec/rr/rspec/rspec_adapter_spec.rb +12 -12
  35. data/spec/rr/space/space_create_spec.rb +27 -37
  36. data/spec/rr/space/space_register_spec.rb +3 -3
  37. data/spec/rr/space/space_reset_spec.rb +24 -24
  38. data/spec/rr/space/space_spec.rb +2 -2
  39. data/spec/rr/space/space_verify_spec.rb +18 -18
  40. metadata +9 -2
@@ -7,17 +7,17 @@ module RR
7
7
  @object = Object.new
8
8
  @method_name = :foobar
9
9
  @object.methods.should_not include(@method_name.to_s)
10
- @double_insertion = @space.double_insertion(@object, @method_name)
10
+ @double_injection = @space.double_injection(@object, @method_name)
11
11
  end
12
12
 
13
13
  it "verifies each double was met" do
14
- double = Double.new(@space, @double_insertion, @space.double_definition)
15
- @double_insertion.register_double double
14
+ double = Double.new(@space, @double_injection, @space.double_definition)
15
+ @double_injection.register_double double
16
16
 
17
17
  double.with(1).once.returns {nil}
18
- proc {@double_insertion.verify}.should raise_error(Errors::TimesCalledError)
18
+ proc {@double_injection.verify}.should raise_error(Errors::TimesCalledError)
19
19
  @object.foobar(1)
20
- proc {@double_insertion.verify}.should_not raise_error
20
+ proc {@double_injection.verify}.should_not raise_error
21
21
  end
22
22
  end
23
23
  end
@@ -6,8 +6,8 @@ describe DoubleDefinition, :shared => true do
6
6
  @space = Space.new
7
7
  @object = Object.new
8
8
  add_original_method
9
- @double_insertion = @space.double_insertion(@object, :foobar)
10
- @double = @space.double(@double_insertion)
9
+ @double_injection = @space.double_injection(@object, :foobar)
10
+ @double = @space.double(@double_injection)
11
11
  @definition = @double.definition
12
12
  end
13
13
 
@@ -459,7 +459,7 @@ describe DoubleDefinition, "#ordered", :shared => true do
459
459
  @space.ordered_doubles.should include(@double)
460
460
  end
461
461
 
462
- it "does not double_insertion add itself" do
462
+ it "does not double_injection add itself" do
463
463
  @definition.ordered
464
464
  @space.ordered_doubles.should == [@double]
465
465
  end
@@ -683,8 +683,8 @@ describe DoubleDefinition, "#implemented_by_original_method" do
683
683
  "method_missing for #{method_name}(#{args.inspect})"
684
684
  end
685
685
  end
686
- double_insertion = @space.double_insertion(@object, :does_not_exist)
687
- double = @space.double(double_insertion)
686
+ double_injection = @space.double_injection(@object, :does_not_exist)
687
+ double = @space.double(double_injection)
688
688
  double.with_any_args
689
689
  double.implemented_by_original_method
690
690
 
@@ -22,7 +22,7 @@ module RR
22
22
  describe ".new without block" do
23
23
  it_should_behave_like "RR::DoubleMethodProxy initializes proxy with passed in creator"
24
24
  before do
25
- @the_proxy = DoubleMethodProxy.new(space, creator, subject)
25
+ @the_proxy = DoubleMethodProxy.new(creator, subject)
26
26
  end
27
27
 
28
28
  it "clears out all methods from proxy" do
@@ -32,7 +32,7 @@ module RR
32
32
  end
33
33
  proxy_subclass.instance_methods.should include('i_should_be_a_double')
34
34
 
35
- proxy = proxy_subclass.new(space, creator, subject)
35
+ proxy = proxy_subclass.new(creator, subject)
36
36
  proxy.i_should_be_a_double.should be_instance_of(DoubleDefinition)
37
37
  end
38
38
  end
@@ -40,7 +40,7 @@ module RR
40
40
  describe ".new with block" do
41
41
  it_should_behave_like "RR::DoubleMethodProxy initializes proxy with passed in creator"
42
42
  before do
43
- @the_proxy = DoubleMethodProxy.new(space, creator, subject) do |b|
43
+ @the_proxy = DoubleMethodProxy.new(creator, subject) do |b|
44
44
  b.foobar(1, 2) {:one_two}
45
45
  b.foobar(1) {:one}
46
46
  b.foobar.with_any_args {:default}
@@ -48,7 +48,7 @@ module RR
48
48
  end
49
49
  end
50
50
 
51
- it "creates double_insertions" do
51
+ it "creates double_injections" do
52
52
  subject.foobar(1, 2).should == :one_two
53
53
  subject.foobar(1).should == :one
54
54
  subject.foobar(:something).should == :default
@@ -62,7 +62,7 @@ module RR
62
62
  end
63
63
  proxy_subclass.instance_methods.should include('i_should_be_a_double')
64
64
 
65
- proxy_subclass.new(space, creator, subject) do |m|
65
+ proxy_subclass.new(creator, subject) do |m|
66
66
  m.i_should_be_a_double.should be_instance_of(DoubleDefinition)
67
67
  end
68
68
  end
@@ -2,15 +2,15 @@ require "spec/spec_helper"
2
2
 
3
3
  module RR
4
4
  describe Double do
5
- attr_reader :space, :object, :double_insertion, :double
5
+ attr_reader :space, :object, :double_injection, :double
6
6
  before do
7
7
  @space = Space.new
8
8
  @object = Object.new
9
9
  def object.foobar(a, b)
10
10
  [b, a]
11
11
  end
12
- @double_insertion = space.double_insertion(object, :foobar)
13
- @double = space.double(double_insertion)
12
+ @double_injection = space.double_injection(object, :foobar)
13
+ @double = space.double(double_injection)
14
14
  end
15
15
 
16
16
  describe "#with" do
@@ -74,12 +74,12 @@ module RR
74
74
 
75
75
  it "sets up a Times Called Expectation with 0" do
76
76
  double.never
77
- proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
77
+ proc {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
78
78
  end
79
79
 
80
80
  it "sets return value when block passed in" do
81
81
  double.with_any_args.never
82
- proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
82
+ proc {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
83
83
  end
84
84
  end
85
85
 
@@ -90,8 +90,8 @@ module RR
90
90
 
91
91
  it "sets up a Times Called Expectation with 1" do
92
92
  double.once
93
- double.call(double_insertion)
94
- proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
93
+ double.call(double_injection)
94
+ proc {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
95
95
  end
96
96
 
97
97
  it "sets return value when block passed in" do
@@ -107,9 +107,9 @@ module RR
107
107
 
108
108
  it "sets up a Times Called Expectation with 2" do
109
109
  double.twice
110
- double.call(double_insertion)
111
- double.call(double_insertion)
112
- proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
110
+ double.call(double_injection)
111
+ double.call(double_injection)
112
+ proc {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
113
113
  end
114
114
 
115
115
  it "sets return value when block passed in" do
@@ -141,10 +141,10 @@ module RR
141
141
 
142
142
  it "sets up a Times Called Expectation with 1" do
143
143
  double.at_most(2)
144
- double.call(double_insertion)
145
- double.call(double_insertion)
144
+ double.call(double_injection)
145
+ double.call(double_injection)
146
146
  proc do
147
- double.call(double_insertion)
147
+ double.call(double_injection)
148
148
  end.should raise_error(
149
149
  Errors::TimesCalledError,
150
150
  "foobar()\nCalled 3 times.\nExpected at most 2 times."
@@ -164,10 +164,10 @@ module RR
164
164
 
165
165
  it "sets up a Times Called Expectation with passed in times" do
166
166
  double.times(3)
167
- double.call(double_insertion)
168
- double.call(double_insertion)
169
- double.call(double_insertion)
170
- proc {double.call(double_insertion)}.should raise_error(Errors::TimesCalledError)
167
+ double.call(double_injection)
168
+ double.call(double_injection)
169
+ double.call(double_injection)
170
+ proc {double.call(double_injection)}.should raise_error(Errors::TimesCalledError)
171
171
  end
172
172
 
173
173
  it "sets return value when block passed in" do
@@ -198,7 +198,7 @@ module RR
198
198
  space.ordered_doubles.should include(double)
199
199
  end
200
200
 
201
- it "does not double_insertion add itself" do
201
+ it "does not double_injection add itself" do
202
202
  double.ordered
203
203
  double.ordered
204
204
  space.ordered_doubles.should == [double ]
@@ -259,7 +259,7 @@ module RR
259
259
  value
260
260
  end
261
261
 
262
- actual_value = double.call(double_insertion)
262
+ actual_value = double.call(double_injection)
263
263
  actual_value.should === return_value
264
264
  actual_value.should == {:foo => :bar}
265
265
  end
@@ -270,7 +270,7 @@ module RR
270
270
  :after_call_value
271
271
  end
272
272
 
273
- actual_value = double.call(double_insertion)
273
+ actual_value = double.call(double_injection)
274
274
  actual_value.should == :after_call_value
275
275
  end
276
276
 
@@ -299,17 +299,17 @@ module RR
299
299
 
300
300
  it "sets the value of the method when passed a block" do
301
301
  double.returns {:baz}
302
- double.call(double_insertion).should == :baz
302
+ double.call(double_injection).should == :baz
303
303
  end
304
304
 
305
305
  it "sets the value of the method when passed an argument" do
306
306
  double.returns(:baz)
307
- double.call(double_insertion).should == :baz
307
+ double.call(double_injection).should == :baz
308
308
  end
309
309
 
310
310
  it "returns false when passed false" do
311
311
  double.returns(false)
312
- double.call(double_insertion).should == false
312
+ double.call(double_injection).should == false
313
313
  end
314
314
 
315
315
  it "raises an error when both argument and block is passed in" do
@@ -326,7 +326,7 @@ module RR
326
326
 
327
327
  it "sets the implementation to the passed in proc" do
328
328
  double.implemented_by(proc{:baz})
329
- double.call(double_insertion).should == :baz
329
+ double.call(double_injection).should == :baz
330
330
  end
331
331
 
332
332
  it "sets the implementation to the passed in method" do
@@ -334,7 +334,7 @@ module RR
334
334
  [b, a]
335
335
  end
336
336
  double.implemented_by(object.method(:foobar))
337
- double.call(double_insertion, 1, 2).should == [2, 1]
337
+ double.call(double_injection, 1, 2).should == [2, 1]
338
338
  end
339
339
  end
340
340
 
@@ -345,7 +345,7 @@ module RR
345
345
 
346
346
  it "sets the implementation to the original method" do
347
347
  double.implemented_by_original_method
348
- double.call(double_insertion, 1, 2).should == [2, 1]
348
+ double.call(double_injection, 1, 2).should == [2, 1]
349
349
  end
350
350
 
351
351
  it "calls methods when respond_to? is true and methods does not contain original method" do
@@ -365,8 +365,8 @@ module RR
365
365
  end
366
366
  end
367
367
 
368
- double_insertion = space.double_insertion(object, :foobar)
369
- double = space.double(double_insertion)
368
+ double_injection = space.double_injection(object, :foobar)
369
+ double = space.double(double_injection)
370
370
  double.with_any_args
371
371
  double.implemented_by_original_method
372
372
 
@@ -379,8 +379,8 @@ module RR
379
379
  "method_missing for #{method_name}(#{args.inspect})"
380
380
  end
381
381
  end
382
- double_insertion = space.double_insertion(object, :does_not_exist)
383
- double = space.double(double_insertion)
382
+ double_injection = space.double_injection(object, :does_not_exist)
383
+ double = space.double(double_injection)
384
384
  double.with_any_args
385
385
  double.implemented_by_original_method
386
386
 
@@ -392,36 +392,36 @@ module RR
392
392
  describe "#call implemented by a proc" do
393
393
  it "calls the return proc when implemented by a proc" do
394
394
  double.returns {|arg| "returning #{arg}"}
395
- double.call(double_insertion, :foobar).should == "returning foobar"
395
+ double.call(double_injection, :foobar).should == "returning foobar"
396
396
  end
397
397
 
398
398
  it "calls and returns the after_call when after_call is set" do
399
399
  double.returns {|arg| "returning #{arg}"}.after_call do |value|
400
400
  "#{value} after call"
401
401
  end
402
- double.call(double_insertion, :foobar).should == "returning foobar after call"
402
+ double.call(double_injection, :foobar).should == "returning foobar after call"
403
403
  end
404
404
 
405
405
  it "returns nil when to returns is not set" do
406
- double.call(double_insertion).should be_nil
406
+ double.call(double_injection).should be_nil
407
407
  end
408
408
 
409
409
  it "works when times_called is not set" do
410
410
  double.returns {:value}
411
- double.call(double_insertion)
411
+ double.call(double_injection)
412
412
  end
413
413
 
414
414
  it "verifes the times_called does not exceed the TimesCalledExpectation" do
415
415
  double.times(2).returns {:value}
416
416
 
417
- double.call(double_insertion, :foobar)
418
- double.call(double_insertion, :foobar)
419
- proc {double.call(double_insertion, :foobar)}.should raise_error(Errors::TimesCalledError)
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
420
  end
421
421
 
422
422
  it "raises DoubleOrderError when ordered and called out of order" do
423
423
  double1 = double
424
- double2 = space.double(double_insertion)
424
+ double2 = space.double(double_injection)
425
425
 
426
426
  double1.with(1).returns {:return_1}.ordered.once
427
427
  double2.with(2).returns {:return_2}.ordered.once
@@ -451,7 +451,7 @@ module RR
451
451
  end
452
452
 
453
453
  double.returns {:value}.ordered
454
- double.call(double_insertion, :foobar)
454
+ double.call(double_injection, :foobar)
455
455
  verify_ordered_double_called.should be_true
456
456
  passed_in_double.should === double
457
457
  end
@@ -469,7 +469,7 @@ module RR
469
469
  end
470
470
 
471
471
  double.returns {:value}
472
- double.call(double_insertion, :foobar)
472
+ double.call(double_injection, :foobar)
473
473
  verify_ordered_double_called.should be_false
474
474
  end
475
475
 
@@ -561,15 +561,15 @@ module RR
561
561
  describe "#attempt?" do
562
562
  it "returns true when TimesCalledExpectation#attempt? is true" do
563
563
  double.with(1, 2, 3).twice
564
- double.call(double_insertion, 1, 2, 3)
564
+ double.call(double_injection, 1, 2, 3)
565
565
  double.times_called_expectation.should be_attempt
566
566
  double.should be_attempt
567
567
  end
568
568
 
569
569
  it "returns false when TimesCalledExpectation#attempt? is true" do
570
570
  double.with(1, 2, 3).twice
571
- double.call(double_insertion, 1, 2, 3)
572
- double.call(double_insertion, 1, 2, 3)
571
+ double.call(double_injection, 1, 2, 3)
572
+ double.call(double_injection, 1, 2, 3)
573
573
  double.times_called_expectation.should_not be_attempt
574
574
  double.should_not be_attempt
575
575
  end
@@ -586,18 +586,18 @@ module RR
586
586
  double.twice.returns {:return_value}
587
587
 
588
588
  proc {double.verify}.should raise_error(Errors::TimesCalledError)
589
- double.call(double_insertion)
589
+ double.call(double_injection)
590
590
  proc {double.verify}.should raise_error(Errors::TimesCalledError)
591
- double.call(double_insertion)
591
+ double.call(double_injection)
592
592
 
593
593
  proc {double.verify}.should_not raise_error
594
594
  end
595
595
 
596
596
  it "does not raise an error when there is no times called expectation" do
597
597
  proc {double.verify}.should_not raise_error
598
- double.call(double_insertion)
598
+ double.call(double_injection)
599
599
  proc {double.verify}.should_not raise_error
600
- double.call(double_insertion)
600
+ double.call(double_injection)
601
601
  proc {double.verify}.should_not raise_error
602
602
  end
603
603
  end
@@ -623,7 +623,7 @@ module RR
623
623
 
624
624
  describe "#method_name" do
625
625
  it "returns the DoubleInjection's method_name" do
626
- double_insertion.method_name.should == :foobar
626
+ double_injection.method_name.should == :foobar
627
627
  double.method_name.should == :foobar
628
628
  end
629
629
  end
@@ -0,0 +1,14 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe Anything do
6
+ describe "#inspect" do
7
+ it "returns anything" do
8
+ matcher = Anything.new
9
+ matcher.inspect.should == "anything"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe Boolean do
6
+ describe "#inspect" do
7
+ it "returns boolean" do
8
+ matcher = Boolean.new
9
+ matcher.inspect.should == "boolean"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe DuckType do
6
+ describe "#inspect" do
7
+ it "returns duck_type with methods" do
8
+ matcher = DuckType.new(:foo, :bar, :baz)
9
+ matcher.inspect.should == "duck_type(:foo, :bar, :baz)"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe IsA do
6
+ describe "#inspect" do
7
+ it "returns the is_a(ClassName)" do
8
+ matcher = IsA.new(Symbol)
9
+ matcher.inspect.should == "is_a(Symbol)"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end