rr 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ * 0.2.2
2
+ - Fixed "singleton method bound for a different object"
3
+ - Doing Method aliasing again to store original method
4
+
1
5
  * 0.2.1
2
6
  - Added mock_probe
3
7
  - Added stub_probe
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ def run_suite
21
21
  end
22
22
 
23
23
  PKG_NAME = "rr"
24
- PKG_VERSION = "0.2.1"
24
+ PKG_VERSION = "0.2.2"
25
25
  PKG_FILES = FileList[
26
26
  '[A-Z]*',
27
27
  '*.rb',
@@ -28,6 +28,12 @@ describe Double, "#bind with an existing method" do
28
28
  @object.foobar
29
29
  rr_foobar_called.should == true
30
30
  end
31
+
32
+ it "stores original method in __rr__original_method_name" do
33
+ @double.bind
34
+ @object.respond_to?(:__rr__original_foobar).should == true
35
+ @object.method(:__rr__original_foobar).should == @original_method
36
+ end
31
37
  end
32
38
 
33
39
  describe Double, "#bind without an existing method" do
@@ -55,5 +61,10 @@ describe Double, "#bind without an existing method" do
55
61
  @object.foobar
56
62
  rr_foobar_called.should == true
57
63
  end
64
+
65
+ it "stores original method in __rr__original_method_name" do
66
+ @double.bind
67
+ @object.respond_to?(:__rr__original_foobar).should == false
68
+ end
58
69
  end
59
70
  end
data/lib/rr/double.rb CHANGED
@@ -4,13 +4,15 @@ module RR
4
4
  # has Argument Expectations and Times called Expectations.
5
5
  class Double
6
6
  MethodArguments = Struct.new(:arguments, :block)
7
- attr_reader :space, :object, :method_name, :original_method, :scenarios
7
+ attr_reader :space, :object, :method_name, :scenarios
8
8
 
9
9
  def initialize(space, object, method_name)
10
10
  @space = space
11
11
  @object = object
12
12
  @method_name = method_name.to_sym
13
- @original_method = object.method(method_name) if @object.methods.include?(method_name.to_s)
13
+ if @object.respond_to?(method_name)
14
+ meta.send(:alias_method, original_method_name, method_name)
15
+ end
14
16
  @scenarios = []
15
17
  end
16
18
 
@@ -22,7 +24,7 @@ module RR
22
24
 
23
25
  # RR::Double#bind injects a method that acts as a dispatcher
24
26
  # that dispatches to the matching Scenario when the method
25
- # is called.
27
+ # is called.
26
28
  def bind
27
29
  define_implementation_placeholder
28
30
  returns_method = <<-METHOD
@@ -44,16 +46,24 @@ module RR
44
46
 
45
47
  # RR::Double#reset removes the injected dispatcher method.
46
48
  # It binds the original method implementation on the object
47
- # if one exists.
49
+ # if one exists.
48
50
  def reset
49
51
  meta.send(:remove_method, placeholder_name)
50
- if @original_method
51
- meta.send(:define_method, @method_name, @original_method)
52
+ if original_method
53
+ meta.send(:alias_method, @method_name, original_method_name)
54
+ meta.send(:remove_method, original_method_name)
52
55
  else
53
56
  meta.send(:remove_method, @method_name)
54
57
  end
55
58
  end
56
59
 
60
+ # The original method of the object. It returns nil if the object
61
+ # does not have an original method.
62
+ def original_method
63
+ return nil unless @object.respond_to?(original_method_name)
64
+ return @object.method(original_method_name)
65
+ end
66
+
57
67
  protected
58
68
  def define_implementation_placeholder
59
69
  me = self
@@ -69,7 +79,6 @@ module RR
69
79
  scenario_not_found_error(*args)
70
80
  end
71
81
 
72
- protected
73
82
  def find_scenario_to_attempt(args)
74
83
  matches = ScenarioMatches.new(@scenarios).find_all_matches!(args)
75
84
 
@@ -106,9 +115,13 @@ module RR
106
115
  def placeholder_name
107
116
  "__rr__#{@method_name}"
108
117
  end
109
-
118
+
119
+ def original_method_name
120
+ "__rr__original_#{@method_name}"
121
+ end
122
+
110
123
  def meta
111
124
  (class << @object; self; end)
112
125
  end
113
126
  end
114
- end
127
+ end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: rr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
6
+ version: 0.2.2
7
7
  date: 2007-07-17 00:00:00 -07: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: