rr 0.10.11 → 1.0.0
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.
- data/CHANGES +5 -0
- data/Gemfile +6 -0
- data/README.rdoc +28 -2
- data/VERSION.yml +3 -3
- data/lib/rr.rb +23 -17
- data/lib/rr/adapters/rr_methods.rb +43 -17
- data/lib/rr/blank_slate.rb +2 -2
- data/lib/rr/class_instance_method_defined.rb +9 -0
- data/lib/rr/double.rb +2 -2
- data/lib/rr/double_definitions/double_definition.rb +29 -16
- data/lib/rr/double_definitions/double_definition_create.rb +52 -86
- data/lib/rr/double_definitions/double_injections/any_instance_of.rb +28 -0
- data/lib/rr/double_definitions/double_injections/instance.rb +16 -0
- data/lib/rr/double_definitions/double_injections/new_instance_of.rb +53 -0
- data/lib/rr/double_definitions/strategies/double_injection/any_instance_of.rb +31 -0
- data/lib/rr/double_definitions/strategies/double_injection/double_injection_strategy.rb +10 -0
- data/lib/rr/double_definitions/strategies/double_injection/instance.rb +17 -0
- data/lib/rr/double_definitions/strategies/double_injection/new_instance_of.rb +37 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +0 -5
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +0 -2
- data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +0 -2
- data/lib/rr/double_definitions/strategies/strategy.rb +0 -27
- data/lib/rr/double_definitions/strategies/strategy_methods.rb +53 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +0 -2
- data/lib/rr/double_definitions/strategies/verification/mock.rb +0 -2
- data/lib/rr/double_definitions/strategies/verification/stub.rb +0 -2
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +0 -5
- data/lib/rr/hash_with_object_id_key.rb +4 -0
- data/lib/rr/injections/double_injection.rb +94 -71
- data/lib/rr/injections/injection.rb +8 -10
- data/lib/rr/injections/method_missing_injection.rb +13 -20
- data/lib/rr/injections/singleton_method_added_injection.rb +19 -17
- data/lib/rr/method_dispatches/base_method_dispatch.rb +1 -1
- data/lib/rr/method_dispatches/method_dispatch.rb +4 -4
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +17 -14
- data/lib/rr/recorded_calls.rb +1 -1
- data/lib/rr/space.rb +6 -6
- data/lib/rr/times_called_matchers/times_called_matcher.rb +2 -2
- data/scratch.rb +118 -0
- data/spec/api/any_instance_of/all_instances_of_spec.rb +14 -0
- data/spec/api/any_instance_of/any_instance_of_spec.rb +47 -0
- data/spec/api/mock/mock_spec.rb +2 -2
- data/spec/api/new_instance_of/instance_of_spec.rb +15 -0
- data/spec/api/new_instance_of/new_instance_of_spec.rb +61 -0
- data/spec/environment_fixture_setup.rb +3 -2
- data/spec/rr/adapters/rr_methods_space_spec.rb +8 -10
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +1 -1
- data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +6 -2
- data/spec/rr/double_definitions/double_definition_create_spec.rb +1 -52
- data/spec/rr/double_injection/double_injection_verify_spec.rb +1 -1
- data/spec/rr/rspec/rspec_adapter_spec.rb +5 -5
- data/spec/rr/space/space_spec.rb +58 -67
- data/spec/spec_helper.rb +2 -2
- metadata +33 -9
- data/lib/rr/double_definitions/strategies/scope/instance.rb +0 -15
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +0 -50
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +0 -15
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
describe "all_instances_of" do
|
4
|
+
it "applies to instances instantiated before the Double expection was created" do
|
5
|
+
pending("Completion of all_instances_of") do
|
6
|
+
subject_class = Class.new
|
7
|
+
subject = subject_class.new
|
8
|
+
all_instances_of(subject_class) do |o|
|
9
|
+
o.to_s {"Subject is stubbed"}
|
10
|
+
end
|
11
|
+
subject.to_s.should == "Subject is stubbed"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
describe "any_instance_of" do
|
4
|
+
context "when passed a block" do
|
5
|
+
it "applies to instances instantiated before the Double expection was created" do
|
6
|
+
subject_class = Class.new
|
7
|
+
subject = subject_class.new
|
8
|
+
class_called = false
|
9
|
+
any_instance_of(subject_class) do |o|
|
10
|
+
stub(o).to_s {"Subject is stubbed"}
|
11
|
+
stub.proxy(o).class {|klass| class_called = true; klass}
|
12
|
+
stub(o).foobar {:baz}
|
13
|
+
end
|
14
|
+
|
15
|
+
subject.to_s.should == "Subject is stubbed"
|
16
|
+
subject.class.should == subject_class
|
17
|
+
class_called.should == true
|
18
|
+
subject.foobar.should == :baz
|
19
|
+
|
20
|
+
RR.reset
|
21
|
+
|
22
|
+
subject.to_s.should_not == "Subject is stubbed"
|
23
|
+
class_called = false
|
24
|
+
subject.class.should == subject_class
|
25
|
+
class_called.should == false
|
26
|
+
subject.should_not respond_to(:baz)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when passed a Hash" do
|
31
|
+
it "stubs methods (key) with the value on instances instantiated before the Double expection was created" do
|
32
|
+
subject_class = Class.new
|
33
|
+
subject = subject_class.new
|
34
|
+
subject.should_not respond_to(:baz)
|
35
|
+
|
36
|
+
any_instance_of(subject_class, :to_s => "Subject is stubbed", :foobar => lambda {:baz})
|
37
|
+
|
38
|
+
subject.to_s.should == "Subject is stubbed"
|
39
|
+
subject.foobar.should == :baz
|
40
|
+
|
41
|
+
RR.reset
|
42
|
+
|
43
|
+
subject.to_s.should_not == "Subject is stubbed"
|
44
|
+
subject.should_not respond_to(:baz)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/api/mock/mock_spec.rb
CHANGED
@@ -169,10 +169,10 @@ describe "mock" do
|
|
169
169
|
SampleClass1.hello.should == "hola!"
|
170
170
|
end
|
171
171
|
|
172
|
-
it "
|
172
|
+
it "does not override subclasses" do
|
173
173
|
mock(SampleClass1).hello { "hi!" }
|
174
174
|
|
175
|
-
SampleClass2.hello.should == "
|
175
|
+
SampleClass2.hello.should == "hello!"
|
176
176
|
end
|
177
177
|
|
178
178
|
it "should not get affected from a previous example" do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
describe "instance_of" do
|
4
|
+
it "applies to instances instantiated before the Double expection was created" do
|
5
|
+
subject_class = Class.new
|
6
|
+
existing_subject = subject_class.new
|
7
|
+
stub.instance_of(subject_class) do |o|
|
8
|
+
o.to_s {"Subject is stubbed"}
|
9
|
+
end
|
10
|
+
new_subject = subject_class.new
|
11
|
+
|
12
|
+
existing_subject.to_s.should_not == "Subject is stubbed"
|
13
|
+
new_subject.to_s.should == "Subject is stubbed"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
describe "new_instance_of" do
|
4
|
+
context "when passed a method chain" do
|
5
|
+
it "stubs the called method name with the given value" do
|
6
|
+
subject_class = Class.new
|
7
|
+
existing_subject = subject_class.new
|
8
|
+
new_instance_of(subject_class).foobar {:baz}
|
9
|
+
|
10
|
+
subject_new = subject_class.new
|
11
|
+
existing_subject.should_not respond_to(:foobar)
|
12
|
+
subject_new.foobar.should == :baz
|
13
|
+
|
14
|
+
subject_allocate = subject_class.allocate
|
15
|
+
existing_subject.should_not respond_to(:foobar)
|
16
|
+
subject_allocate.foobar.should == :baz
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when passed a block" do
|
21
|
+
it "applies to instances instantiated before the Double expection was created" do
|
22
|
+
subject_class = Class.new
|
23
|
+
existing_subject = subject_class.new
|
24
|
+
class_called = false
|
25
|
+
new_instance_of(subject_class) do |o|
|
26
|
+
stub(o).to_s {"Subject is stubbed"}
|
27
|
+
stub.proxy(o).class {|klass| class_called = true; klass}
|
28
|
+
end
|
29
|
+
|
30
|
+
existing_subject.to_s.should_not == "Subject is stubbed"
|
31
|
+
|
32
|
+
subject_new = subject_class.new
|
33
|
+
subject_new.to_s.should == "Subject is stubbed"
|
34
|
+
subject_new.class.should == subject_class
|
35
|
+
class_called.should be_true
|
36
|
+
|
37
|
+
subject_allocate = subject_class.allocate
|
38
|
+
subject_allocate.to_s.should == "Subject is stubbed"
|
39
|
+
subject_allocate.class.should == subject_class
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when passed a Hash" do
|
44
|
+
it "stubs methods (key) with the value on instances instantiated before the Double expection was created" do
|
45
|
+
subject_class = Class.new
|
46
|
+
existing_subject = subject_class.new
|
47
|
+
new_instance_of(subject_class, :to_s => "Subject is stubbed", :foobar => lambda {:baz})
|
48
|
+
|
49
|
+
existing_subject.to_s.should_not == "Subject is stubbed"
|
50
|
+
existing_subject.should_not respond_to(:foobar)
|
51
|
+
|
52
|
+
subject_new = subject_class.new
|
53
|
+
subject_new.to_s.should == "Subject is stubbed"
|
54
|
+
subject_new.foobar.should == :baz
|
55
|
+
|
56
|
+
subject_allocate = subject_class.allocate
|
57
|
+
subject_allocate.to_s.should == "Subject is stubbed"
|
58
|
+
subject_allocate.foobar.should == :baz
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -20,7 +20,7 @@ module RR
|
|
20
20
|
|
21
21
|
describe "#rr_verify" do
|
22
22
|
it "verifies and deletes the double_injections" do
|
23
|
-
double_1 = Injections::DoubleInjection.
|
23
|
+
double_1 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_1, method_name)
|
24
24
|
double_1_verify_calls = 0
|
25
25
|
double_1_reset_calls = 0
|
26
26
|
(
|
@@ -34,13 +34,10 @@ module RR
|
|
34
34
|
double_1_reset_calls += 1
|
35
35
|
end
|
36
36
|
end
|
37
|
-
double_2 = Injections::DoubleInjection.
|
37
|
+
double_2 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_2, method_name)
|
38
38
|
double_2_verify_calls = 0
|
39
39
|
double_2_reset_calls = 0
|
40
|
-
(
|
41
|
-
class << double_2;
|
42
|
-
self;
|
43
|
-
end).class_eval do
|
40
|
+
( class << double_2; self; end).class_eval do
|
44
41
|
define_method(:verify) do ||
|
45
42
|
double_2_verify_calls += 1
|
46
43
|
end
|
@@ -68,21 +65,22 @@ module RR
|
|
68
65
|
mock(subject_1).foobar1.ordered
|
69
66
|
mock(subject_2).foobar2.ordered
|
70
67
|
|
71
|
-
Injections::DoubleInjection.instances.should_not be_empty
|
68
|
+
::RR::Injections::DoubleInjection.instances.should_not be_empty
|
72
69
|
|
73
70
|
rr_reset
|
74
|
-
Injections::DoubleInjection.instances
|
71
|
+
::RR::Injections::DoubleInjection.instances
|
72
|
+
::RR::Injections::DoubleInjection.instances.should be_empty
|
75
73
|
end
|
76
74
|
|
77
75
|
it "resets all double_injections" do
|
78
|
-
double_1 = Injections::DoubleInjection.
|
76
|
+
double_1 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_1, method_name)
|
79
77
|
double_1_reset_calls = 0
|
80
78
|
( class << double_1; self; end).class_eval do
|
81
79
|
define_method(:reset) do ||
|
82
80
|
double_1_reset_calls += 1
|
83
81
|
end
|
84
82
|
end
|
85
|
-
double_2 = Injections::DoubleInjection.
|
83
|
+
double_2 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_2, method_name)
|
86
84
|
double_2_reset_calls = 0
|
87
85
|
( class << double_2; self; end).class_eval do
|
88
86
|
define_method(:reset) do ||
|
@@ -51,7 +51,9 @@ module RR
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "passes the self into the block" do
|
54
|
-
passed_in_argument.__double_definition_create__.should be_instance_of(
|
54
|
+
passed_in_argument.__double_definition_create__.should be_instance_of(
|
55
|
+
::RR::DoubleDefinitions::DoubleDefinitionCreate
|
56
|
+
)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -77,7 +79,9 @@ module RR
|
|
77
79
|
end
|
78
80
|
|
79
81
|
it "evaluates the block with the context of self" do
|
80
|
-
self_value.__double_definition_create__.should be_instance_of(
|
82
|
+
self_value.__double_definition_create__.should be_instance_of(
|
83
|
+
::RR::DoubleDefinitions::DoubleDefinitionCreate
|
84
|
+
)
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
@@ -43,15 +43,6 @@ module RR
|
|
43
43
|
subject.foobar.should == :baz
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
47
|
-
context "when already using an ImplementationStrategy" do
|
48
|
-
it "raises a DoubleDefinitionError" do
|
49
|
-
double_definition_create.mock
|
50
|
-
lambda do
|
51
|
-
call_strategy
|
52
|
-
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double already has a mock strategy")
|
53
|
-
end
|
54
|
-
end
|
55
46
|
end
|
56
47
|
|
57
48
|
describe "#stub" do
|
@@ -73,15 +64,6 @@ module RR
|
|
73
64
|
subject.foobar.should == :baz
|
74
65
|
end
|
75
66
|
end
|
76
|
-
|
77
|
-
context "when already using an ImplementationStrategy" do
|
78
|
-
it "raises a DoubleDefinitionError" do
|
79
|
-
double_definition_create.mock
|
80
|
-
lambda do
|
81
|
-
call_strategy
|
82
|
-
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double already has a mock strategy")
|
83
|
-
end
|
84
|
-
end
|
85
67
|
end
|
86
68
|
|
87
69
|
describe "#dont_allow" do
|
@@ -95,13 +77,6 @@ module RR
|
|
95
77
|
end
|
96
78
|
end
|
97
79
|
|
98
|
-
it "raises error when proxied" do
|
99
|
-
double_definition_create.proxy
|
100
|
-
lambda do
|
101
|
-
double_definition_create.dont_allow
|
102
|
-
end.should raise_error(RR::Errors::DoubleDefinitionError, "Doubles cannot be proxied when using dont_allow strategy")
|
103
|
-
end
|
104
|
-
|
105
80
|
context "when passed a subject and a method_name argument_expectation" do
|
106
81
|
it "creates a mock Double for method" do
|
107
82
|
double_definition = double_definition_create.dont_allow(subject, :foobar)
|
@@ -114,15 +89,6 @@ module RR
|
|
114
89
|
RR.reset
|
115
90
|
end
|
116
91
|
end
|
117
|
-
|
118
|
-
context "when already using an ImplementationStrategy" do
|
119
|
-
it "raises a DoubleDefinitionError" do
|
120
|
-
double_definition_create.mock
|
121
|
-
lambda do
|
122
|
-
call_strategy
|
123
|
-
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double already has a mock strategy")
|
124
|
-
end
|
125
|
-
end
|
126
92
|
end
|
127
93
|
end
|
128
94
|
|
@@ -182,15 +148,6 @@ module RR
|
|
182
148
|
end
|
183
149
|
end
|
184
150
|
|
185
|
-
context "when already using Strategies::Verification::DontAllow" do
|
186
|
-
it "raises error" do
|
187
|
-
double_definition_create.dont_allow
|
188
|
-
lambda do
|
189
|
-
double_definition_create.proxy
|
190
|
-
end.should raise_error(RR::Errors::DoubleDefinitionError, "Doubles cannot be proxied when using dont_allow strategy")
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
151
|
context "when passed a method_name argument" do
|
195
152
|
it "creates a proxy Double for method" do
|
196
153
|
double_definition = double_definition_create.stub.proxy(subject, :foobar).after_call {:baz}
|
@@ -205,7 +162,7 @@ module RR
|
|
205
162
|
context "when not passed a class" do
|
206
163
|
it "raises an ArgumentError" do
|
207
164
|
lambda do
|
208
|
-
double_definition_create.instance_of(Object.new)
|
165
|
+
double_definition_create.instance_of(Object.new).foobar
|
209
166
|
end.should raise_error(ArgumentError, "instance_of only accepts class objects")
|
210
167
|
end
|
211
168
|
end
|
@@ -248,14 +205,6 @@ module RR
|
|
248
205
|
|
249
206
|
describe "StrategyExecutionMethods" do
|
250
207
|
describe "#create" do
|
251
|
-
context "when #verification_strategy is not set" do
|
252
|
-
it "raises a DoubleDefinitionError" do
|
253
|
-
lambda do
|
254
|
-
double_definition_create.call(:foobar, 1, 2)
|
255
|
-
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double has no strategy")
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
208
|
context "when #verification_strategy is a Mock" do
|
260
209
|
context "when #implementation_strategy is a Reimplementation" do
|
261
210
|
before do
|
@@ -9,7 +9,7 @@ module RR
|
|
9
9
|
@subject = Object.new
|
10
10
|
@method_name = :foobar
|
11
11
|
subject.methods.should_not include(method_name.to_s)
|
12
|
-
@double_injection = Injections::DoubleInjection.
|
12
|
+
@double_injection = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject, method_name)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "verifies each double was met" do
|
@@ -15,10 +15,10 @@ module RR
|
|
15
15
|
|
16
16
|
it "resets the double_injections" do
|
17
17
|
stub(subject).foobar
|
18
|
-
Injections::DoubleInjection.instances.should_not be_empty
|
18
|
+
::RR::Injections::DoubleInjection.instances.should_not be_empty
|
19
19
|
|
20
20
|
fixture.setup_mocks_for_rspec
|
21
|
-
Injections::DoubleInjection.instances.should be_empty
|
21
|
+
::RR::Injections::DoubleInjection.instances.should be_empty
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -37,7 +37,7 @@ module RR
|
|
37
37
|
lambda do
|
38
38
|
fixture.verify_mocks_for_rspec
|
39
39
|
end.should raise_error(::RR::Errors::TimesCalledError)
|
40
|
-
Injections::DoubleInjection.instances.should be_empty
|
40
|
+
::RR::Injections::DoubleInjection.instances.should be_empty
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -52,10 +52,10 @@ module RR
|
|
52
52
|
|
53
53
|
it "resets the double_injections" do
|
54
54
|
stub(subject).foobar
|
55
|
-
Injections::DoubleInjection.instances.should_not be_empty
|
55
|
+
::RR::Injections::DoubleInjection.instances.should_not be_empty
|
56
56
|
|
57
57
|
fixture.teardown_mocks_for_rspec
|
58
|
-
Injections::DoubleInjection.instances.should be_empty
|
58
|
+
::RR::Injections::DoubleInjection.instances.should be_empty
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/spec/rr/space/space_spec.rb
CHANGED
@@ -26,8 +26,8 @@ module RR
|
|
26
26
|
(subject_1 === subject_2).should be_true
|
27
27
|
subject_1.__id__.should_not == subject_2.__id__
|
28
28
|
|
29
|
-
injection_1 = Injections::DoubleInjection.
|
30
|
-
injection_2 = Injections::DoubleInjection.
|
29
|
+
injection_1 = Injections::DoubleInjection.find_or_create_by_subject(subject_1, :foobar)
|
30
|
+
injection_2 = Injections::DoubleInjection.find_or_create_by_subject(subject_2, :foobar)
|
31
31
|
|
32
32
|
injection_1.should_not == injection_2
|
33
33
|
end
|
@@ -44,25 +44,25 @@ module RR
|
|
44
44
|
|
45
45
|
context "when method_name is a symbol" do
|
46
46
|
it "returns double_injection and adds double_injection to double_injection list" do
|
47
|
-
double_injection = Injections::DoubleInjection.
|
48
|
-
Injections::DoubleInjection.
|
49
|
-
double_injection.
|
47
|
+
double_injection = Injections::DoubleInjection.find_or_create_by_subject(subject, method_name)
|
48
|
+
Injections::DoubleInjection.find_or_create_by_subject(subject, method_name).should === double_injection
|
49
|
+
double_injection.subject_class.should == (class << subject; self; end)
|
50
50
|
double_injection.method_name.should === method_name
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
context "when method_name is a string" do
|
55
55
|
it "returns double_injection and adds double_injection to double_injection list" do
|
56
|
-
double_injection = Injections::DoubleInjection.
|
57
|
-
Injections::DoubleInjection.
|
58
|
-
double_injection.
|
56
|
+
double_injection = Injections::DoubleInjection.find_or_create_by_subject(subject, 'foobar')
|
57
|
+
Injections::DoubleInjection.find_or_create_by_subject(subject, method_name).should === double_injection
|
58
|
+
double_injection.subject_class.should == (class << subject; self; end)
|
59
59
|
double_injection.method_name.should === method_name
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
it "overrides the method when passing a block" do
|
64
64
|
original_method = subject.method(:foobar)
|
65
|
-
Injections::DoubleInjection.
|
65
|
+
Injections::DoubleInjection.find_or_create_by_subject(subject, method_name)
|
66
66
|
subject.method(:foobar).should_not == original_method
|
67
67
|
end
|
68
68
|
end
|
@@ -78,11 +78,11 @@ module RR
|
|
78
78
|
|
79
79
|
context "when a DoubleInjection is registered for the subject and method_name" do
|
80
80
|
it "returns the existing DoubleInjection" do
|
81
|
-
@double_injection = Injections::DoubleInjection.
|
81
|
+
@double_injection = Injections::DoubleInjection.find_or_create_by_subject(subject, 'foobar')
|
82
82
|
|
83
83
|
double_injection.subject_has_original_method?.should be_true
|
84
84
|
|
85
|
-
Injections::DoubleInjection.
|
85
|
+
Injections::DoubleInjection.find_or_create_by_subject(subject, 'foobar').should === double_injection
|
86
86
|
|
87
87
|
double_injection.reset
|
88
88
|
subject.foobar.should == :original_foobar
|
@@ -99,8 +99,8 @@ module RR
|
|
99
99
|
(subject_1 === subject_2).should be_true
|
100
100
|
subject_1.__id__.should_not == subject_2.__id__
|
101
101
|
|
102
|
-
injection_1 = Injections::MethodMissingInjection.
|
103
|
-
injection_2 = Injections::MethodMissingInjection.
|
102
|
+
injection_1 = Injections::MethodMissingInjection.find_or_create(class << subject_1; self; end)
|
103
|
+
injection_2 = Injections::MethodMissingInjection.find_or_create(class << subject_2; self; end)
|
104
104
|
|
105
105
|
injection_1.should_not == injection_2
|
106
106
|
end
|
@@ -115,7 +115,7 @@ module RR
|
|
115
115
|
|
116
116
|
it "overrides the method when passing a block" do
|
117
117
|
original_method = subject.method(:method_missing)
|
118
|
-
Injections::MethodMissingInjection.
|
118
|
+
Injections::MethodMissingInjection.find_or_create(class << subject; self; end)
|
119
119
|
subject.method(:method_missing).should_not == original_method
|
120
120
|
end
|
121
121
|
end
|
@@ -129,10 +129,10 @@ module RR
|
|
129
129
|
|
130
130
|
context "when a DoubleInjection is registered for the subject and method_name" do
|
131
131
|
it "returns the existing DoubleInjection" do
|
132
|
-
injection = Injections::MethodMissingInjection.
|
132
|
+
injection = Injections::MethodMissingInjection.find_or_create(class << subject; self; end)
|
133
133
|
injection.subject_has_original_method?.should be_true
|
134
134
|
|
135
|
-
Injections::MethodMissingInjection.
|
135
|
+
Injections::MethodMissingInjection.find_or_create(class << subject; self; end).should === injection
|
136
136
|
|
137
137
|
injection.reset
|
138
138
|
subject.method_missing(:foobar).should == :original_method_missing
|
@@ -149,8 +149,8 @@ module RR
|
|
149
149
|
(subject_1 === subject_2).should be_true
|
150
150
|
subject_1.__id__.should_not == subject_2.__id__
|
151
151
|
|
152
|
-
injection_1 = Injections::SingletonMethodAddedInjection.
|
153
|
-
injection_2 = Injections::SingletonMethodAddedInjection.
|
152
|
+
injection_1 = Injections::SingletonMethodAddedInjection.find_or_create(class << subject_1; self; end)
|
153
|
+
injection_2 = Injections::SingletonMethodAddedInjection.find_or_create(class << subject_2; self; end)
|
154
154
|
|
155
155
|
injection_1.should_not == injection_2
|
156
156
|
end
|
@@ -165,7 +165,7 @@ module RR
|
|
165
165
|
|
166
166
|
it "overrides the method when passing a block" do
|
167
167
|
original_method = subject.method(:singleton_method_added)
|
168
|
-
Injections::SingletonMethodAddedInjection.
|
168
|
+
Injections::SingletonMethodAddedInjection.find_or_create(class << subject; self; end)
|
169
169
|
subject.method(:singleton_method_added).should_not == original_method
|
170
170
|
end
|
171
171
|
end
|
@@ -179,10 +179,10 @@ module RR
|
|
179
179
|
|
180
180
|
context "when a DoubleInjection is registered for the subject and method_name" do
|
181
181
|
it "returns the existing DoubleInjection" do
|
182
|
-
injection = Injections::SingletonMethodAddedInjection.
|
182
|
+
injection = Injections::SingletonMethodAddedInjection.find_or_create(class << subject; self; end)
|
183
183
|
injection.subject_has_original_method?.should be_true
|
184
184
|
|
185
|
-
Injections::SingletonMethodAddedInjection.
|
185
|
+
Injections::SingletonMethodAddedInjection.find_or_create(class << subject; self; end).should === injection
|
186
186
|
|
187
187
|
injection.reset
|
188
188
|
subject.singleton_method_added(:foobar).should == :original_singleton_method_added
|
@@ -221,12 +221,12 @@ module RR
|
|
221
221
|
subject_1.respond_to?(method_name).should be_false
|
222
222
|
subject_2.respond_to?(method_name).should be_false
|
223
223
|
|
224
|
-
Injections::DoubleInjection.
|
225
|
-
Injections::DoubleInjection.
|
224
|
+
Injections::DoubleInjection.find_or_create_by_subject(subject_1, method_name)
|
225
|
+
Injections::DoubleInjection.exists_by_subject?(subject_1, method_name).should be_true
|
226
226
|
subject_1.respond_to?(method_name).should be_true
|
227
227
|
|
228
|
-
Injections::DoubleInjection.
|
229
|
-
Injections::DoubleInjection.
|
228
|
+
Injections::DoubleInjection.find_or_create_by_subject(subject_2, method_name)
|
229
|
+
Injections::DoubleInjection.exists_by_subject?(subject_2, method_name).should be_true
|
230
230
|
subject_2.respond_to?(method_name).should be_true
|
231
231
|
|
232
232
|
space.reset
|
@@ -242,12 +242,12 @@ module RR
|
|
242
242
|
subject_1.respond_to?(:method_missing).should be_false
|
243
243
|
subject_2.respond_to?(:method_missing).should be_false
|
244
244
|
|
245
|
-
Injections::MethodMissingInjection.
|
246
|
-
Injections::MethodMissingInjection.exists?(subject_1).should be_true
|
245
|
+
Injections::MethodMissingInjection.find_or_create(class << subject_1; self; end)
|
246
|
+
Injections::MethodMissingInjection.exists?(class << subject_1; self; end).should be_true
|
247
247
|
subject_1.respond_to?(:method_missing).should be_true
|
248
248
|
|
249
|
-
Injections::MethodMissingInjection.
|
250
|
-
Injections::MethodMissingInjection.exists?(subject_2).should be_true
|
249
|
+
Injections::MethodMissingInjection.find_or_create(class << subject_2; self; end)
|
250
|
+
Injections::MethodMissingInjection.exists?(class << subject_2; self; end).should be_true
|
251
251
|
subject_2.respond_to?(:method_missing).should be_true
|
252
252
|
|
253
253
|
space.reset
|
@@ -263,12 +263,12 @@ module RR
|
|
263
263
|
subject_1.respond_to?(:singleton_method_added).should be_false
|
264
264
|
subject_2.respond_to?(:singleton_method_added).should be_false
|
265
265
|
|
266
|
-
Injections::SingletonMethodAddedInjection.
|
267
|
-
Injections::SingletonMethodAddedInjection.exists?(subject_1).should be_true
|
266
|
+
Injections::SingletonMethodAddedInjection.find_or_create(class << subject_1; self; end)
|
267
|
+
Injections::SingletonMethodAddedInjection.exists?(class << subject_1; self; end).should be_true
|
268
268
|
subject_1.respond_to?(:singleton_method_added).should be_true
|
269
269
|
|
270
|
-
Injections::SingletonMethodAddedInjection.
|
271
|
-
Injections::SingletonMethodAddedInjection.exists?(subject_2).should be_true
|
270
|
+
Injections::SingletonMethodAddedInjection.find_or_create(class << subject_2; self; end)
|
271
|
+
Injections::SingletonMethodAddedInjection.exists?(class << subject_2; self; end).should be_true
|
272
272
|
subject_2.respond_to?(:singleton_method_added).should be_true
|
273
273
|
|
274
274
|
space.reset
|
@@ -292,9 +292,9 @@ module RR
|
|
292
292
|
it "resets the double_injections and restores the original method" do
|
293
293
|
original_method = subject.method(method_name)
|
294
294
|
|
295
|
-
@double_injection = Injections::DoubleInjection.
|
296
|
-
Injections::DoubleInjection.instances.keys.should include(subject)
|
297
|
-
Injections::DoubleInjection.
|
295
|
+
@double_injection = Injections::DoubleInjection.find_or_create_by_subject(subject, method_name)
|
296
|
+
Injections::DoubleInjection.instances.keys.should include(class << subject; self; end)
|
297
|
+
Injections::DoubleInjection.find_by_subject(subject, method_name).should_not be_nil
|
298
298
|
subject.method(method_name).should_not == original_method
|
299
299
|
|
300
300
|
space.reset_double(subject, method_name)
|
@@ -304,17 +304,17 @@ module RR
|
|
304
304
|
|
305
305
|
context "when it has no double_injections" do
|
306
306
|
it "removes the subject from the double_injections map" do
|
307
|
-
double_1 = Injections::DoubleInjection.
|
308
|
-
double_2 = Injections::DoubleInjection.
|
307
|
+
double_1 = Injections::DoubleInjection.find_or_create_by_subject(subject, :foobar1)
|
308
|
+
double_2 = Injections::DoubleInjection.find_or_create_by_subject(subject, :foobar2)
|
309
309
|
|
310
|
-
Injections::DoubleInjection.instances.include?(subject).should == true
|
311
|
-
Injections::DoubleInjection.
|
312
|
-
Injections::DoubleInjection.
|
310
|
+
Injections::DoubleInjection.instances.include?(class << subject; self; end).should == true
|
311
|
+
Injections::DoubleInjection.find_by_subject(subject, :foobar1).should_not be_nil
|
312
|
+
Injections::DoubleInjection.find_by_subject(subject, :foobar2).should_not be_nil
|
313
313
|
|
314
314
|
space.reset_double(subject, :foobar1)
|
315
|
-
Injections::DoubleInjection.instances.include?(subject).should == true
|
316
|
-
Injections::DoubleInjection.
|
317
|
-
Injections::DoubleInjection.
|
315
|
+
Injections::DoubleInjection.instances.include?(class << subject; self; end).should == true
|
316
|
+
Injections::DoubleInjection.find_by_subject(subject, :foobar1).should be_nil
|
317
|
+
Injections::DoubleInjection.find_by_subject(subject, :foobar2).should_not be_nil
|
318
318
|
|
319
319
|
space.reset_double(subject, :foobar2)
|
320
320
|
Injections::DoubleInjection.instances.include?(subject).should == false
|
@@ -331,14 +331,14 @@ module RR
|
|
331
331
|
end
|
332
332
|
|
333
333
|
it "resets the double_injection and removes it from the double_injections list" do
|
334
|
-
double_injection_1 = Injections::DoubleInjection.
|
334
|
+
double_injection_1 = Injections::DoubleInjection.find_or_create_by_subject(subject_1, method_name)
|
335
335
|
double_1_reset_call_count = 0
|
336
336
|
( class << double_injection_1; self; end).class_eval do
|
337
337
|
define_method(:reset) do
|
338
338
|
double_1_reset_call_count += 1
|
339
339
|
end
|
340
340
|
end
|
341
|
-
double_injection_2 = Injections::DoubleInjection.
|
341
|
+
double_injection_2 = Injections::DoubleInjection.find_or_create_by_subject(subject_2, method_name)
|
342
342
|
double_2_reset_call_count = 0
|
343
343
|
( class << double_injection_2; self; end).class_eval do
|
344
344
|
define_method(:reset) do
|
@@ -359,9 +359,9 @@ module RR
|
|
359
359
|
@subject_2 = Object.new
|
360
360
|
@subject3 = Object.new
|
361
361
|
@method_name = :foobar
|
362
|
-
@double_1 = Injections::DoubleInjection.
|
363
|
-
@double_2 = Injections::DoubleInjection.
|
364
|
-
@double3 = Injections::DoubleInjection.
|
362
|
+
@double_1 = Injections::DoubleInjection.find_or_create_by_subject(subject_1, method_name)
|
363
|
+
@double_2 = Injections::DoubleInjection.find_or_create_by_subject(subject_2, method_name)
|
364
|
+
@double3 = Injections::DoubleInjection.find_or_create_by_subject(subject3, method_name)
|
365
365
|
end
|
366
366
|
|
367
367
|
context "when passed no arguments" do
|
@@ -445,10 +445,7 @@ module RR
|
|
445
445
|
it "verifies the Doubles injected into all of the Objects" do
|
446
446
|
double_1_verify_call_count = 0
|
447
447
|
double_1_reset_call_count = 0
|
448
|
-
(
|
449
|
-
class << double_1;
|
450
|
-
self;
|
451
|
-
end).class_eval do
|
448
|
+
( class << double_1; self; end).class_eval do
|
452
449
|
define_method(:verify) do
|
453
450
|
double_1_verify_call_count += 1
|
454
451
|
end
|
@@ -459,10 +456,7 @@ module RR
|
|
459
456
|
|
460
457
|
double_2_verify_call_count = 0
|
461
458
|
double_2_reset_call_count = 0
|
462
|
-
(
|
463
|
-
class << double_2;
|
464
|
-
self;
|
465
|
-
end).class_eval do
|
459
|
+
( class << double_2; self; end).class_eval do
|
466
460
|
define_method(:verify) do
|
467
461
|
double_2_verify_call_count += 1
|
468
462
|
end
|
@@ -473,10 +467,7 @@ module RR
|
|
473
467
|
|
474
468
|
double3_verify_call_count = 0
|
475
469
|
double3_reset_call_count = 0
|
476
|
-
(
|
477
|
-
class << double3;
|
478
|
-
self;
|
479
|
-
end).class_eval do
|
470
|
+
( class << double3; self; end).class_eval do
|
480
471
|
define_method(:verify) do
|
481
472
|
double3_verify_call_count += 1
|
482
473
|
end
|
@@ -553,8 +544,8 @@ module RR
|
|
553
544
|
end
|
554
545
|
|
555
546
|
it "verifies and deletes the double_injection" do
|
556
|
-
@double_injection = Injections::DoubleInjection.
|
557
|
-
Injections::DoubleInjection.
|
547
|
+
@double_injection = Injections::DoubleInjection.find_or_create_by_subject(subject, method_name)
|
548
|
+
Injections::DoubleInjection.find_by_subject(subject, method_name).should === double_injection
|
558
549
|
|
559
550
|
verify_call_count = 0
|
560
551
|
( class << double_injection; self; end).class_eval do
|
@@ -565,17 +556,17 @@ module RR
|
|
565
556
|
space.verify_double(subject, method_name)
|
566
557
|
verify_call_count.should == 1
|
567
558
|
|
568
|
-
Injections::DoubleInjection.
|
559
|
+
Injections::DoubleInjection.find(subject, method_name).should be_nil
|
569
560
|
end
|
570
561
|
|
571
562
|
context "when verifying the double_injection raises an error" do
|
572
563
|
it "deletes the double_injection and restores the original method" do
|
573
564
|
original_method = subject.method(method_name)
|
574
565
|
|
575
|
-
@double_injection = Injections::DoubleInjection.
|
566
|
+
@double_injection = Injections::DoubleInjection.find_or_create_by_subject(subject, method_name)
|
576
567
|
subject.method(method_name).should_not == original_method
|
577
568
|
|
578
|
-
Injections::DoubleInjection.
|
569
|
+
Injections::DoubleInjection.find_by_subject(subject, method_name).should === double_injection
|
579
570
|
|
580
571
|
verify_called = true
|
581
572
|
( class << double_injection; self; end).class_eval do
|
@@ -587,7 +578,7 @@ module RR
|
|
587
578
|
lambda {space.verify_double(subject, method_name)}.should raise_error
|
588
579
|
verify_called.should be_true
|
589
580
|
|
590
|
-
Injections::DoubleInjection.
|
581
|
+
Injections::DoubleInjection.find(subject, method_name).should be_nil
|
591
582
|
subject.method(method_name).should == original_method
|
592
583
|
end
|
593
584
|
end
|