rr 0.10.2 → 0.10.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/README.rdoc +1 -0
- data/Rakefile +5 -1
- data/VERSION.yml +1 -1
- data/lib/rr.rb +8 -1
- data/lib/rr/double.rb +18 -78
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +1 -1
- data/lib/rr/hash_with_object_id_key.rb +1 -3
- data/lib/rr/injections/double_injection.rb +119 -0
- data/lib/rr/injections/injection.rb +22 -0
- data/lib/rr/injections/method_missing_injection.rb +62 -0
- data/lib/rr/injections/singleton_method_added_injection.rb +58 -0
- data/lib/rr/method_dispatches/base_method_dispatch.rb +84 -0
- data/lib/rr/method_dispatches/method_dispatch.rb +58 -0
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +59 -0
- data/lib/rr/space.rb +44 -4
- data/lib/rr/spy_verification_proxy.rb +1 -1
- data/spec/rr/double_injection/double_injection_spec.rb +523 -66
- data/spec/rr/double_injection/double_injection_verify_spec.rb +3 -3
- data/spec/rr/double_spec.rb +18 -18
- data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +250 -64
- data/spec/spec_helper.rb +5 -0
- metadata +9 -7
- data/lib/rr/double_injection.rb +0 -136
- data/spec/rr/double_injection/double_injection_bind_spec.rb +0 -99
- data/spec/rr/double_injection/double_injection_dispatching_spec.rb +0 -244
- data/spec/rr/double_injection/double_injection_has_original_method_spec.rb +0 -58
- data/spec/rr/double_injection/double_injection_reset_spec.rb +0 -72
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe DoubleInjection do
|
5
|
-
describe "#object_has_original_method?" do
|
6
|
-
attr_reader :subject, :method_name, :double_injection
|
7
|
-
before do
|
8
|
-
@subject = Object.new
|
9
|
-
@method_name = :to_s
|
10
|
-
@double_injection = DoubleInjection.new(subject, method_name, (class << subject; self; end))
|
11
|
-
class << double_injection
|
12
|
-
public :original_method_alias_name
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns true when method is still in object" do
|
17
|
-
double_injection.bind
|
18
|
-
double_injection.object_has_original_method?.should be_true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns true when respond_to is true and methods include method" do
|
22
|
-
double_injection.bind
|
23
|
-
def subject.methods
|
24
|
-
[:__rr_original_to_s]
|
25
|
-
end
|
26
|
-
def subject.respond_to?(value)
|
27
|
-
true
|
28
|
-
end
|
29
|
-
|
30
|
-
double_injection.object_has_original_method?.should be_true
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns true when respond_to is true and methods do not include method" do
|
34
|
-
double_injection.bind
|
35
|
-
def subject.methods
|
36
|
-
[]
|
37
|
-
end
|
38
|
-
def subject.respond_to?(value)
|
39
|
-
true
|
40
|
-
end
|
41
|
-
|
42
|
-
double_injection.object_has_original_method?.should be_true
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns false when respond_to is false and methods do not include method" do
|
46
|
-
double_injection.bind
|
47
|
-
def subject.methods
|
48
|
-
[]
|
49
|
-
end
|
50
|
-
def subject.respond_to?(value)
|
51
|
-
false
|
52
|
-
end
|
53
|
-
|
54
|
-
double_injection.object_has_original_method?.should be_false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe DoubleInjection do
|
5
|
-
describe "#reset" do
|
6
|
-
attr_reader :subject, :method_name, :double_injection
|
7
|
-
context "when method does not exist" do
|
8
|
-
before do
|
9
|
-
@subject = Object.new
|
10
|
-
@method_name = :foobar
|
11
|
-
subject.methods.should_not include(method_name.to_s)
|
12
|
-
@double_injection = DoubleInjection.new(subject, method_name, (class << subject; self; end))
|
13
|
-
end
|
14
|
-
|
15
|
-
it "removes the method" do
|
16
|
-
double_injection.bind
|
17
|
-
subject.methods.should include(method_name.to_s)
|
18
|
-
|
19
|
-
double_injection.reset
|
20
|
-
subject.methods.should_not include(method_name.to_s)
|
21
|
-
lambda {subject.foobar}.should raise_error(NoMethodError)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when method exists" do
|
26
|
-
before do
|
27
|
-
@subject = Object.new
|
28
|
-
@method_name = :foobar
|
29
|
-
def subject.foobar
|
30
|
-
:original_foobar
|
31
|
-
end
|
32
|
-
subject.methods.should include(method_name.to_s)
|
33
|
-
@original_method = subject.method(method_name)
|
34
|
-
@double_injection = RR::Space.double_injection(subject, method_name)
|
35
|
-
subject.methods.should include(method_name.to_s)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "rebind original method" do
|
39
|
-
double_injection.reset
|
40
|
-
subject.methods.should include(method_name.to_s)
|
41
|
-
subject.foobar.should == :original_foobar
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when method with block exists" do
|
46
|
-
before do
|
47
|
-
@subject = Object.new
|
48
|
-
@method_name = :foobar
|
49
|
-
def subject.foobar
|
50
|
-
yield(:original_argument)
|
51
|
-
end
|
52
|
-
subject.methods.should include(method_name.to_s)
|
53
|
-
@original_method = subject.method(method_name)
|
54
|
-
@double_injection = RR::Space.double_injection(subject, method_name)
|
55
|
-
|
56
|
-
subject.methods.should include(method_name.to_s)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "rebinds original method with block" do
|
60
|
-
double_injection.reset
|
61
|
-
subject.methods.should include(method_name.to_s)
|
62
|
-
|
63
|
-
original_argument = nil
|
64
|
-
subject.foobar do |arg|
|
65
|
-
original_argument = arg
|
66
|
-
end
|
67
|
-
original_argument.should == :original_argument
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|