rr 0.3.11 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -3
- data/README +130 -39
- data/Rakefile +6 -5
- data/lib/rr.rb +8 -8
- data/lib/rr/adapters/rr_methods.rb +228 -0
- data/lib/rr/adapters/rspec.rb +1 -1
- data/lib/rr/adapters/test_unit.rb +1 -1
- data/lib/rr/double.rb +294 -89
- data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
- data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
- data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
- data/lib/rr/double_insertion.rb +132 -0
- data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
- data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
- data/lib/rr/errors/argument_equality_error.rb +3 -3
- data/lib/rr/errors/rr_error.rb +13 -13
- data/lib/rr/errors/scenario_definition_error.rb +3 -3
- data/lib/rr/errors/scenario_not_found_error.rb +3 -3
- data/lib/rr/errors/scenario_order_error.rb +3 -3
- data/lib/rr/errors/times_called_error.rb +3 -3
- data/lib/rr/expectations/any_argument_expectation.rb +1 -1
- data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/hash_with_object_id_key.rb +1 -1
- data/lib/rr/space.rb +40 -40
- data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
- data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
- data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
- data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
- data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
- data/lib/rr/times_called_matchers/terminal.rb +16 -16
- data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
- data/spec/core_spec_suite.rb +18 -0
- data/{examples → spec}/environment_fixture_setup.rb +0 -1
- data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
- data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
- data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
- data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
- data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
- data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
- data/spec/rr/double/double_insertion_spec.rb +66 -0
- data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
- data/spec/rr/double_creator_spec.rb +454 -0
- data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
- data/spec/rr/double_method_proxy_spec.rb +71 -0
- data/spec/rr/double_spec.rb +654 -0
- data/spec/rr/errors/rr_error_spec.rb +65 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_create_spec.rb +278 -0
- data/spec/rr/space/space_helper.rb +7 -0
- data/spec/rr/space/space_register_spec.rb +32 -0
- data/spec/rr/space/space_reset_spec.rb +131 -0
- data/spec/rr/space/space_spec.rb +32 -0
- data/spec/rr/space/space_verify_spec.rb +181 -0
- data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
- data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
- data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rspec_spec_suite.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
- data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
- metadata +93 -93
- data/examples/core_example_suite.rb +0 -31
- data/examples/example_helper.rb +0 -9
- data/examples/rr/double/double_bind_example.rb +0 -70
- data/examples/rr/double/double_dispatching_example.rb +0 -236
- data/examples/rr/double/double_example.rb +0 -66
- data/examples/rr/double/double_has_original_method_example.rb +0 -56
- data/examples/rr/double/double_register_scenario_example.rb +0 -24
- data/examples/rr/double/double_reset_example.rb +0 -89
- data/examples/rr/double/double_verify_example.rb +0 -23
- data/examples/rr/errors/rr_error_example.rb +0 -65
- data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
- data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
- data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
- data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
- data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
- data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
- data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
- data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
- data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
- data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
- data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
- data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
- data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
- data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
- data/examples/rr/rspec/rspec_usage_example.rb +0 -65
- data/examples/rr/scenario_creator_example.rb +0 -459
- data/examples/rr/scenario_example.rb +0 -701
- data/examples/rr/scenario_method_proxy_example.rb +0 -71
- data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
- data/examples/rr/space/space_create_example.rb +0 -278
- data/examples/rr/space/space_example.rb +0 -29
- data/examples/rr/space/space_helper.rb +0 -7
- data/examples/rr/space/space_register_example.rb +0 -32
- data/examples/rr/space/space_reset_example.rb +0 -120
- data/examples/rr/space/space_verify_example.rb +0 -169
- data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
- data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
- data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
- data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
- data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
- data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
- data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
- data/examples/rspec_example_suite.rb +0 -25
- data/lib/rr/extensions/instance_methods.rb +0 -228
- data/lib/rr/scenario.rb +0 -337
@@ -1,701 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe Scenario, :shared => true do
|
5
|
-
before do
|
6
|
-
@space = Space.new
|
7
|
-
@object = Object.new
|
8
|
-
def @object.foobar(a, b)
|
9
|
-
[b, a]
|
10
|
-
end
|
11
|
-
@double = @space.double(@object, :foobar)
|
12
|
-
@scenario = @space.scenario(@double)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe Scenario, "#with" do
|
17
|
-
it_should_behave_like "RR::Scenario"
|
18
|
-
|
19
|
-
it "returns ScenarioDefinition" do
|
20
|
-
@scenario.with(1).should === @scenario.definition
|
21
|
-
end
|
22
|
-
|
23
|
-
it "sets an ArgumentEqualityExpectation" do
|
24
|
-
@scenario.with(1)
|
25
|
-
@scenario.should be_exact_match(1)
|
26
|
-
@scenario.should_not be_exact_match(2)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "sets return value when block passed in" do
|
30
|
-
@scenario.with(1) {:return_value}
|
31
|
-
@object.foobar(1).should == :return_value
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe Scenario, "#with_any_args" do
|
36
|
-
it_should_behave_like "RR::Scenario"
|
37
|
-
|
38
|
-
before do
|
39
|
-
@scenario.with_any_args {:return_value}
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns ScenarioDefinition" do
|
43
|
-
@scenario.with_no_args.should === @scenario.definition
|
44
|
-
end
|
45
|
-
|
46
|
-
it "sets an AnyArgumentExpectation" do
|
47
|
-
@scenario.should_not be_exact_match(1)
|
48
|
-
@scenario.should be_wildcard_match(1)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "sets return value when block passed in" do
|
52
|
-
@object.foobar(:anything).should == :return_value
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe Scenario, "#with_no_args" do
|
57
|
-
it_should_behave_like "RR::Scenario"
|
58
|
-
|
59
|
-
before do
|
60
|
-
@scenario.with_no_args {:return_value}
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns ScenarioDefinition" do
|
64
|
-
@scenario.with_no_args.should === @scenario.definition
|
65
|
-
end
|
66
|
-
|
67
|
-
it "sets an ArgumentEqualityExpectation with no arguments" do
|
68
|
-
@scenario.argument_expectation.should == Expectations::ArgumentEqualityExpectation.new()
|
69
|
-
end
|
70
|
-
|
71
|
-
it "sets return value when block passed in" do
|
72
|
-
@object.foobar().should == :return_value
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe Scenario, "#never" do
|
77
|
-
it_should_behave_like "RR::Scenario"
|
78
|
-
|
79
|
-
it "returns ScenarioDefinition" do
|
80
|
-
@scenario.never.should === @scenario.definition
|
81
|
-
end
|
82
|
-
|
83
|
-
it "sets up a Times Called Expectation with 0" do
|
84
|
-
@scenario.never
|
85
|
-
proc {@scenario.call(@double)}.should raise_error(Errors::TimesCalledError)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "sets return value when block passed in" do
|
89
|
-
@scenario.with_any_args.never
|
90
|
-
proc {@scenario.call(@double)}.should raise_error(Errors::TimesCalledError)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe Scenario, "#once" do
|
95
|
-
it_should_behave_like "RR::Scenario"
|
96
|
-
|
97
|
-
it "returns ScenarioDefinition" do
|
98
|
-
@scenario.once.should === @scenario.definition
|
99
|
-
end
|
100
|
-
|
101
|
-
it "sets up a Times Called Expectation with 1" do
|
102
|
-
@scenario.once
|
103
|
-
@scenario.call(@double)
|
104
|
-
proc {@scenario.call(@double)}.should raise_error(Errors::TimesCalledError)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "sets return value when block passed in" do
|
108
|
-
@scenario.with_any_args.once {:return_value}
|
109
|
-
@object.foobar.should == :return_value
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe Scenario, "#twice" do
|
114
|
-
it_should_behave_like "RR::Scenario"
|
115
|
-
|
116
|
-
it "returns ScenarioDefinition" do
|
117
|
-
@scenario.twice.should === @scenario.definition
|
118
|
-
end
|
119
|
-
|
120
|
-
it "sets up a Times Called Expectation with 2" do
|
121
|
-
@scenario.twice
|
122
|
-
@scenario.call(@double)
|
123
|
-
@scenario.call(@double)
|
124
|
-
proc {@scenario.call(@double)}.should raise_error(Errors::TimesCalledError)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "sets return value when block passed in" do
|
128
|
-
@scenario.with_any_args.twice {:return_value}
|
129
|
-
@object.foobar.should == :return_value
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe Scenario, "#at_least" do
|
134
|
-
it_should_behave_like "RR::Scenario"
|
135
|
-
|
136
|
-
it "returns ScenarioDefinition" do
|
137
|
-
@scenario.with_any_args.at_least(2).should === @scenario.definition
|
138
|
-
end
|
139
|
-
|
140
|
-
it "sets up a AtLeastMatcher with 2" do
|
141
|
-
@scenario.at_least(2)
|
142
|
-
@scenario.definition.times_matcher.should == TimesCalledMatchers::AtLeastMatcher.new(2)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "sets return value when block passed in" do
|
146
|
-
@scenario.with_any_args.at_least(2) {:return_value}
|
147
|
-
@object.foobar.should == :return_value
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe Scenario, "#at_most" do
|
152
|
-
it_should_behave_like "RR::Scenario"
|
153
|
-
|
154
|
-
it "returns ScenarioDefinition" do
|
155
|
-
@scenario.with_any_args.at_most(2).should === @scenario.definition
|
156
|
-
end
|
157
|
-
|
158
|
-
it "sets up a Times Called Expectation with 1" do
|
159
|
-
@scenario.at_most(2)
|
160
|
-
@scenario.call(@double)
|
161
|
-
@scenario.call(@double)
|
162
|
-
proc do
|
163
|
-
@scenario.call(@double)
|
164
|
-
end.should raise_error(
|
165
|
-
Errors::TimesCalledError,
|
166
|
-
"foobar()\nCalled 3 times.\nExpected at most 2 times."
|
167
|
-
)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "sets return value when block passed in" do
|
171
|
-
@scenario.with_any_args.at_most(2) {:return_value}
|
172
|
-
@object.foobar.should == :return_value
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe Scenario, "#times" do
|
177
|
-
it_should_behave_like "RR::Scenario"
|
178
|
-
|
179
|
-
it "returns ScenarioDefinition" do
|
180
|
-
@scenario.times(3).should === @scenario.definition
|
181
|
-
end
|
182
|
-
|
183
|
-
it "sets up a Times Called Expectation with passed in times" do
|
184
|
-
@scenario.times(3)
|
185
|
-
@scenario.call(@double)
|
186
|
-
@scenario.call(@double)
|
187
|
-
@scenario.call(@double)
|
188
|
-
proc {@scenario.call(@double)}.should raise_error(Errors::TimesCalledError)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "sets return value when block passed in" do
|
192
|
-
@scenario.with_any_args.times(3) {:return_value}
|
193
|
-
@object.foobar.should == :return_value
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe Scenario, "#any_number_of_times" do
|
198
|
-
it_should_behave_like "RR::Scenario"
|
199
|
-
|
200
|
-
it "returns ScenarioDefinition" do
|
201
|
-
@scenario.any_number_of_times.should === @scenario.definition
|
202
|
-
end
|
203
|
-
|
204
|
-
it "sets up a Times Called Expectation with AnyTimes matcher" do
|
205
|
-
@scenario.any_number_of_times
|
206
|
-
@scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
207
|
-
end
|
208
|
-
|
209
|
-
it "sets return value when block passed in" do
|
210
|
-
@scenario.with_any_args.any_number_of_times {:return_value}
|
211
|
-
@object.foobar.should == :return_value
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe Scenario, "#ordered" do
|
216
|
-
it_should_behave_like "RR::Scenario"
|
217
|
-
|
218
|
-
it "adds itself to the ordered scenarios list" do
|
219
|
-
@scenario.ordered
|
220
|
-
@space.ordered_scenarios.should include(@scenario)
|
221
|
-
end
|
222
|
-
|
223
|
-
it "does not double add itself" do
|
224
|
-
@scenario.ordered
|
225
|
-
@scenario.ordered
|
226
|
-
@space.ordered_scenarios.should == [@scenario ]
|
227
|
-
end
|
228
|
-
|
229
|
-
it "sets ordered? to true" do
|
230
|
-
@scenario.ordered
|
231
|
-
@scenario.should be_ordered
|
232
|
-
end
|
233
|
-
|
234
|
-
it "sets return value when block passed in" do
|
235
|
-
@scenario.with_any_args.once.ordered {:return_value}
|
236
|
-
@object.foobar.should == :return_value
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe Scenario, "#ordered?" do
|
241
|
-
it_should_behave_like "RR::Scenario"
|
242
|
-
|
243
|
-
it "defaults to false" do
|
244
|
-
@scenario.should_not be_ordered
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe Scenario, "#yields" do
|
249
|
-
it_should_behave_like "RR::Scenario"
|
250
|
-
|
251
|
-
it "returns ScenarioDefinition" do
|
252
|
-
@scenario.yields(:baz).should === @scenario.definition
|
253
|
-
end
|
254
|
-
|
255
|
-
it "yields the passed in argument to the call block when there is no returns value set" do
|
256
|
-
@scenario.with_any_args.yields(:baz)
|
257
|
-
passed_in_block_arg = nil
|
258
|
-
@object.foobar {|arg| passed_in_block_arg = arg}.should == nil
|
259
|
-
passed_in_block_arg.should == :baz
|
260
|
-
end
|
261
|
-
|
262
|
-
it "yields the passed in argument to the call block when there is a no returns value set" do
|
263
|
-
@scenario.with_any_args.yields(:baz).returns(:return_value)
|
264
|
-
|
265
|
-
passed_in_block_arg = nil
|
266
|
-
@object.foobar {|arg| passed_in_block_arg = arg}.should == :return_value
|
267
|
-
passed_in_block_arg.should == :baz
|
268
|
-
end
|
269
|
-
|
270
|
-
it "sets return value when block passed in" do
|
271
|
-
@scenario.with_any_args.yields {:return_value}
|
272
|
-
@object.foobar {}.should == :return_value
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
describe Scenario, "#after_call" do
|
277
|
-
it_should_behave_like "RR::Scenario"
|
278
|
-
|
279
|
-
it "returns ScenarioDefinition" do
|
280
|
-
@scenario.after_call {}.should === @scenario.definition
|
281
|
-
end
|
282
|
-
|
283
|
-
it "sends return value of Scenario implementation to after_call" do
|
284
|
-
return_value = {}
|
285
|
-
@scenario.returns(return_value).after_call do |value|
|
286
|
-
value[:foo] = :bar
|
287
|
-
value
|
288
|
-
end
|
289
|
-
|
290
|
-
actual_value = @scenario.call(@double)
|
291
|
-
actual_value.should === return_value
|
292
|
-
actual_value.should == {:foo => :bar}
|
293
|
-
end
|
294
|
-
|
295
|
-
it "receives the return value in the after_call callback" do
|
296
|
-
return_value = :returns_value
|
297
|
-
@scenario.returns(return_value).after_call do |value|
|
298
|
-
:after_call_value
|
299
|
-
end
|
300
|
-
|
301
|
-
actual_value = @scenario.call(@double)
|
302
|
-
actual_value.should == :after_call_value
|
303
|
-
end
|
304
|
-
|
305
|
-
it "allows after_call to mock the return value" do
|
306
|
-
return_value = Object.new
|
307
|
-
@scenario.with_any_args.returns(return_value).after_call do |value|
|
308
|
-
mock(value).inner_method(1) {:baz}
|
309
|
-
value
|
310
|
-
end
|
311
|
-
|
312
|
-
@object.foobar.inner_method(1).should == :baz
|
313
|
-
end
|
314
|
-
|
315
|
-
it "raises an error when not passed a block" do
|
316
|
-
proc do
|
317
|
-
@scenario.after_call
|
318
|
-
end.should raise_error(ArgumentError, "after_call expects a block")
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
describe Scenario, "#returns" do
|
323
|
-
it_should_behave_like "RR::Scenario"
|
324
|
-
|
325
|
-
it "returns ScenarioDefinition" do
|
326
|
-
@scenario.returns {:baz}.should === @scenario.definition
|
327
|
-
@scenario.returns(:baz).should === @scenario.definition
|
328
|
-
end
|
329
|
-
|
330
|
-
it "sets the value of the method when passed a block" do
|
331
|
-
@scenario.returns {:baz}
|
332
|
-
@scenario.call(@double).should == :baz
|
333
|
-
end
|
334
|
-
|
335
|
-
it "sets the value of the method when passed an argument" do
|
336
|
-
@scenario.returns(:baz)
|
337
|
-
@scenario.call(@double).should == :baz
|
338
|
-
end
|
339
|
-
|
340
|
-
it "returns false when passed false" do
|
341
|
-
@scenario.returns(false)
|
342
|
-
@scenario.call(@double).should == false
|
343
|
-
end
|
344
|
-
|
345
|
-
it "raises an error when both argument and block is passed in" do
|
346
|
-
proc do
|
347
|
-
@scenario.returns(:baz) {:another}
|
348
|
-
end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe Scenario, "#implemented_by" do
|
353
|
-
it_should_behave_like "RR::Scenario"
|
354
|
-
|
355
|
-
it "returns the ScenarioDefinition" do
|
356
|
-
@scenario.implemented_by(proc{:baz}).should === @scenario.definition
|
357
|
-
end
|
358
|
-
|
359
|
-
it "sets the implementation to the passed in proc" do
|
360
|
-
@scenario.implemented_by(proc{:baz})
|
361
|
-
@scenario.call(@double).should == :baz
|
362
|
-
end
|
363
|
-
|
364
|
-
it "sets the implementation to the passed in method" do
|
365
|
-
def @object.foobar(a, b)
|
366
|
-
[b, a]
|
367
|
-
end
|
368
|
-
@scenario.implemented_by(@object.method(:foobar))
|
369
|
-
@scenario.call(@double, 1, 2).should == [2, 1]
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
describe Scenario, "#implemented_by_original_method" do
|
374
|
-
it_should_behave_like "RR::Scenario"
|
375
|
-
|
376
|
-
it "returns the ScenarioDefinition object" do
|
377
|
-
@scenario.implemented_by_original_method.should === @scenario.definition
|
378
|
-
end
|
379
|
-
|
380
|
-
it "sets the implementation to the original method" do
|
381
|
-
@scenario.implemented_by_original_method
|
382
|
-
@scenario.call(@double, 1, 2).should == [2, 1]
|
383
|
-
end
|
384
|
-
|
385
|
-
it "calls methods when respond_to? is true and methods does not contain original method" do
|
386
|
-
method_name = nil
|
387
|
-
class << @object
|
388
|
-
def methods
|
389
|
-
[]
|
390
|
-
end
|
391
|
-
def method(name)
|
392
|
-
raise "We should not be here"
|
393
|
-
end
|
394
|
-
def respond_to?(name)
|
395
|
-
true
|
396
|
-
end
|
397
|
-
def method_missing(method_name, *args, &block)
|
398
|
-
raise "We should not be here"
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
double = @space.double(@object, :foobar)
|
403
|
-
scenario = @space.scenario(double)
|
404
|
-
scenario.with_any_args
|
405
|
-
scenario.implemented_by_original_method
|
406
|
-
|
407
|
-
@object.foobar(1, 2).should == [2, 1]
|
408
|
-
end
|
409
|
-
|
410
|
-
it "calls method when original_method does not exist" do
|
411
|
-
class << @object
|
412
|
-
def method_missing(method_name, *args, &block)
|
413
|
-
"method_missing for #{method_name}(#{args.inspect})"
|
414
|
-
end
|
415
|
-
end
|
416
|
-
double = @space.double(@object, :does_not_exist)
|
417
|
-
scenario = @space.scenario(double)
|
418
|
-
scenario.with_any_args
|
419
|
-
scenario.implemented_by_original_method
|
420
|
-
|
421
|
-
return_value = @object.does_not_exist(1, 2)
|
422
|
-
return_value.should == "method_missing for does_not_exist([1, 2])"
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
describe Scenario, "#call implemented by a proc" do
|
427
|
-
it_should_behave_like "RR::Scenario"
|
428
|
-
|
429
|
-
it "calls the return proc when implemented by a proc" do
|
430
|
-
@scenario.returns {|arg| "returning #{arg}"}
|
431
|
-
@scenario.call(@double, :foobar).should == "returning foobar"
|
432
|
-
end
|
433
|
-
|
434
|
-
it "calls and returns the after_call when after_call is set" do
|
435
|
-
@scenario.returns {|arg| "returning #{arg}"}.after_call do |value|
|
436
|
-
"#{value} after call"
|
437
|
-
end
|
438
|
-
@scenario.call(@double, :foobar).should == "returning foobar after call"
|
439
|
-
end
|
440
|
-
|
441
|
-
it "returns nil when to returns is not set" do
|
442
|
-
@scenario.call(@double).should be_nil
|
443
|
-
end
|
444
|
-
|
445
|
-
it "works when times_called is not set" do
|
446
|
-
@scenario.returns {:value}
|
447
|
-
@scenario.call(@double)
|
448
|
-
end
|
449
|
-
|
450
|
-
it "verifes the times_called does not exceed the TimesCalledExpectation" do
|
451
|
-
@scenario.times(2).returns {:value}
|
452
|
-
|
453
|
-
@scenario.call(@double, :foobar)
|
454
|
-
@scenario.call(@double, :foobar)
|
455
|
-
proc {@scenario.call(@double, :foobar)}.should raise_error(Errors::TimesCalledError)
|
456
|
-
end
|
457
|
-
|
458
|
-
it "raises ScenarioOrderError when ordered and called out of order" do
|
459
|
-
scenario1 = @scenario
|
460
|
-
scenario2 = @space.scenario(@double)
|
461
|
-
|
462
|
-
scenario1.with(1).returns {:return_1}.ordered.once
|
463
|
-
scenario2.with(2).returns {:return_2}.ordered.once
|
464
|
-
|
465
|
-
proc do
|
466
|
-
@object.foobar(2)
|
467
|
-
end.should raise_error(
|
468
|
-
Errors::ScenarioOrderError,
|
469
|
-
"foobar(2) called out of order in list\n" <<
|
470
|
-
"- foobar(1)\n" <<
|
471
|
-
"- foobar(2)"
|
472
|
-
)
|
473
|
-
end
|
474
|
-
|
475
|
-
it "dispatches to Space#verify_ordered_scenario when ordered" do
|
476
|
-
verify_ordered_scenario_called = false
|
477
|
-
passed_in_scenario = nil
|
478
|
-
@space.method(:verify_ordered_scenario).arity.should == 1
|
479
|
-
(class << @space; self; end).class_eval do
|
480
|
-
define_method :verify_ordered_scenario do |scenario|
|
481
|
-
passed_in_scenario = scenario
|
482
|
-
verify_ordered_scenario_called = true
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
@scenario.returns {:value}.ordered
|
487
|
-
@scenario.call(@double, :foobar)
|
488
|
-
verify_ordered_scenario_called.should be_true
|
489
|
-
passed_in_scenario.should === @scenario
|
490
|
-
end
|
491
|
-
|
492
|
-
it "does not dispatche to Space#verify_ordered_scenario when not ordered" do
|
493
|
-
verify_ordered_scenario_called = false
|
494
|
-
@space.method(:verify_ordered_scenario).arity.should == 1
|
495
|
-
(class << @space; self; end).class_eval do
|
496
|
-
define_method :verify_ordered_scenario do |scenario|
|
497
|
-
verify_ordered_scenario_called = true
|
498
|
-
end
|
499
|
-
end
|
500
|
-
|
501
|
-
@scenario.returns {:value}
|
502
|
-
@scenario.call(@double, :foobar)
|
503
|
-
verify_ordered_scenario_called.should be_false
|
504
|
-
end
|
505
|
-
|
506
|
-
it "does not add block argument if no block passed in" do
|
507
|
-
@scenario.with(1, 2).returns {|*args| args}
|
508
|
-
|
509
|
-
args = @object.foobar(1, 2)
|
510
|
-
args.should == [1, 2]
|
511
|
-
end
|
512
|
-
|
513
|
-
it "makes the block the last argument" do
|
514
|
-
@scenario.with(1, 2).returns {|a, b, blk| blk}
|
515
|
-
|
516
|
-
block = @object.foobar(1, 2) {|a, b| [b, a]}
|
517
|
-
block.call(3, 4).should == [4, 3]
|
518
|
-
end
|
519
|
-
|
520
|
-
it "raises ArgumentError when yields was called and no block passed in" do
|
521
|
-
@scenario.with(1, 2).yields(55)
|
522
|
-
|
523
|
-
proc do
|
524
|
-
@object.foobar(1, 2)
|
525
|
-
end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
|
526
|
-
end
|
527
|
-
end
|
528
|
-
|
529
|
-
describe Scenario, "#call implemented by a method" do
|
530
|
-
it_should_behave_like "RR::Scenario"
|
531
|
-
|
532
|
-
it "sends block to the method" do
|
533
|
-
def @object.foobar(a, b)
|
534
|
-
yield(a, b)
|
535
|
-
end
|
536
|
-
|
537
|
-
@scenario.with(1, 2).implemented_by(@object.method(:foobar))
|
538
|
-
|
539
|
-
@object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
|
540
|
-
end
|
541
|
-
end
|
542
|
-
|
543
|
-
describe Scenario, "#exact_match?" do
|
544
|
-
it_should_behave_like "RR::Scenario"
|
545
|
-
|
546
|
-
it "returns false when no expectation set" do
|
547
|
-
@scenario.should_not be_exact_match()
|
548
|
-
@scenario.should_not be_exact_match(nil)
|
549
|
-
@scenario.should_not be_exact_match(Object.new)
|
550
|
-
@scenario.should_not be_exact_match(1, 2, 3)
|
551
|
-
end
|
552
|
-
|
553
|
-
it "returns false when arguments are not an exact match" do
|
554
|
-
@scenario.with(1, 2, 3)
|
555
|
-
@scenario.should_not be_exact_match(1, 2)
|
556
|
-
@scenario.should_not be_exact_match(1)
|
557
|
-
@scenario.should_not be_exact_match()
|
558
|
-
@scenario.should_not be_exact_match("does not match")
|
559
|
-
end
|
560
|
-
|
561
|
-
it "returns true when arguments are an exact match" do
|
562
|
-
@scenario.with(1, 2, 3)
|
563
|
-
@scenario.should be_exact_match(1, 2, 3)
|
564
|
-
end
|
565
|
-
end
|
566
|
-
|
567
|
-
describe Scenario, "#wildcard_match?" do
|
568
|
-
it_should_behave_like "RR::Scenario"
|
569
|
-
|
570
|
-
it "returns false when no expectation set" do
|
571
|
-
@scenario.should_not be_wildcard_match()
|
572
|
-
@scenario.should_not be_wildcard_match(nil)
|
573
|
-
@scenario.should_not be_wildcard_match(Object.new)
|
574
|
-
@scenario.should_not be_wildcard_match(1, 2, 3)
|
575
|
-
end
|
576
|
-
|
577
|
-
it "returns true when arguments are an exact match" do
|
578
|
-
@scenario.with(1, 2, 3)
|
579
|
-
@scenario.should be_wildcard_match(1, 2, 3)
|
580
|
-
@scenario.should_not be_wildcard_match(1, 2)
|
581
|
-
@scenario.should_not be_wildcard_match(1)
|
582
|
-
@scenario.should_not be_wildcard_match()
|
583
|
-
@scenario.should_not be_wildcard_match("does not match")
|
584
|
-
end
|
585
|
-
|
586
|
-
it "returns true when with_any_args" do
|
587
|
-
@scenario.with_any_args
|
588
|
-
|
589
|
-
@scenario.should be_wildcard_match(1, 2, 3)
|
590
|
-
@scenario.should be_wildcard_match(1, 2)
|
591
|
-
@scenario.should be_wildcard_match(1)
|
592
|
-
@scenario.should be_wildcard_match()
|
593
|
-
@scenario.should be_wildcard_match("does not match")
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
describe Scenario, "#attempt?" do
|
598
|
-
it_should_behave_like "RR::Scenario"
|
599
|
-
|
600
|
-
it "returns true when TimesCalledExpectation#attempt? is true" do
|
601
|
-
@scenario.with(1, 2, 3).twice
|
602
|
-
@scenario.call(@double, 1, 2, 3)
|
603
|
-
@scenario.times_called_expectation.should be_attempt
|
604
|
-
@scenario.should be_attempt
|
605
|
-
end
|
606
|
-
|
607
|
-
it "returns false when TimesCalledExpectation#attempt? is true" do
|
608
|
-
@scenario.with(1, 2, 3).twice
|
609
|
-
@scenario.call(@double, 1, 2, 3)
|
610
|
-
@scenario.call(@double, 1, 2, 3)
|
611
|
-
@scenario.times_called_expectation.should_not be_attempt
|
612
|
-
@scenario.should_not be_attempt
|
613
|
-
end
|
614
|
-
|
615
|
-
it "returns true when there is no Times Called expectation" do
|
616
|
-
@scenario.with(1, 2, 3)
|
617
|
-
@scenario.definition.times_matcher.should be_nil
|
618
|
-
@scenario.should be_attempt
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
|
-
describe Scenario, "#verify" do
|
623
|
-
it_should_behave_like "RR::Scenario"
|
624
|
-
|
625
|
-
it "verifies that times called expectation was met" do
|
626
|
-
@scenario.twice.returns {:return_value}
|
627
|
-
|
628
|
-
proc {@scenario.verify}.should raise_error(Errors::TimesCalledError)
|
629
|
-
@scenario.call(@double)
|
630
|
-
proc {@scenario.verify}.should raise_error(Errors::TimesCalledError)
|
631
|
-
@scenario.call(@double)
|
632
|
-
|
633
|
-
proc {@scenario.verify}.should_not raise_error
|
634
|
-
end
|
635
|
-
|
636
|
-
it "does not raise an error when there is no times called expectation" do
|
637
|
-
proc {@scenario.verify}.should_not raise_error
|
638
|
-
@scenario.call(@double)
|
639
|
-
proc {@scenario.verify}.should_not raise_error
|
640
|
-
@scenario.call(@double)
|
641
|
-
proc {@scenario.verify}.should_not raise_error
|
642
|
-
end
|
643
|
-
end
|
644
|
-
|
645
|
-
describe Scenario, "#terminal?" do
|
646
|
-
it_should_behave_like "RR::Scenario"
|
647
|
-
|
648
|
-
it "returns true when times_called_expectation's terminal? is true" do
|
649
|
-
@scenario.once
|
650
|
-
@scenario.times_called_expectation.should be_terminal
|
651
|
-
@scenario.should be_terminal
|
652
|
-
end
|
653
|
-
|
654
|
-
it "returns false when times_called_expectation's terminal? is false" do
|
655
|
-
@scenario.any_number_of_times
|
656
|
-
@scenario.times_called_expectation.should_not be_terminal
|
657
|
-
@scenario.should_not be_terminal
|
658
|
-
end
|
659
|
-
|
660
|
-
it "returns false when there is no times_matcher" do
|
661
|
-
@scenario.definition.times_matcher.should be_nil
|
662
|
-
@scenario.should_not be_terminal
|
663
|
-
end
|
664
|
-
end
|
665
|
-
|
666
|
-
describe Scenario, "#method_name" do
|
667
|
-
it_should_behave_like "RR::Scenario"
|
668
|
-
|
669
|
-
it "returns the Double's method_name" do
|
670
|
-
@double.method_name.should == :foobar
|
671
|
-
@scenario.method_name.should == :foobar
|
672
|
-
end
|
673
|
-
end
|
674
|
-
|
675
|
-
describe Scenario, "#expected_arguments" do
|
676
|
-
it_should_behave_like "RR::Scenario"
|
677
|
-
|
678
|
-
it "returns argument expectation's expected_arguments when there is a argument expectation" do
|
679
|
-
@scenario.with(1, 2)
|
680
|
-
@scenario.expected_arguments.should == [1, 2]
|
681
|
-
end
|
682
|
-
|
683
|
-
it "returns an empty array when there is no argument expectation" do
|
684
|
-
@scenario.argument_expectation.should be_nil
|
685
|
-
@scenario.expected_arguments.should == []
|
686
|
-
end
|
687
|
-
end
|
688
|
-
|
689
|
-
describe Scenario, "#formatted_name" do
|
690
|
-
it_should_behave_like "RR::Scenario"
|
691
|
-
|
692
|
-
it "renders the formatted name of the Scenario with no arguments" do
|
693
|
-
@scenario.formatted_name.should == "foobar()"
|
694
|
-
end
|
695
|
-
|
696
|
-
it "renders the formatted name of the Scenario with arguments" do
|
697
|
-
@scenario.with(1, 2)
|
698
|
-
@scenario.formatted_name.should == "foobar(1, 2)"
|
699
|
-
end
|
700
|
-
end
|
701
|
-
end
|