rr 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/{README → README.rdoc} +14 -6
- data/Rakefile +2 -2
- data/lib/rr.rb +11 -3
- data/lib/rr/adapters/rr_methods.rb +12 -12
- data/lib/rr/adapters/rspec.rb +3 -3
- data/lib/rr/adapters/test_unit.rb +3 -3
- data/lib/rr/double.rb +12 -10
- data/lib/rr/double_creator.rb +48 -45
- data/lib/rr/double_definition.rb +17 -149
- data/lib/rr/double_definition_builder.rb +11 -11
- data/lib/rr/double_definition_creator.rb +156 -0
- data/lib/rr/{double_method_proxy.rb → double_definition_creator_proxy.rb} +2 -2
- data/lib/rr/double_injection.rb +6 -6
- data/lib/rr/double_matches.rb +40 -40
- data/lib/rr/errors/rr_error.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/space.rb +9 -30
- data/spec/high_level_spec.rb +140 -143
- data/spec/rr/adapters/rr_methods_creator_spec.rb +21 -21
- data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
- data/spec/rr/double/double_injection_dispatching_spec.rb +15 -15
- data/spec/rr/double/double_injection_reset_spec.rb +1 -1
- data/spec/rr/double/double_injection_verify_spec.rb +5 -4
- data/spec/rr/{double_method_proxy_spec.rb → double_definition_creator_proxy_spec.rb} +12 -10
- data/spec/rr/{double_creator_spec.rb → double_definition_creator_spec.rb} +166 -124
- data/spec/rr/double_definition_spec.rb +637 -642
- data/spec/rr/double_spec.rb +44 -43
- data/spec/rr/errors/rr_error_spec.rb +6 -6
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +3 -3
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +8 -8
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +11 -13
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +19 -19
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +16 -16
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +7 -11
- data/spec/rr/rspec/rspec_adapter_spec.rb +10 -10
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +372 -18
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +3 -3
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +3 -3
- data/spec/spec_helper.rb +14 -3
- data/spec/spec_suite.rb +2 -2
- metadata +47 -45
- data/spec/rr/double/double_injection_register_scenario_spec.rb +0 -24
- data/spec/rr/space/space_create_spec.rb +0 -268
- data/spec/rr/space/space_helper.rb +0 -7
- data/spec/rr/space/space_register_spec.rb +0 -32
- data/spec/rr/space/space_reset_spec.rb +0 -131
- data/spec/rr/space/space_verify_spec.rb +0 -181
@@ -1,32 +0,0 @@
|
|
1
|
-
require "spec/spec_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe Space, "#register_ordered_double" do
|
5
|
-
it_should_behave_like "RR::Space"
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@space = Space.new
|
9
|
-
@original_space = Space.instance
|
10
|
-
Space.instance = @space
|
11
|
-
@object = Object.new
|
12
|
-
@method_name = :foobar
|
13
|
-
@double_injection = @space.double_injection(@object, @method_name)
|
14
|
-
end
|
15
|
-
|
16
|
-
after(:each) do
|
17
|
-
Space.instance = @original_space
|
18
|
-
end
|
19
|
-
|
20
|
-
it "adds the ordered double to the ordered_doubles collection" do
|
21
|
-
double1 = @space.double(@double_injection)
|
22
|
-
|
23
|
-
@space.ordered_doubles.should == []
|
24
|
-
@space.register_ordered_double double1
|
25
|
-
@space.ordered_doubles.should == [double1]
|
26
|
-
|
27
|
-
double2 = @space.double(@double_injection)
|
28
|
-
@space.register_ordered_double double2
|
29
|
-
@space.ordered_doubles.should == [double1, double2]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require "spec/spec_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe Space do
|
5
|
-
it_should_behave_like "RR::Space"
|
6
|
-
describe "#reset" do
|
7
|
-
before do
|
8
|
-
@space = Space.new
|
9
|
-
@object1 = Object.new
|
10
|
-
@object2 = Object.new
|
11
|
-
@method_name = :foobar
|
12
|
-
end
|
13
|
-
|
14
|
-
it "removes the ordered doubles" do
|
15
|
-
double1 = @space.double_injection(@object1, :foobar1)
|
16
|
-
double2 = @space.double_injection(@object1, :foobar2)
|
17
|
-
|
18
|
-
double1 = @space.double(double1)
|
19
|
-
double2 = @space.double(double2)
|
20
|
-
|
21
|
-
double1.ordered
|
22
|
-
double2.ordered
|
23
|
-
|
24
|
-
@space.ordered_doubles.should_not be_empty
|
25
|
-
|
26
|
-
@space.reset
|
27
|
-
@space.ordered_doubles.should be_empty
|
28
|
-
end
|
29
|
-
|
30
|
-
it "resets all double_injections" do
|
31
|
-
double1 = @space.double_injection(@object1, @method_name)
|
32
|
-
double1_reset_calls = 0
|
33
|
-
(
|
34
|
-
class << double1;
|
35
|
-
self;
|
36
|
-
end).class_eval do
|
37
|
-
define_method(:reset) do ||
|
38
|
-
double1_reset_calls += 1
|
39
|
-
end
|
40
|
-
end
|
41
|
-
double2 = @space.double_injection(@object2, @method_name)
|
42
|
-
double2_reset_calls = 0
|
43
|
-
(
|
44
|
-
class << double2;
|
45
|
-
self;
|
46
|
-
end).class_eval do
|
47
|
-
define_method(:reset) do ||
|
48
|
-
double2_reset_calls += 1
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
@space.reset
|
53
|
-
double1_reset_calls.should == 1
|
54
|
-
double2_reset_calls.should == 1
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#reset_double" do
|
59
|
-
before do
|
60
|
-
@space = Space.new
|
61
|
-
@object = Object.new
|
62
|
-
@method_name = :foobar
|
63
|
-
end
|
64
|
-
|
65
|
-
it "resets the double_injections" do
|
66
|
-
double_injection = @space.double_injection(@object, @method_name)
|
67
|
-
@space.double_injections[@object][@method_name].should === double_injection
|
68
|
-
@object.methods.should include("__rr__#{@method_name}")
|
69
|
-
|
70
|
-
@space.reset_double(@object, @method_name)
|
71
|
-
@space.double_injections[@object][@method_name].should be_nil
|
72
|
-
@object.methods.should_not include("__rr__#{@method_name}")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "removes the object from the double_injections map when it has no double_injections" do
|
76
|
-
double1 = @space.double_injection(@object, :foobar1)
|
77
|
-
double2 = @space.double_injection(@object, :foobar2)
|
78
|
-
|
79
|
-
@space.double_injections.include?(@object).should == true
|
80
|
-
@space.double_injections[@object][:foobar1].should_not be_nil
|
81
|
-
@space.double_injections[@object][:foobar2].should_not be_nil
|
82
|
-
|
83
|
-
@space.reset_double(@object, :foobar1)
|
84
|
-
@space.double_injections.include?(@object).should == true
|
85
|
-
@space.double_injections[@object][:foobar1].should be_nil
|
86
|
-
@space.double_injections[@object][:foobar2].should_not be_nil
|
87
|
-
|
88
|
-
@space.reset_double(@object, :foobar2)
|
89
|
-
@space.double_injections.include?(@object).should == false
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "#reset_double_injections" do
|
94
|
-
it_should_behave_like "RR::Space"
|
95
|
-
|
96
|
-
before do
|
97
|
-
@space = Space.new
|
98
|
-
@object1 = Object.new
|
99
|
-
@object2 = Object.new
|
100
|
-
@method_name = :foobar
|
101
|
-
end
|
102
|
-
|
103
|
-
it "resets the double_injection and removes it from the double_injections list" do
|
104
|
-
double1 = @space.double_injection(@object1, @method_name)
|
105
|
-
double1_reset_calls = 0
|
106
|
-
(
|
107
|
-
class << double1;
|
108
|
-
self;
|
109
|
-
end).class_eval do
|
110
|
-
define_method(:reset) do ||
|
111
|
-
double1_reset_calls += 1
|
112
|
-
end
|
113
|
-
end
|
114
|
-
double2 = @space.double_injection(@object2, @method_name)
|
115
|
-
double2_reset_calls = 0
|
116
|
-
(
|
117
|
-
class << double2;
|
118
|
-
self;
|
119
|
-
end).class_eval do
|
120
|
-
define_method(:reset) do ||
|
121
|
-
double2_reset_calls += 1
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
@space.send(:reset_double_injections)
|
126
|
-
double1_reset_calls.should == 1
|
127
|
-
double2_reset_calls.should == 1
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
@@ -1,181 +0,0 @@
|
|
1
|
-
require "spec/spec_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe Space, "#verify_ordered_double", :shared => true do
|
5
|
-
before do
|
6
|
-
@space = Space.new
|
7
|
-
@object = Object.new
|
8
|
-
@method_name = :foobar
|
9
|
-
@double_injection = @space.double_injection(@object, @method_name)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "raises an error when Double is NonTerminal" do
|
13
|
-
double = @space.double(@double_injection)
|
14
|
-
@space.register_ordered_double(double)
|
15
|
-
|
16
|
-
double.any_number_of_times
|
17
|
-
double.should_not be_terminal
|
18
|
-
|
19
|
-
proc do
|
20
|
-
@space.verify_ordered_double(double)
|
21
|
-
end.should raise_error(
|
22
|
-
Errors::DoubleOrderError,
|
23
|
-
"Ordered Doubles cannot have a NonTerminal TimesCalledExpectation"
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Space do
|
29
|
-
it_should_behave_like "RR::Space"
|
30
|
-
|
31
|
-
describe "#verify_doubles" do
|
32
|
-
before do
|
33
|
-
@space = Space.new
|
34
|
-
@object1 = Object.new
|
35
|
-
@object2 = Object.new
|
36
|
-
@method_name = :foobar
|
37
|
-
end
|
38
|
-
|
39
|
-
it "verifies and deletes the double_injections" do
|
40
|
-
double1 = @space.double_injection(@object1, @method_name)
|
41
|
-
double1_verify_calls = 0
|
42
|
-
double1_reset_calls = 0
|
43
|
-
(
|
44
|
-
class << double1;
|
45
|
-
self;
|
46
|
-
end).class_eval do
|
47
|
-
define_method(:verify) do ||
|
48
|
-
double1_verify_calls += 1
|
49
|
-
end
|
50
|
-
define_method(:reset) do ||
|
51
|
-
double1_reset_calls += 1
|
52
|
-
end
|
53
|
-
end
|
54
|
-
double2 = @space.double_injection(@object2, @method_name)
|
55
|
-
double2_verify_calls = 0
|
56
|
-
double2_reset_calls = 0
|
57
|
-
(
|
58
|
-
class << double2;
|
59
|
-
self;
|
60
|
-
end).class_eval do
|
61
|
-
define_method(:verify) do ||
|
62
|
-
double2_verify_calls += 1
|
63
|
-
end
|
64
|
-
define_method(:reset) do ||
|
65
|
-
double2_reset_calls += 1
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
@space.verify_doubles
|
70
|
-
double1_verify_calls.should == 1
|
71
|
-
double2_verify_calls.should == 1
|
72
|
-
double1_reset_calls.should == 1
|
73
|
-
double1_reset_calls.should == 1
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#verify_double" do
|
78
|
-
it_should_behave_like "RR::Space"
|
79
|
-
|
80
|
-
before do
|
81
|
-
@space = Space.new
|
82
|
-
@object = Object.new
|
83
|
-
@method_name = :foobar
|
84
|
-
end
|
85
|
-
|
86
|
-
it "verifies and deletes the double_injection" do
|
87
|
-
double_injection = @space.double_injection(@object, @method_name)
|
88
|
-
@space.double_injections[@object][@method_name].should === double_injection
|
89
|
-
@object.methods.should include("__rr__#{@method_name}")
|
90
|
-
|
91
|
-
verify_calls = 0
|
92
|
-
(
|
93
|
-
class << double_injection;
|
94
|
-
self;
|
95
|
-
end).class_eval do
|
96
|
-
define_method(:verify) do ||
|
97
|
-
verify_calls += 1
|
98
|
-
end
|
99
|
-
end
|
100
|
-
@space.verify_double(@object, @method_name)
|
101
|
-
verify_calls.should == 1
|
102
|
-
|
103
|
-
@space.double_injections[@object][@method_name].should be_nil
|
104
|
-
@object.methods.should_not include("__rr__#{@method_name}")
|
105
|
-
end
|
106
|
-
|
107
|
-
it "deletes the double_injection when verifying the double_injection raises an error" do
|
108
|
-
double_injection = @space.double_injection(@object, @method_name)
|
109
|
-
@space.double_injections[@object][@method_name].should === double_injection
|
110
|
-
@object.methods.should include("__rr__#{@method_name}")
|
111
|
-
|
112
|
-
verify_called = true
|
113
|
-
(
|
114
|
-
class << double_injection;
|
115
|
-
self;
|
116
|
-
end).class_eval do
|
117
|
-
define_method(:verify) do ||
|
118
|
-
verify_called = true
|
119
|
-
raise "An Error"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
proc {@space.verify_double(@object, @method_name)}.should raise_error
|
123
|
-
verify_called.should be_true
|
124
|
-
|
125
|
-
@space.double_injections[@object][@method_name].should be_nil
|
126
|
-
@object.methods.should_not include("__rr__#{@method_name}")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "#verify_ordered_double where the passed in double is at the front of the queue" do
|
131
|
-
it_should_behave_like "RR::Space#verify_ordered_double"
|
132
|
-
|
133
|
-
it "keeps the double when times called is not verified" do
|
134
|
-
double = @space.double(@double_injection)
|
135
|
-
@space.register_ordered_double(double)
|
136
|
-
|
137
|
-
double.twice
|
138
|
-
double.should be_attempt
|
139
|
-
|
140
|
-
@space.verify_ordered_double(double)
|
141
|
-
@space.ordered_doubles.should include(double)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "removes the double when times called expectation should no longer be attempted" do
|
145
|
-
double = @space.double(@double_injection)
|
146
|
-
@space.register_ordered_double(double)
|
147
|
-
|
148
|
-
double.with(1).once
|
149
|
-
@object.foobar(1)
|
150
|
-
double.should_not be_attempt
|
151
|
-
|
152
|
-
@space.verify_ordered_double(double)
|
153
|
-
@space.ordered_doubles.should_not include(double)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe "#verify_ordered_double where the passed in double is not at the front of the queue" do
|
158
|
-
it_should_behave_like "RR::Space#verify_ordered_double"
|
159
|
-
|
160
|
-
it "raises error" do
|
161
|
-
first_double = double
|
162
|
-
second_double = double
|
163
|
-
|
164
|
-
proc do
|
165
|
-
@space.verify_ordered_double(second_double)
|
166
|
-
end.should raise_error(
|
167
|
-
Errors::DoubleOrderError,
|
168
|
-
"foobar() called out of order in list\n" <<
|
169
|
-
"- foobar()\n" <<
|
170
|
-
"- foobar()"
|
171
|
-
)
|
172
|
-
end
|
173
|
-
|
174
|
-
def double
|
175
|
-
double_definition = @space.double(@double_injection).once
|
176
|
-
@space.register_ordered_double(double_definition.double)
|
177
|
-
double_definition.double
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|