rr 0.4.3 → 0.4.4

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.
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
@@ -3,27 +3,23 @@ require "spec/spec_helper"
3
3
  module RR
4
4
  describe DoubleInjection, "#bind with an existing method" do
5
5
  before do
6
- @space = Space.new
7
6
  @object = Object.new
8
7
  @method_name = :foobar
9
8
  def @object.foobar;
10
9
  :original_foobar;
11
10
  end
12
- @original_method = @object.method(:foobar)
11
+ @original_method = @object.method(@method_name)
13
12
  @object.methods.should include(@method_name.to_s)
14
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
13
+ @double_injection = DoubleInjection.new(@object, @method_name)
15
14
  end
16
15
 
17
- it "overrides the original method with the double_insertion's dispatching methods" do
16
+ it "overrides the original method with the double_injection's dispatching methods" do
18
17
  @object.respond_to?(:__rr__foobar).should == false
19
- @double_insertion.bind
18
+ @double_injection.bind
20
19
  @object.respond_to?(:__rr__foobar).should == true
21
20
 
22
21
  rr_foobar_called = false
23
- (
24
- class << @object;
25
- self;
26
- end).class_eval do
22
+ (class << @object; self; end).class_eval do
27
23
  define_method :__rr__foobar do
28
24
  rr_foobar_called = true
29
25
  end
@@ -35,7 +31,7 @@ module RR
35
31
  end
36
32
 
37
33
  it "stores original method in __rr__original_method_name" do
38
- @double_insertion.bind
34
+ @double_injection.bind
39
35
  @object.respond_to?(:__rr__original_foobar).should == true
40
36
  @object.method(:__rr__original_foobar).should == @original_method
41
37
  end
@@ -43,23 +39,19 @@ module RR
43
39
 
44
40
  describe DoubleInjection, "#bind without an existing method" do
45
41
  before do
46
- @space = Space.new
47
42
  @object = Object.new
48
43
  @method_name = :foobar
49
44
  @object.methods.should_not include(@method_name.to_s)
50
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
45
+ @double_injection = DoubleInjection.new(@object, @method_name)
51
46
  end
52
47
 
53
- it "overrides the original method with the double_insertion's dispatching methods" do
48
+ it "creates a new method with the double_injection's dispatching methods" do
54
49
  @object.respond_to?(:__rr__foobar).should == false
55
- @double_insertion.bind
50
+ @double_injection.bind
56
51
  @object.respond_to?(:__rr__foobar).should == true
57
52
 
58
53
  rr_foobar_called = false
59
- (
60
- class << @object;
61
- self;
62
- end).class_eval do
54
+ (class << @object; self; end).class_eval do
63
55
  define_method :__rr__foobar do
64
56
  rr_foobar_called = true
65
57
  end
@@ -70,9 +62,44 @@ module RR
70
62
  rr_foobar_called.should == true
71
63
  end
72
64
 
73
- it "stores original method in __rr__original_method_name" do
74
- @double_insertion.bind
65
+ it "does not create method __rr__original_method_name" do
66
+ @double_injection.bind
75
67
  @object.respond_to?(:__rr__original_foobar).should == false
76
68
  end
77
69
  end
70
+
71
+ describe DoubleInjection, "#bind with ==" do
72
+ before do
73
+ @object = Object.new
74
+ @method_name = :'=='
75
+ @object.should respond_to(@method_name)
76
+ @original_method = @object.method(@method_name)
77
+ @object.methods.should include(@method_name.to_s)
78
+ @double_injection = DoubleInjection.new(@object, @method_name)
79
+ end
80
+
81
+ it "overrides the original method with the double_injection's dispatching methods" do
82
+ @object.respond_to?(:"__rr__#{@method_name}").should == false
83
+ @double_injection.bind
84
+ @object.respond_to?(:"__rr__#{@method_name}").should == true
85
+
86
+ override_called = false
87
+ method_name = @method_name
88
+ (class << @object; self; end).class_eval do
89
+ define_method :"__rr__#{method_name}" do
90
+ override_called = true
91
+ end
92
+ end
93
+
94
+ override_called.should == false
95
+ @object == 1
96
+ override_called.should == true
97
+ end
98
+
99
+ it "stores original method in __rr__original_method_name" do
100
+ @double_injection.bind
101
+ @object.respond_to?(:"__rr__original_#{@method_name}").should == true
102
+ @object.method(:"__rr__original_#{@method_name}").should == @original_method
103
+ end
104
+ end
78
105
  end
@@ -6,7 +6,7 @@ module RR
6
6
  @space = Space.new
7
7
  @object = Object.new
8
8
  @object.methods.should_not include(method_name.to_s)
9
- @double_insertion = @space.double_insertion(@object, method_name)
9
+ @double_injection = @space.double_injection(@object, method_name)
10
10
  end
11
11
 
12
12
  describe "normal methods" do
@@ -22,7 +22,7 @@ module RR
22
22
  yield(a, b)
23
23
  end
24
24
  end
25
- double = @space.double(@double_insertion)
25
+ double = @space.double(@double_injection)
26
26
  double.with(1, 2).implemented_by(method_fixture.method(:method_with_block))
27
27
  @object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
28
28
  end
@@ -30,11 +30,11 @@ module RR
30
30
 
31
31
  describe "where there are no doubles with duplicate ArgumentExpectations" do
32
32
  it "dispatches to Double that have an exact match" do
33
- double1_with_exact_match = @space.double(@double_insertion)
33
+ double1_with_exact_match = @space.double(@double_injection)
34
34
  double1_with_exact_match.with(:exact_match_1).returns {:return_1}
35
- double_with_no_match = @space.double(@double_insertion)
35
+ double_with_no_match = @space.double(@double_injection)
36
36
  double_with_no_match.with("nothing that matches").returns {:no_match}
37
- double2_with_exact_match = @space.double(@double_insertion)
37
+ double2_with_exact_match = @space.double(@double_injection)
38
38
  double2_with_exact_match.with(:exact_match_2).returns {:return_2}
39
39
 
40
40
  @object.foobar(:exact_match_1).should == :return_1
@@ -42,9 +42,9 @@ module RR
42
42
  end
43
43
 
44
44
  it "dispatches to Double that have a wildcard match" do
45
- double_with_wildcard_match = @space.double(@double_insertion)
45
+ double_with_wildcard_match = @space.double(@double_injection)
46
46
  double_with_wildcard_match.with_any_args.returns {:wild_card_value}
47
- double_with_no_match = @space.double(@double_insertion)
47
+ double_with_no_match = @space.double(@double_injection)
48
48
  double_with_no_match.with("nothing that matches").returns {:no_match}
49
49
 
50
50
  @object.foobar(:wildcard_match_1).should == :wild_card_value
@@ -54,18 +54,24 @@ module RR
54
54
 
55
55
  describe "where there are doubles" do
56
56
  it "raises DoubleNotFoundError error when arguments do not match a double" do
57
- double_1 = @space.double(@double_insertion)
57
+ double_1 = @space.double(@double_injection)
58
58
  double_1.with(1, 2)
59
59
 
60
- double_2 = @space.double(@double_insertion)
60
+ double_2 = @space.double(@double_injection)
61
61
  double_2.with(3)
62
62
 
63
- proc {@object.foobar(:arg1, :arg2)}.should raise_error(
64
- Errors::DoubleNotFoundError,
65
- "Unexpected method invocation foobar(:arg1, :arg2), expected\n" <<
66
- "- foobar(1, 2)\n" <<
67
- "- foobar(3)"
68
- )
63
+ error = nil
64
+ begin
65
+ @object.foobar(:arg1, :arg2)
66
+ viotated "Error should have been raised"
67
+ rescue Errors::DoubleNotFoundError => e
68
+ error = e
69
+ end
70
+ error.message.should include("On object #<Object")
71
+ expected_double_message_part = "unexpected method invocation foobar(:arg1, :arg2), expected\n" <<
72
+ "- foobar(1, 2)\n" <<
73
+ "- foobar(3)"
74
+ error.message.should include(expected_double_message_part)
69
75
  end
70
76
  end
71
77
 
@@ -102,7 +108,7 @@ module RR
102
108
  end
103
109
 
104
110
  def double(*arguments, &return_value)
105
- double = @space.double(@double_insertion)
111
+ double = @space.double(@double_injection)
106
112
  double.with(*arguments).any_number_of_times.returns(&return_value)
107
113
  double.should_not be_terminal
108
114
  double
@@ -144,7 +150,7 @@ module RR
144
150
  end
145
151
 
146
152
  def double(*arguments, &return_value)
147
- double = @space.double(@double_insertion)
153
+ double = @space.double(@double_injection)
148
154
  double.with(*arguments).once.returns(&return_value)
149
155
  double.should be_terminal
150
156
  double
@@ -186,7 +192,7 @@ module RR
186
192
  end
187
193
 
188
194
  def double(&return_value)
189
- double = @space.double(@double_insertion)
195
+ double = @space.double(@double_injection)
190
196
  double.with_any_args.once.returns(&return_value)
191
197
  double.should be_terminal
192
198
  double
@@ -200,7 +206,7 @@ module RR
200
206
  end
201
207
 
202
208
  it "executes the block" do
203
- double = @space.double(@double_insertion)
209
+ double = @space.double(@double_injection)
204
210
  double.with(1, 2) {:return_value}
205
211
  @object.foobar!(1, 2).should == :return_value
206
212
  end
@@ -212,7 +218,7 @@ module RR
212
218
  end
213
219
 
214
220
  it "executes the block" do
215
- double = @space.double(@double_insertion)
221
+ double = @space.double(@double_injection)
216
222
  double.with(1, 2) {:return_value}
217
223
  @object.foobar?(1, 2).should == :return_value
218
224
  end
@@ -3,22 +3,21 @@ require "spec/spec_helper"
3
3
  module RR
4
4
  describe DoubleInjection, "#object_has_original_method?" do
5
5
  before do
6
- @space = Space.new
7
6
  @object = Object.new
8
7
  @method_name = :to_s
9
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
10
- class << @double_insertion
8
+ @double_injection = DoubleInjection.new(@object, @method_name)
9
+ class << @double_injection
11
10
  public :original_method_name
12
11
  end
13
12
  end
14
13
 
15
14
  it "returns true when method is still in object" do
16
- @double_insertion.bind
17
- @double_insertion.object_has_original_method?.should be_true
15
+ @double_injection.bind
16
+ @double_injection.object_has_original_method?.should be_true
18
17
  end
19
18
 
20
19
  it "returns true when respond_to is true and methods include method" do
21
- @double_insertion.bind
20
+ @double_injection.bind
22
21
  def @object.methods
23
22
  [:__rr_original_to_s]
24
23
  end
@@ -26,11 +25,11 @@ module RR
26
25
  true
27
26
  end
28
27
 
29
- @double_insertion.object_has_original_method?.should be_true
28
+ @double_injection.object_has_original_method?.should be_true
30
29
  end
31
30
 
32
31
  it "returns true when respond_to is true and methods do not include method" do
33
- @double_insertion.bind
32
+ @double_injection.bind
34
33
  def @object.methods
35
34
  []
36
35
  end
@@ -38,11 +37,11 @@ module RR
38
37
  true
39
38
  end
40
39
 
41
- @double_insertion.object_has_original_method?.should be_true
40
+ @double_injection.object_has_original_method?.should be_true
42
41
  end
43
42
 
44
43
  it "returns false when respond_to is false and methods do not include method" do
45
- @double_insertion.bind
44
+ @double_injection.bind
46
45
  def @object.methods
47
46
  []
48
47
  end
@@ -50,7 +49,7 @@ module RR
50
49
  false
51
50
  end
52
51
 
53
- @double_insertion.object_has_original_method?.should be_false
52
+ @double_injection.object_has_original_method?.should be_false
54
53
  end
55
54
  end
56
55
  end
@@ -7,18 +7,18 @@ 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 = DoubleInjection.new(@space, @object, @method_name)
11
- def @double_insertion.doubles
10
+ @double_injection = DoubleInjection.new(@object, @method_name)
11
+ def @double_injection.doubles
12
12
  @doubles
13
13
  end
14
14
  end
15
15
 
16
16
  it "adds the double to the doubles list" do
17
- double = Double.new(@space, @double_insertion, @space.double_definition)
17
+ double = Double.new(@space, @double_injection, @space.double_definition)
18
18
 
19
- @double_insertion.doubles.should_not include(double)
20
- @double_insertion.register_double double
21
- @double_insertion.doubles.should include(double)
19
+ @double_injection.doubles.should_not include(double)
20
+ @double_injection.register_double double
21
+ @double_injection.doubles.should include(double)
22
22
  end
23
23
  end
24
24
  end
@@ -3,10 +3,10 @@ require "spec/spec_helper"
3
3
  module RR
4
4
  describe DoubleInjection, "#reset", :shared => true do
5
5
  it "cleans up by removing the __rr__method" do
6
- @double_insertion.bind
6
+ @double_injection.bind
7
7
  @object.methods.should include("__rr__foobar")
8
8
 
9
- @double_insertion.reset
9
+ @double_injection.reset
10
10
  @object.methods.should_not include("__rr__foobar")
11
11
  end
12
12
  end
@@ -15,18 +15,17 @@ module RR
15
15
  it_should_behave_like "RR::DoubleInjection#reset"
16
16
 
17
17
  before do
18
- @space = Space.new
19
18
  @object = Object.new
20
19
  @method_name = :foobar
21
20
  @object.methods.should_not include(@method_name.to_s)
22
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
21
+ @double_injection = DoubleInjection.new(@object, @method_name)
23
22
  end
24
23
 
25
24
  it "removes the method" do
26
- @double_insertion.bind
25
+ @double_injection.bind
27
26
  @object.methods.should include(@method_name.to_s)
28
27
 
29
- @double_insertion.reset
28
+ @double_injection.reset
30
29
  @object.methods.should_not include(@method_name.to_s)
31
30
  proc {@object.foobar}.should raise_error(NoMethodError)
32
31
  end
@@ -36,7 +35,6 @@ module RR
36
35
  it_should_behave_like "RR::DoubleInjection#reset"
37
36
 
38
37
  before do
39
- @space = Space.new
40
38
  @object = Object.new
41
39
  @method_name = :foobar
42
40
  def @object.foobar
@@ -44,14 +42,14 @@ module RR
44
42
  end
45
43
  @object.methods.should include(@method_name.to_s)
46
44
  @original_method = @object.method(@method_name)
47
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
45
+ @double_injection = DoubleInjection.new(@object, @method_name)
48
46
 
49
- @double_insertion.bind
47
+ @double_injection.bind
50
48
  @object.methods.should include(@method_name.to_s)
51
49
  end
52
50
 
53
51
  it "rebind original method" do
54
- @double_insertion.reset
52
+ @double_injection.reset
55
53
  @object.methods.should include(@method_name.to_s)
56
54
  @object.foobar.should == :original_foobar
57
55
  end
@@ -61,7 +59,6 @@ module RR
61
59
  it_should_behave_like "RR::DoubleInjection#reset"
62
60
 
63
61
  before do
64
- @space = Space.new
65
62
  @object = Object.new
66
63
  @method_name = :foobar
67
64
  def @object.foobar
@@ -69,14 +66,14 @@ module RR
69
66
  end
70
67
  @object.methods.should include(@method_name.to_s)
71
68
  @original_method = @object.method(@method_name)
72
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
69
+ @double_injection = DoubleInjection.new(@object, @method_name)
73
70
 
74
- @double_insertion.bind
71
+ @double_injection.bind
75
72
  @object.methods.should include(@method_name.to_s)
76
73
  end
77
74
 
78
75
  it "rebinds original method with block" do
79
- @double_insertion.reset
76
+ @double_injection.reset
80
77
  @object.methods.should include(@method_name.to_s)
81
78
 
82
79
  original_argument = nil
@@ -3,8 +3,8 @@ require "spec/spec_helper"
3
3
  module RR
4
4
  describe DoubleInjection, :shared => true do
5
5
  it "sets up object and method_name" do
6
- @double_insertion.object.should === @object
7
- @double_insertion.method_name.should == @method_name.to_sym
6
+ @double_injection.object.should === @object
7
+ @double_injection.method_name.should == @method_name.to_sym
8
8
  end
9
9
  end
10
10
 
@@ -12,11 +12,10 @@ module RR
12
12
  it_should_behave_like "RR::DoubleInjection"
13
13
 
14
14
  before do
15
- @space = Space.new
16
15
  @object = Object.new
17
16
  @method_name = :foobar
18
17
  @object.methods.should_not include(@method_name.to_s)
19
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
18
+ @double_injection = DoubleInjection.new(@object, @method_name)
20
19
  end
21
20
  end
22
21
 
@@ -24,11 +23,10 @@ module RR
24
23
  it_should_behave_like "RR::DoubleInjection"
25
24
 
26
25
  before do
27
- @space = Space.new
28
26
  @object = Object.new
29
27
  @method_name = 'foobar'
30
28
  @object.methods.should_not include(@method_name)
31
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
29
+ @double_injection = DoubleInjection.new(@object, @method_name)
32
30
  end
33
31
  end
34
32
 
@@ -36,15 +34,14 @@ module RR
36
34
  it_should_behave_like "RR::DoubleInjection"
37
35
 
38
36
  before do
39
- @space = Space.new
40
37
  @object = Object.new
41
38
  @method_name = :foobar
42
39
  @object.methods.should_not include(@method_name.to_s)
43
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
40
+ @double_injection = DoubleInjection.new(@object, @method_name)
44
41
  end
45
42
 
46
43
  it "object does not have original method" do
47
- @double_insertion.object_has_original_method?.should be_false
44
+ @double_injection.object_has_original_method?.should be_false
48
45
  end
49
46
  end
50
47
 
@@ -52,15 +49,24 @@ module RR
52
49
  it_should_behave_like "RR::DoubleInjection"
53
50
 
54
51
  before do
55
- @space = Space.new
56
52
  @object = Object.new
57
53
  @method_name = :to_s
58
54
  @object.methods.should include(@method_name.to_s)
59
- @double_insertion = DoubleInjection.new(@space, @object, @method_name)
55
+ @double_injection = DoubleInjection.new(@object, @method_name)
60
56
  end
61
57
 
62
58
  it "has a original_method" do
63
- @double_insertion.object_has_original_method?.should be_true
59
+ @double_injection.object_has_original_method?.should be_true
64
60
  end
65
61
  end
62
+
63
+ describe DoubleInjection, "#initialize where method_name is ==" do
64
+ it_should_behave_like "RR::DoubleInjection"
65
+
66
+ before do
67
+ @object = Object.new
68
+ @method_name = '=='
69
+ @double_injection = DoubleInjection.new(@object, @method_name)
70
+ end
71
+ end
66
72
  end