rr 0.10.10 → 0.10.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/VERSION.yml +1 -1
- data/lib/rr.rb +5 -3
- data/lib/rr/adapters/rr_methods.rb +5 -5
- data/lib/rr/blank_slate.rb +17 -0
- data/lib/rr/double_definitions/{child_double_definition_creator.rb → child_double_definition_create.rb} +1 -1
- data/lib/rr/double_definitions/double_definition.rb +13 -11
- data/lib/rr/double_definitions/{double_definition_creator.rb → double_definition_create.rb} +52 -43
- data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +2 -2
- data/lib/rr/double_definitions/strategies/scope/instance.rb +1 -1
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +6 -6
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +2 -2
- data/lib/rr/double_definitions/strategies/strategy.rb +15 -16
- data/lib/rr/double_definitions/strategies/verification/mock.rb +1 -1
- data/lib/rr/double_definitions/strategies/verification/stub.rb +1 -1
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +2 -2
- data/lib/rr/injections/double_injection.rb +59 -4
- data/lib/rr/injections/injection.rb +6 -0
- data/lib/rr/injections/method_missing_injection.rb +13 -1
- data/lib/rr/injections/singleton_method_added_injection.rb +14 -3
- data/lib/rr/method_dispatches/base_method_dispatch.rb +2 -2
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +2 -2
- data/lib/rr/recorded_calls.rb +1 -1
- data/lib/rr/space.rb +17 -68
- data/lib/rr/spy_verification_proxy.rb +1 -6
- data/spec/rr/adapters/rr_methods_creator_spec.rb +9 -21
- data/spec/rr/adapters/rr_methods_space_spec.rb +10 -25
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +16 -16
- data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +87 -0
- data/spec/rr/double_definitions/{double_definition_creator_spec.rb → double_definition_create_spec.rb} +64 -72
- data/spec/rr/double_injection/double_injection_verify_spec.rb +2 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +5 -29
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +7 -39
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +19 -47
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +1 -9
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +18 -64
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +7 -53
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +12 -56
- data/spec/rr/rspec/rspec_adapter_spec.rb +8 -11
- data/spec/rr/space/space_spec.rb +72 -212
- data/spec/spec_helper.rb +0 -76
- data/spec/spy_verification_spec.rb +1 -1
- metadata +8 -11
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +0 -37
- data/ruby_19_spec.rb +0 -12
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +0 -124
- data/spec/rr/double_definitions/double_definition_spec.rb +0 -1168
- data/spec/rr/double_spec.rb +0 -361
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +0 -38
@@ -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 =
|
23
|
+
double_1 = Injections::DoubleInjection.create(subject_1, method_name)
|
24
24
|
double_1_verify_calls = 0
|
25
25
|
double_1_reset_calls = 0
|
26
26
|
(
|
@@ -34,7 +34,7 @@ module RR
|
|
34
34
|
double_1_reset_calls += 1
|
35
35
|
end
|
36
36
|
end
|
37
|
-
double_2 =
|
37
|
+
double_2 = Injections::DoubleInjection.create(subject_2, method_name)
|
38
38
|
double_2_verify_calls = 0
|
39
39
|
double_2_reset_calls = 0
|
40
40
|
(
|
@@ -65,41 +65,26 @@ module RR
|
|
65
65
|
|
66
66
|
describe "#rr_reset" do
|
67
67
|
it "removes the ordered doubles" do
|
68
|
-
|
69
|
-
|
70
|
-
RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject_1)
|
71
|
-
)
|
72
|
-
double_2 = new_double(
|
73
|
-
space.double_injection(subject_2, :foobar2),
|
74
|
-
RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject_2)
|
75
|
-
)
|
68
|
+
mock(subject_1).foobar1.ordered
|
69
|
+
mock(subject_2).foobar2.ordered
|
76
70
|
|
77
|
-
|
78
|
-
double_2.definition.ordered
|
79
|
-
|
80
|
-
space.ordered_doubles.should_not be_empty
|
71
|
+
Injections::DoubleInjection.instances.should_not be_empty
|
81
72
|
|
82
73
|
rr_reset
|
83
|
-
|
74
|
+
Injections::DoubleInjection.instances.should be_empty
|
84
75
|
end
|
85
76
|
|
86
77
|
it "resets all double_injections" do
|
87
|
-
double_1 =
|
78
|
+
double_1 = Injections::DoubleInjection.create(subject_1, method_name)
|
88
79
|
double_1_reset_calls = 0
|
89
|
-
(
|
90
|
-
class << double_1;
|
91
|
-
self;
|
92
|
-
end).class_eval do
|
80
|
+
( class << double_1; self; end).class_eval do
|
93
81
|
define_method(:reset) do ||
|
94
82
|
double_1_reset_calls += 1
|
95
83
|
end
|
96
84
|
end
|
97
|
-
double_2 =
|
85
|
+
double_2 = Injections::DoubleInjection.create(subject_2, method_name)
|
98
86
|
double_2_reset_calls = 0
|
99
|
-
(
|
100
|
-
class << double_2;
|
101
|
-
self;
|
102
|
-
end).class_eval do
|
87
|
+
( class << double_2; self; end).class_eval do
|
103
88
|
define_method(:reset) do ||
|
104
89
|
double_2_reset_calls += 1
|
105
90
|
end
|
@@ -2,22 +2,22 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module DoubleDefinitions
|
5
|
-
describe
|
6
|
-
attr_reader :parent_subject, :
|
5
|
+
describe ChildDoubleDefinitionCreate do
|
6
|
+
attr_reader :parent_subject, :parent_double_definition_create, :parent_double_definition, :child_double_definition_create
|
7
7
|
it_should_behave_like "Swapped Space"
|
8
8
|
before(:each) do
|
9
9
|
@parent_subject = Object.new
|
10
|
-
@
|
11
|
-
@parent_double_definition = DoubleDefinition.new(
|
12
|
-
@
|
10
|
+
@parent_double_definition_create = DoubleDefinitionCreate.new
|
11
|
+
@parent_double_definition = DoubleDefinition.new(parent_double_definition_create)
|
12
|
+
@child_double_definition_create = ChildDoubleDefinitionCreate.new(parent_double_definition)
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#root_subject" do
|
16
16
|
it "returns the #parent_double_definition.root_subject" do
|
17
17
|
child_subject = Object.new
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
parent_double_definition_create.stub(parent_subject)
|
19
|
+
child_double_definition_create.stub(child_subject)
|
20
|
+
child_double_definition_create.root_subject.should == parent_subject
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -32,7 +32,7 @@ module RR
|
|
32
32
|
context "when passed a subject" do
|
33
33
|
it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
|
34
34
|
parent_double_definition.implementation.should be_nil
|
35
|
-
|
35
|
+
child_double_definition_create.mock(child_subject)
|
36
36
|
parent_double_definition.implementation.call.should == child_subject
|
37
37
|
end
|
38
38
|
end
|
@@ -42,7 +42,7 @@ module RR
|
|
42
42
|
context "when passed a subject" do
|
43
43
|
it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
|
44
44
|
parent_double_definition.implementation.should be_nil
|
45
|
-
|
45
|
+
child_double_definition_create.stub(child_subject)
|
46
46
|
parent_double_definition.implementation.call.should == child_subject
|
47
47
|
end
|
48
48
|
end
|
@@ -52,7 +52,7 @@ module RR
|
|
52
52
|
context "when passed a subject" do
|
53
53
|
it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
|
54
54
|
parent_double_definition.implementation.should be_nil
|
55
|
-
|
55
|
+
child_double_definition_create.dont_allow(child_subject)
|
56
56
|
parent_double_definition.implementation.call.should == child_subject
|
57
57
|
end
|
58
58
|
end
|
@@ -63,7 +63,7 @@ module RR
|
|
63
63
|
describe "#mock!" do
|
64
64
|
it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
|
65
65
|
parent_double_definition.implementation.should be_nil
|
66
|
-
child_subject =
|
66
|
+
child_subject = child_double_definition_create.mock!.__double_definition_create__.subject
|
67
67
|
parent_double_definition.implementation.call.should == child_subject
|
68
68
|
end
|
69
69
|
end
|
@@ -71,7 +71,7 @@ module RR
|
|
71
71
|
describe "#stub!" do
|
72
72
|
it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
|
73
73
|
parent_double_definition.implementation.should be_nil
|
74
|
-
child_subject =
|
74
|
+
child_subject = child_double_definition_create.stub!.__double_definition_create__.subject
|
75
75
|
parent_double_definition.implementation.call.should == child_subject
|
76
76
|
end
|
77
77
|
end
|
@@ -79,7 +79,7 @@ module RR
|
|
79
79
|
describe "#dont_allow!" do
|
80
80
|
it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
|
81
81
|
parent_double_definition.implementation.should be_nil
|
82
|
-
child_subject =
|
82
|
+
child_subject = child_double_definition_create.dont_allow!.__double_definition_create__.subject
|
83
83
|
parent_double_definition.implementation.call.should == child_subject
|
84
84
|
end
|
85
85
|
end
|
@@ -91,7 +91,7 @@ module RR
|
|
91
91
|
describe "#instance_of" do
|
92
92
|
it "raises a NoMethodError" do
|
93
93
|
lambda do
|
94
|
-
|
94
|
+
child_double_definition_create.instance_of
|
95
95
|
end.should raise_error(NoMethodError)
|
96
96
|
end
|
97
97
|
end
|
@@ -101,7 +101,7 @@ module RR
|
|
101
101
|
describe "#instance_of!" do
|
102
102
|
it "raises a NoMethodError" do
|
103
103
|
lambda do
|
104
|
-
|
104
|
+
child_double_definition_create.instance_of!
|
105
105
|
end.should raise_error(NoMethodError)
|
106
106
|
end
|
107
107
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module DoubleDefinitions
|
5
|
+
describe DoubleDefinitionCreateBlankSlate do
|
6
|
+
attr_reader :subject, :double_definition_create, :blank_slate
|
7
|
+
it_should_behave_like "Swapped Space"
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@subject = Object.new
|
11
|
+
@double_definition_create = DoubleDefinitionCreate.new
|
12
|
+
double_definition_create.mock(subject)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".new" do
|
16
|
+
it "does not undefine object_id" do
|
17
|
+
blank_slate = DoubleDefinitionCreateBlankSlate.new(double_definition_create)
|
18
|
+
blank_slate.object_id.class.should == Fixnum
|
19
|
+
end
|
20
|
+
|
21
|
+
context "without block" do
|
22
|
+
before do
|
23
|
+
@blank_slate = DoubleDefinitionCreateBlankSlate.new(double_definition_create)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "clears out all methods from proxy" do
|
27
|
+
stub(subject).i_should_be_a_double.should be_instance_of(DoubleDefinition)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when passed a block" do
|
32
|
+
context "when the block has an arity of 1" do
|
33
|
+
attr_reader :passed_in_argument
|
34
|
+
before do
|
35
|
+
passed_in_argument = nil
|
36
|
+
stub(subject) do |b|
|
37
|
+
passed_in_argument = b
|
38
|
+
b.foobar(1, 2) {:one_two}
|
39
|
+
b.foobar(1) {:one}
|
40
|
+
b.foobar.with_any_args {:default}
|
41
|
+
b.baz() {:baz_result}
|
42
|
+
end
|
43
|
+
@passed_in_argument = passed_in_argument
|
44
|
+
end
|
45
|
+
|
46
|
+
it "creates double_injections" do
|
47
|
+
subject.foobar(1, 2).should == :one_two
|
48
|
+
subject.foobar(1).should == :one
|
49
|
+
subject.foobar(:something).should == :default
|
50
|
+
subject.baz.should == :baz_result
|
51
|
+
end
|
52
|
+
|
53
|
+
it "passes the self into the block" do
|
54
|
+
passed_in_argument.__double_definition_create__.should be_instance_of(DoubleDefinitions::DoubleDefinitionCreate)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the block has an arity of 0" do
|
59
|
+
attr_reader :self_value
|
60
|
+
before do
|
61
|
+
self_value = nil
|
62
|
+
stub(subject) do ||
|
63
|
+
self_value = self
|
64
|
+
foobar(1, 2) {:one_two}
|
65
|
+
foobar(1) {:one}
|
66
|
+
foobar.with_any_args {:default}
|
67
|
+
baz() {:baz_result}
|
68
|
+
end
|
69
|
+
@self_value = self_value
|
70
|
+
end
|
71
|
+
|
72
|
+
it "creates double_injections" do
|
73
|
+
subject.foobar(1, 2).should == :one_two
|
74
|
+
subject.foobar(1).should == :one
|
75
|
+
subject.foobar(:something).should == :default
|
76
|
+
subject.baz.should == :baz_result
|
77
|
+
end
|
78
|
+
|
79
|
+
it "evaluates the block with the context of self" do
|
80
|
+
self_value.__double_definition_create__.should be_instance_of(DoubleDefinitions::DoubleDefinitionCreate)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -2,25 +2,25 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module DoubleDefinitions
|
5
|
-
describe
|
6
|
-
attr_reader :
|
5
|
+
describe DoubleDefinitionCreate do
|
6
|
+
attr_reader :double_definition_create, :subject, :strategy_method_name
|
7
7
|
it_should_behave_like "Swapped Space"
|
8
8
|
before(:each) do
|
9
9
|
@subject = Object.new
|
10
|
-
@
|
10
|
+
@double_definition_create = DoubleDefinitionCreate.new
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#root_subject" do
|
14
14
|
it "returns #subject" do
|
15
|
-
|
16
|
-
|
15
|
+
double_definition_create.stub(subject).foobar
|
16
|
+
double_definition_create.root_subject.should == subject
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "StrategySetupMethods" do
|
21
21
|
describe "normal strategy definitions" do
|
22
22
|
def call_strategy(*args, &block)
|
23
|
-
|
23
|
+
double_definition_create.__send__(strategy_method_name, *args, &block)
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "#mock" do
|
@@ -28,17 +28,15 @@ module RR
|
|
28
28
|
@strategy_method_name = :mock
|
29
29
|
end
|
30
30
|
|
31
|
-
send("normal strategy definition")
|
32
|
-
|
33
31
|
context "when passing no args" do
|
34
32
|
it "returns self" do
|
35
|
-
call_strategy.should ===
|
33
|
+
call_strategy.should === double_definition_create
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
context "when passed a subject and a method_name argument" do
|
40
38
|
it "creates a mock Double for method" do
|
41
|
-
double_definition =
|
39
|
+
double_definition = double_definition_create.mock(subject, :foobar).returns {:baz}
|
42
40
|
double_definition.times_matcher.should == RR::TimesCalledMatchers::IntegerMatcher.new(1)
|
43
41
|
double_definition.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
44
42
|
double_definition.argument_expectation.expected_arguments.should == []
|
@@ -48,7 +46,7 @@ module RR
|
|
48
46
|
|
49
47
|
context "when already using an ImplementationStrategy" do
|
50
48
|
it "raises a DoubleDefinitionError" do
|
51
|
-
|
49
|
+
double_definition_create.mock
|
52
50
|
lambda do
|
53
51
|
call_strategy
|
54
52
|
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double already has a mock strategy")
|
@@ -61,17 +59,15 @@ module RR
|
|
61
59
|
@strategy_method_name = :stub
|
62
60
|
end
|
63
61
|
|
64
|
-
send("normal strategy definition")
|
65
|
-
|
66
62
|
context "when passing no args" do
|
67
63
|
it "returns self" do
|
68
|
-
call_strategy.should ===
|
64
|
+
call_strategy.should === double_definition_create
|
69
65
|
end
|
70
66
|
end
|
71
67
|
|
72
68
|
context "when passed subject and a method_name argument" do
|
73
69
|
it "creates a stub Double for method when passed a method_name argument" do
|
74
|
-
double_definition =
|
70
|
+
double_definition = double_definition_create.stub(subject, :foobar).returns {:baz}
|
75
71
|
double_definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
|
76
72
|
double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
|
77
73
|
subject.foobar.should == :baz
|
@@ -80,7 +76,7 @@ module RR
|
|
80
76
|
|
81
77
|
context "when already using an ImplementationStrategy" do
|
82
78
|
it "raises a DoubleDefinitionError" do
|
83
|
-
|
79
|
+
double_definition_create.mock
|
84
80
|
lambda do
|
85
81
|
call_strategy
|
86
82
|
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double already has a mock strategy")
|
@@ -93,24 +89,22 @@ module RR
|
|
93
89
|
@strategy_method_name = :dont_allow
|
94
90
|
end
|
95
91
|
|
96
|
-
send("normal strategy definition")
|
97
|
-
|
98
92
|
context "when passing no args" do
|
99
93
|
it "returns self" do
|
100
|
-
call_strategy.should ===
|
94
|
+
call_strategy.should === double_definition_create
|
101
95
|
end
|
102
96
|
end
|
103
97
|
|
104
98
|
it "raises error when proxied" do
|
105
|
-
|
99
|
+
double_definition_create.proxy
|
106
100
|
lambda do
|
107
|
-
|
101
|
+
double_definition_create.dont_allow
|
108
102
|
end.should raise_error(RR::Errors::DoubleDefinitionError, "Doubles cannot be proxied when using dont_allow strategy")
|
109
103
|
end
|
110
104
|
|
111
105
|
context "when passed a subject and a method_name argument_expectation" do
|
112
106
|
it "creates a mock Double for method" do
|
113
|
-
double_definition =
|
107
|
+
double_definition = double_definition_create.dont_allow(subject, :foobar)
|
114
108
|
double_definition.times_matcher.should == RR::TimesCalledMatchers::NeverMatcher.new
|
115
109
|
double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
|
116
110
|
|
@@ -123,7 +117,7 @@ module RR
|
|
123
117
|
|
124
118
|
context "when already using an ImplementationStrategy" do
|
125
119
|
it "raises a DoubleDefinitionError" do
|
126
|
-
|
120
|
+
double_definition_create.mock
|
127
121
|
lambda do
|
128
122
|
call_strategy
|
129
123
|
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double already has a mock strategy")
|
@@ -135,7 +129,7 @@ module RR
|
|
135
129
|
describe "! strategy definitions" do
|
136
130
|
attr_reader :strategy_method_name
|
137
131
|
def call_strategy(*args, &definition_eval_block)
|
138
|
-
|
132
|
+
double_definition_create.__send__(strategy_method_name, *args, &definition_eval_block)
|
139
133
|
end
|
140
134
|
|
141
135
|
describe "#mock!" do
|
@@ -143,12 +137,11 @@ module RR
|
|
143
137
|
@strategy_method_name = :mock!
|
144
138
|
end
|
145
139
|
|
146
|
-
send("! strategy definition")
|
147
|
-
|
148
140
|
context "when passed a method_name argument" do
|
149
141
|
it "sets #verification_strategy to Mock" do
|
150
|
-
|
151
|
-
|
142
|
+
double_definition_create.mock!(:foobar)
|
143
|
+
double_definition_create.verification_strategy.class.should == Strategies::Verification::Mock
|
144
|
+
lambda {RR.verify}.should raise_error(::RR::Errors::TimesCalledError)
|
152
145
|
end
|
153
146
|
end
|
154
147
|
end
|
@@ -158,12 +151,10 @@ module RR
|
|
158
151
|
@strategy_method_name = :stub!
|
159
152
|
end
|
160
153
|
|
161
|
-
send("! strategy definition")
|
162
|
-
|
163
154
|
context "when passed a method_name argument" do
|
164
155
|
it "sets #verification_strategy to Stub" do
|
165
|
-
|
166
|
-
|
156
|
+
double_definition_create.stub!(:foobar)
|
157
|
+
double_definition_create.verification_strategy.class.should == Strategies::Verification::Stub
|
167
158
|
end
|
168
159
|
end
|
169
160
|
end
|
@@ -173,12 +164,10 @@ module RR
|
|
173
164
|
@strategy_method_name = :dont_allow!
|
174
165
|
end
|
175
166
|
|
176
|
-
send("! strategy definition")
|
177
|
-
|
178
167
|
context "when passed a method_name argument" do
|
179
168
|
it "sets #verification_strategy to DontAllow" do
|
180
|
-
|
181
|
-
|
169
|
+
double_definition_create.dont_allow!(:foobar)
|
170
|
+
double_definition_create.verification_strategy.class.should == Strategies::Verification::DontAllow
|
182
171
|
end
|
183
172
|
end
|
184
173
|
end
|
@@ -195,16 +184,16 @@ module RR
|
|
195
184
|
|
196
185
|
context "when already using Strategies::Verification::DontAllow" do
|
197
186
|
it "raises error" do
|
198
|
-
|
187
|
+
double_definition_create.dont_allow
|
199
188
|
lambda do
|
200
|
-
|
189
|
+
double_definition_create.proxy
|
201
190
|
end.should raise_error(RR::Errors::DoubleDefinitionError, "Doubles cannot be proxied when using dont_allow strategy")
|
202
191
|
end
|
203
192
|
end
|
204
193
|
|
205
194
|
context "when passed a method_name argument" do
|
206
195
|
it "creates a proxy Double for method" do
|
207
|
-
double_definition =
|
196
|
+
double_definition = double_definition_create.stub.proxy(subject, :foobar).after_call {:baz}
|
208
197
|
double_definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
|
209
198
|
double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
|
210
199
|
subject.foobar.should == :baz
|
@@ -216,7 +205,7 @@ module RR
|
|
216
205
|
context "when not passed a class" do
|
217
206
|
it "raises an ArgumentError" do
|
218
207
|
lambda do
|
219
|
-
|
208
|
+
double_definition_create.instance_of(Object.new)
|
220
209
|
end.should raise_error(ArgumentError, "instance_of only accepts class objects")
|
221
210
|
end
|
222
211
|
end
|
@@ -224,7 +213,7 @@ module RR
|
|
224
213
|
context "when passed a method_name argument" do
|
225
214
|
it "creates a proxy Double for method" do
|
226
215
|
klass = Class.new
|
227
|
-
double_definition =
|
216
|
+
double_definition = double_definition_create.stub.instance_of(klass, :foobar).returns {:baz}
|
228
217
|
double_definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
|
229
218
|
double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
|
230
219
|
klass.new.foobar.should == :baz
|
@@ -238,8 +227,8 @@ module RR
|
|
238
227
|
end
|
239
228
|
|
240
229
|
context "when passed no arguments" do
|
241
|
-
it "returns a
|
242
|
-
instance_of.instance_of.should be_instance_of(
|
230
|
+
it "returns a DoubleDefinitiondouble_definition_create" do
|
231
|
+
instance_of.instance_of.should be_instance_of(DoubleDefinitionCreate)
|
243
232
|
end
|
244
233
|
end
|
245
234
|
|
@@ -262,7 +251,7 @@ module RR
|
|
262
251
|
context "when #verification_strategy is not set" do
|
263
252
|
it "raises a DoubleDefinitionError" do
|
264
253
|
lambda do
|
265
|
-
|
254
|
+
double_definition_create.call(:foobar, 1, 2)
|
266
255
|
end.should raise_error(RR::Errors::DoubleDefinitionError, "This Double has no strategy")
|
267
256
|
end
|
268
257
|
end
|
@@ -270,18 +259,19 @@ module RR
|
|
270
259
|
context "when #verification_strategy is a Mock" do
|
271
260
|
context "when #implementation_strategy is a Reimplementation" do
|
272
261
|
before do
|
273
|
-
|
262
|
+
double_definition_create.mock(subject)
|
274
263
|
end
|
275
264
|
|
276
265
|
it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
|
277
|
-
|
266
|
+
mock(subject).foobar(1, 2)
|
278
267
|
subject.foobar(1, 2)
|
279
268
|
lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
|
269
|
+
lambda {RR.verify}.should raise_error(RR::Errors::TimesCalledError)
|
280
270
|
end
|
281
271
|
|
282
272
|
describe "#subject.method_name being called" do
|
283
273
|
it "returns the return value of the Double#returns block" do
|
284
|
-
|
274
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
285
275
|
subject.foobar(1, 2).should == :baz
|
286
276
|
end
|
287
277
|
end
|
@@ -289,17 +279,19 @@ module RR
|
|
289
279
|
|
290
280
|
context "when #implementation_strategy is a Proxy" do
|
291
281
|
before do
|
292
|
-
|
293
|
-
|
282
|
+
double_definition_create.mock
|
283
|
+
double_definition_create.proxy(subject)
|
294
284
|
end
|
295
285
|
|
296
286
|
it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
|
297
287
|
def subject.foobar(*args)
|
298
|
-
:baz
|
288
|
+
:baz
|
299
289
|
end
|
300
|
-
|
290
|
+
mock(subject).foobar(1, 2)
|
291
|
+
|
301
292
|
subject.foobar(1, 2)
|
302
293
|
lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
|
294
|
+
lambda {RR.verify}.should raise_error(RR::Errors::TimesCalledError)
|
303
295
|
end
|
304
296
|
|
305
297
|
describe "#subject.method_name being called" do
|
@@ -310,7 +302,7 @@ module RR
|
|
310
302
|
original_method_called = true
|
311
303
|
end
|
312
304
|
end
|
313
|
-
|
305
|
+
double_definition_create.call(:foobar, 1, 2)
|
314
306
|
subject.foobar(1, 2)
|
315
307
|
original_method_called.should be_true
|
316
308
|
end
|
@@ -320,7 +312,7 @@ module RR
|
|
320
312
|
def subject.foobar(*args)
|
321
313
|
:baz;
|
322
314
|
end
|
323
|
-
|
315
|
+
double_definition_create.call(:foobar, 1, 2)
|
324
316
|
subject.foobar(1, 2).should == :baz
|
325
317
|
end
|
326
318
|
end
|
@@ -335,7 +327,7 @@ module RR
|
|
335
327
|
end
|
336
328
|
|
337
329
|
it "calls the block with the return value of the original method" do
|
338
|
-
|
330
|
+
double_definition_create.call(:foobar, 1, 2) do |value|
|
339
331
|
mock(value).a_method {99}
|
340
332
|
value
|
341
333
|
end
|
@@ -344,7 +336,7 @@ module RR
|
|
344
336
|
end
|
345
337
|
|
346
338
|
it "returns the return value of the block" do
|
347
|
-
|
339
|
+
double_definition_create.call(:foobar, 1, 2) do |value|
|
348
340
|
:something_else
|
349
341
|
end
|
350
342
|
subject.foobar(1, 2).should == :something_else
|
@@ -357,12 +349,12 @@ module RR
|
|
357
349
|
context "when #verification_strategy is a Stub" do
|
358
350
|
context "when #implementation_strategy is a Reimplementation" do
|
359
351
|
before do
|
360
|
-
|
352
|
+
double_definition_create.stub(subject)
|
361
353
|
end
|
362
354
|
|
363
355
|
context "when not passed a block" do
|
364
356
|
it "returns nil" do
|
365
|
-
|
357
|
+
double_definition_create.call(:foobar)
|
366
358
|
subject.foobar.should be_nil
|
367
359
|
end
|
368
360
|
end
|
@@ -370,7 +362,7 @@ module RR
|
|
370
362
|
context "when passed a block" do
|
371
363
|
describe "#subject.method_name being called" do
|
372
364
|
it "returns the return value of the block" do
|
373
|
-
|
365
|
+
double_definition_create.call(:foobar) {:baz}
|
374
366
|
subject.foobar.should == :baz
|
375
367
|
end
|
376
368
|
end
|
@@ -379,7 +371,7 @@ module RR
|
|
379
371
|
context "when not passed args" do
|
380
372
|
describe "#subject.method_name being called with any arguments" do
|
381
373
|
it "invokes the implementation of the Stub" do
|
382
|
-
|
374
|
+
double_definition_create.call(:foobar) {:baz}
|
383
375
|
subject.foobar(1, 2).should == :baz
|
384
376
|
subject.foobar().should == :baz
|
385
377
|
subject.foobar([]).should == :baz
|
@@ -390,14 +382,14 @@ module RR
|
|
390
382
|
context "when passed args" do
|
391
383
|
describe "#subject.method_name being called with the passed-in arguments" do
|
392
384
|
it "invokes the implementation of the Stub" do
|
393
|
-
|
385
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
394
386
|
subject.foobar(1, 2).should == :baz
|
395
387
|
end
|
396
388
|
end
|
397
389
|
|
398
390
|
describe "#subject.method_name being called with different arguments" do
|
399
391
|
it "raises a DoubleNotFoundError" do
|
400
|
-
|
392
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
401
393
|
lambda do
|
402
394
|
subject.foobar
|
403
395
|
end.should raise_error(RR::Errors::DoubleNotFoundError)
|
@@ -411,14 +403,14 @@ module RR
|
|
411
403
|
def subject.foobar(*args)
|
412
404
|
:original_return_value
|
413
405
|
end
|
414
|
-
|
415
|
-
|
406
|
+
double_definition_create.stub
|
407
|
+
double_definition_create.proxy(subject)
|
416
408
|
end
|
417
409
|
|
418
410
|
context "when not passed a block" do
|
419
411
|
describe "#subject.method_name being called" do
|
420
412
|
it "invokes the original implementanion" do
|
421
|
-
|
413
|
+
double_definition_create.call(:foobar)
|
422
414
|
subject.foobar.should == :original_return_value
|
423
415
|
end
|
424
416
|
end
|
@@ -428,7 +420,7 @@ module RR
|
|
428
420
|
describe "#subject.method_name being called" do
|
429
421
|
it "invokes the original implementanion and invokes the block with the return value of the original implementanion" do
|
430
422
|
passed_in_value = nil
|
431
|
-
|
423
|
+
double_definition_create.call(:foobar) do |original_return_value|
|
432
424
|
passed_in_value = original_return_value
|
433
425
|
end
|
434
426
|
subject.foobar
|
@@ -436,7 +428,7 @@ module RR
|
|
436
428
|
end
|
437
429
|
|
438
430
|
it "returns the return value of the block" do
|
439
|
-
|
431
|
+
double_definition_create.call(:foobar) do |original_return_value|
|
440
432
|
:new_return_value
|
441
433
|
end
|
442
434
|
subject.foobar.should == :new_return_value
|
@@ -447,14 +439,14 @@ module RR
|
|
447
439
|
context "when passed args" do
|
448
440
|
describe "#subject.method_name being called with the passed-in arguments" do
|
449
441
|
it "invokes the implementation of the Stub" do
|
450
|
-
|
442
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
451
443
|
subject.foobar(1, 2).should == :baz
|
452
444
|
end
|
453
445
|
end
|
454
446
|
|
455
447
|
describe "#subject.method_name being called with different arguments" do
|
456
448
|
it "raises a DoubleNotFoundError" do
|
457
|
-
|
449
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
458
450
|
lambda do
|
459
451
|
subject.foobar
|
460
452
|
end.should raise_error(RR::Errors::DoubleNotFoundError)
|
@@ -466,13 +458,13 @@ module RR
|
|
466
458
|
|
467
459
|
context "when #verification_strategy is a DontAllow" do
|
468
460
|
before do
|
469
|
-
|
461
|
+
double_definition_create.dont_allow(subject)
|
470
462
|
end
|
471
463
|
|
472
464
|
context "when not passed args" do
|
473
465
|
describe "#subject.method_name being called with any arguments" do
|
474
466
|
it "raises a TimesCalledError" do
|
475
|
-
|
467
|
+
double_definition_create.call(:foobar)
|
476
468
|
lambda {subject.foobar}.should raise_error(RR::Errors::TimesCalledError)
|
477
469
|
lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
|
478
470
|
end
|
@@ -482,14 +474,14 @@ module RR
|
|
482
474
|
context "when passed args" do
|
483
475
|
describe "#subject.method_name being called with the passed-in arguments" do
|
484
476
|
it "raises a TimesCalledError" do
|
485
|
-
|
477
|
+
double_definition_create.call(:foobar, 1, 2)
|
486
478
|
lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
|
487
479
|
end
|
488
480
|
end
|
489
481
|
|
490
482
|
describe "#subject.method_name being called with different arguments" do
|
491
483
|
it "raises a DoubleNotFoundError" do
|
492
|
-
|
484
|
+
double_definition_create.call(:foobar, 1, 2)
|
493
485
|
lambda {subject.foobar()}.should raise_error(RR::Errors::DoubleNotFoundError)
|
494
486
|
end
|
495
487
|
end
|