rr 0.3.11 → 0.4.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.
Files changed (150) hide show
  1. data/CHANGES +8 -3
  2. data/README +130 -39
  3. data/Rakefile +6 -5
  4. data/lib/rr.rb +8 -8
  5. data/lib/rr/adapters/rr_methods.rb +228 -0
  6. data/lib/rr/adapters/rspec.rb +1 -1
  7. data/lib/rr/adapters/test_unit.rb +1 -1
  8. data/lib/rr/double.rb +294 -89
  9. data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
  10. data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
  11. data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
  12. data/lib/rr/double_insertion.rb +132 -0
  13. data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
  14. data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
  15. data/lib/rr/errors/argument_equality_error.rb +3 -3
  16. data/lib/rr/errors/rr_error.rb +13 -13
  17. data/lib/rr/errors/scenario_definition_error.rb +3 -3
  18. data/lib/rr/errors/scenario_not_found_error.rb +3 -3
  19. data/lib/rr/errors/scenario_order_error.rb +3 -3
  20. data/lib/rr/errors/times_called_error.rb +3 -3
  21. data/lib/rr/expectations/any_argument_expectation.rb +1 -1
  22. data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
  23. data/lib/rr/expectations/times_called_expectation.rb +1 -1
  24. data/lib/rr/hash_with_object_id_key.rb +1 -1
  25. data/lib/rr/space.rb +40 -40
  26. data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
  27. data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
  28. data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
  29. data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
  30. data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
  31. data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
  32. data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
  33. data/lib/rr/times_called_matchers/terminal.rb +16 -16
  34. data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
  35. data/spec/core_spec_suite.rb +18 -0
  36. data/{examples → spec}/environment_fixture_setup.rb +0 -1
  37. data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
  38. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  39. data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
  40. data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
  41. data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
  42. data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
  43. data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
  44. data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
  45. data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
  46. data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
  47. data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
  48. data/spec/rr/double/double_insertion_spec.rb +66 -0
  49. data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
  50. data/spec/rr/double_creator_spec.rb +454 -0
  51. data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
  52. data/spec/rr/double_method_proxy_spec.rb +71 -0
  53. data/spec/rr/double_spec.rb +654 -0
  54. data/spec/rr/errors/rr_error_spec.rb +65 -0
  55. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  56. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
  57. data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
  58. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
  59. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
  60. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
  61. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
  62. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
  63. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
  64. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
  65. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
  66. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
  67. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
  68. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
  69. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
  70. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
  71. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
  72. data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
  73. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
  74. data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
  75. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  76. data/spec/rr/space/space_create_spec.rb +278 -0
  77. data/spec/rr/space/space_helper.rb +7 -0
  78. data/spec/rr/space/space_register_spec.rb +32 -0
  79. data/spec/rr/space/space_reset_spec.rb +131 -0
  80. data/spec/rr/space/space_spec.rb +32 -0
  81. data/spec/rr/space/space_verify_spec.rb +181 -0
  82. data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
  83. data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
  84. data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
  85. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  86. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  87. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  88. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  89. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  90. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  91. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  92. data/spec/rspec_spec_suite.rb +16 -0
  93. data/spec/spec_helper.rb +9 -0
  94. data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
  95. data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
  96. metadata +93 -93
  97. data/examples/core_example_suite.rb +0 -31
  98. data/examples/example_helper.rb +0 -9
  99. data/examples/rr/double/double_bind_example.rb +0 -70
  100. data/examples/rr/double/double_dispatching_example.rb +0 -236
  101. data/examples/rr/double/double_example.rb +0 -66
  102. data/examples/rr/double/double_has_original_method_example.rb +0 -56
  103. data/examples/rr/double/double_register_scenario_example.rb +0 -24
  104. data/examples/rr/double/double_reset_example.rb +0 -89
  105. data/examples/rr/double/double_verify_example.rb +0 -23
  106. data/examples/rr/errors/rr_error_example.rb +0 -65
  107. data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
  108. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
  109. data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
  110. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
  111. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
  112. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
  113. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
  114. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
  115. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
  116. data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
  117. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
  118. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
  119. data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
  120. data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
  121. data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
  122. data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
  123. data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
  124. data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
  125. data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
  126. data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
  127. data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
  128. data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
  129. data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
  130. data/examples/rr/rspec/rspec_usage_example.rb +0 -65
  131. data/examples/rr/scenario_creator_example.rb +0 -459
  132. data/examples/rr/scenario_example.rb +0 -701
  133. data/examples/rr/scenario_method_proxy_example.rb +0 -71
  134. data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
  135. data/examples/rr/space/space_create_example.rb +0 -278
  136. data/examples/rr/space/space_example.rb +0 -29
  137. data/examples/rr/space/space_helper.rb +0 -7
  138. data/examples/rr/space/space_register_example.rb +0 -32
  139. data/examples/rr/space/space_reset_example.rb +0 -120
  140. data/examples/rr/space/space_verify_example.rb +0 -169
  141. data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
  142. data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
  143. data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
  144. data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
  145. data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
  146. data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
  147. data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
  148. data/examples/rspec_example_suite.rb +0 -25
  149. data/lib/rr/extensions/instance_methods.rb +0 -228
  150. data/lib/rr/scenario.rb +0 -337
@@ -1,363 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- module Extensions
5
- describe InstanceMethods, "#mock" do
6
- it_should_behave_like "RR::Extensions::InstanceMethods"
7
-
8
- before do
9
- @subject = Object.new
10
- class << @subject
11
- def foobar(*args)
12
- :original_value
13
- end
14
- end
15
- end
16
-
17
- it "returns a ScenarioCreator when passed no arguments" do
18
- mock.should be_instance_of(ScenarioCreator)
19
- end
20
-
21
- it "sets up the RR mock call chain" do
22
- should create_mock_call_chain(mock(@subject))
23
- end
24
-
25
- it "#rr_mock sets up the RR mock call chain" do
26
- should create_mock_call_chain(rr_mock(@subject))
27
- end
28
-
29
- it "creates a mock Scenario for method when passed a second argument" do
30
- should create_scenario_with_method_name(mock(@subject, :foobar))
31
- end
32
-
33
- it "creates a mock Scenario for method when passed a second argument with rr_mock" do
34
- should create_scenario_with_method_name(rr_mock(@subject, :foobar))
35
- end
36
-
37
- it "raises error if passed a method name and a block" do
38
- proc do
39
- mock(@object, :foobar) {}
40
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
41
- end
42
-
43
- def create_scenario_with_method_name(scenario)
44
- scenario.with(1, 2) {:baz}
45
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
46
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
47
- scenario.argument_expectation.expected_arguments.should == [1, 2]
48
-
49
- @subject.foobar(1, 2).should == :baz
50
- end
51
-
52
- def create_mock_call_chain(creator)
53
- scenario = creator.foobar(1, 2) {:baz}
54
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
55
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
56
- scenario.argument_expectation.expected_arguments.should == [1, 2]
57
-
58
- @subject.foobar(1, 2).should == :baz
59
- end
60
- end
61
-
62
- describe InstanceMethods, "#stub" do
63
- it_should_behave_like "RR::Extensions::InstanceMethods"
64
-
65
- before do
66
- @subject = Object.new
67
- class << @subject
68
- def foobar(*args)
69
- :original_value
70
- end
71
- end
72
- end
73
-
74
- it "returns a ScenarioCreator when passed no arguments" do
75
- stub.should be_instance_of(ScenarioCreator)
76
- end
77
-
78
- it "sets up the RR stub call chain" do
79
- should create_stub_call_chain(stub(@subject))
80
- end
81
-
82
- it "#rr_stub sets up the RR stub call chain" do
83
- should create_stub_call_chain(rr_stub(@subject))
84
- end
85
-
86
- it "creates a stub Scenario for method when passed a second argument" do
87
- should create_scenario_with_method_name(stub(@subject, :foobar))
88
- end
89
-
90
- it "#rr_stub creates a stub Scenario for method when passed a second argument" do
91
- should create_scenario_with_method_name(rr_stub(@subject, :foobar))
92
- end
93
-
94
- it "raises error if passed a method name and a block" do
95
- proc do
96
- stub(@object, :foobar) {}
97
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
98
- end
99
-
100
- def create_scenario_with_method_name(scenario)
101
- scenario.with(1, 2) {:baz}
102
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
103
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
104
- @subject.foobar(1, 2).should == :baz
105
- end
106
-
107
- def create_stub_call_chain(creator)
108
- scenario = creator.foobar(1, 2) {:baz}
109
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
110
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
111
- @subject.foobar(1, 2).should == :baz
112
- end
113
- end
114
-
115
- describe InstanceMethods, "#probe and #mock" do
116
- it_should_behave_like "RR::Extensions::InstanceMethods"
117
-
118
- before do
119
- @subject = Object.new
120
- class << @subject
121
- def foobar(*args)
122
- :original_value
123
- end
124
- end
125
- end
126
-
127
- it "#probe returns a ScenarioCreator when passed no arguments" do
128
- probe.should be_instance_of(ScenarioCreator)
129
- end
130
-
131
- it "#probe sets up the RR probe call chain" do
132
- should create_mock_probe_call_chain(mock.probe(@subject))
133
- end
134
-
135
- it "#rr_probe sets up the RR probe call chain" do
136
- should create_mock_probe_call_chain(rr_mock.probe(@subject))
137
- end
138
-
139
- it "#mock_probe sets up the RR probe call chain" do
140
- should create_mock_probe_call_chain(mock.probe(@subject))
141
- end
142
-
143
- it "#rr_mock_probe sets up the RR probe call chain with rr_probe" do
144
- should create_mock_probe_call_chain(rr_mock.probe(@subject))
145
- end
146
-
147
- it "#probe creates a mock Scenario for method when passed a second argument" do
148
- should create_scenario_with_method_name(mock.probe(@subject, :foobar))
149
- end
150
-
151
- it "#rr_probe creates a mock Scenario for method when passed a second argument with rr_mock" do
152
- should create_scenario_with_method_name(rr_probe.mock(@subject, :foobar))
153
- end
154
-
155
- it "#mock_probe creates a mock Scenario for method when passed a second argument" do
156
- should create_scenario_with_method_name(mock.probe(@subject, :foobar))
157
- end
158
-
159
- it "#rr_mock_probe creates a mock Scenario for method when passed a second argument with rr_mock" do
160
- should create_scenario_with_method_name(rr_mock.probe(@subject, :foobar))
161
- end
162
-
163
- it "raises error if passed a method name and a block" do
164
- proc do
165
- mock.probe(@object, :foobar) {}
166
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
167
- end
168
-
169
- def create_scenario_with_method_name(scenario)
170
- scenario.with(1, 2)
171
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
172
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
173
- scenario.argument_expectation.expected_arguments.should == [1, 2]
174
-
175
- @subject.foobar(1, 2).should == :original_value
176
- end
177
-
178
- def create_mock_probe_call_chain(creator)
179
- scenario = creator.foobar(1, 2)
180
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
181
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
182
- scenario.argument_expectation.expected_arguments.should == [1, 2]
183
-
184
- @subject.foobar(1, 2).should == :original_value
185
- end
186
- end
187
-
188
- describe InstanceMethods, "#stub and #probe" do
189
- it_should_behave_like "RR::Extensions::InstanceMethods"
190
-
191
- before do
192
- @subject = Object.new
193
- class << @subject
194
- def foobar(*args)
195
- :original_value
196
- end
197
- end
198
- end
199
-
200
- it "returns a ScenarioCreator when passed no arguments" do
201
- stub.probe.should be_instance_of(ScenarioCreator)
202
- end
203
-
204
- it "sets up the RR probe call chain" do
205
- should create_stub_probe_call_chain(stub.probe(@subject))
206
- end
207
-
208
- it "sets up the RR probe call chain" do
209
- should create_stub_probe_call_chain(rr_stub.probe(@subject))
210
- end
211
-
212
- it "#stub.probe creates a stub Scenario for method when passed a second argument" do
213
- should create_scenario_with_method_name(stub.probe(@subject, :foobar))
214
- end
215
-
216
- it "#rr_stub.probe creates a stub Scenario for method when passed a second argument with rr_stub" do
217
- should create_scenario_with_method_name(rr_stub.probe(@subject, :foobar))
218
- end
219
-
220
- it "raises error if passed a method name and a block" do
221
- proc do
222
- stub.probe(@object, :foobar) {}
223
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
224
- end
225
-
226
- def create_scenario_with_method_name(scenario)
227
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
228
- scenario.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
229
-
230
- @subject.foobar(:something).should == :original_value
231
- end
232
-
233
- def create_stub_probe_call_chain(creator)
234
- scenario = creator.foobar
235
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
236
- scenario.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
237
-
238
- @subject.foobar(1, 2).should == :original_value
239
- end
240
- end
241
-
242
- describe InstanceMethods, "#do_not_allow" do
243
- it_should_behave_like "RR::Extensions::InstanceMethods"
244
-
245
- before do
246
- @subject = Object.new
247
- class << @subject
248
- def foobar(*args)
249
- :original_value
250
- end
251
- end
252
- end
253
-
254
- it "returns a ScenarioCreator when passed no arguments" do
255
- do_not_allow.should be_instance_of(ScenarioCreator)
256
- end
257
-
258
- it "sets up the RR do_not_allow call chain" do
259
- should create_do_not_allow_call_chain(do_not_call(@subject))
260
- should create_do_not_allow_call_chain(rr_do_not_call(@subject))
261
- should create_do_not_allow_call_chain(dont_call(@subject))
262
- should create_do_not_allow_call_chain(rr_dont_call(@subject))
263
- should create_do_not_allow_call_chain(do_not_allow(@subject))
264
- should create_do_not_allow_call_chain(rr_do_not_allow(@subject))
265
- should create_do_not_allow_call_chain(dont_allow(@subject))
266
- should create_do_not_allow_call_chain(rr_dont_allow(@subject))
267
- end
268
-
269
- it "creates a mock Scenario for method when passed a second argument" do
270
- should create_scenario_with_method_name(do_not_call(@subject, :foobar))
271
- should create_scenario_with_method_name(rr_do_not_call(@subject, :foobar))
272
- should create_scenario_with_method_name(dont_call(@subject, :foobar))
273
- should create_scenario_with_method_name(rr_dont_call(@subject, :foobar))
274
- should create_scenario_with_method_name(do_not_allow(@subject, :foobar))
275
- should create_scenario_with_method_name(rr_do_not_allow(@subject, :foobar))
276
- should create_scenario_with_method_name(dont_allow(@subject, :foobar))
277
- should create_scenario_with_method_name(rr_dont_allow(@subject, :foobar))
278
- end
279
-
280
- it "raises error if passed a method name and a block" do
281
- proc do
282
- do_not_allow(@object, :foobar) {}
283
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
284
- end
285
-
286
- def create_scenario_with_method_name(scenario)
287
- scenario.with(1, 2)
288
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
289
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
290
- scenario.argument_expectation.expected_arguments.should == [1, 2]
291
-
292
- proc do
293
- @subject.foobar(1, 2)
294
- end.should raise_error(Errors::TimesCalledError)
295
- reset
296
- nil
297
- end
298
-
299
- def create_do_not_allow_call_chain(creator)
300
- scenario = creator.foobar(1, 2)
301
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
302
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
303
- scenario.argument_expectation.expected_arguments.should == [1, 2]
304
-
305
- proc do
306
- @subject.foobar(1, 2)
307
- end.should raise_error(Errors::TimesCalledError)
308
- reset
309
- nil
310
- end
311
- end
312
-
313
- describe ScenarioCreator, "#instance_of and #mock" do
314
- before do
315
- @klass = Class.new
316
- end
317
-
318
- it "returns a ScenarioCreator when passed no arguments" do
319
- instance_of.instance_of.should be_instance_of(ScenarioCreator)
320
- end
321
-
322
- it "sets up the RR instance_of call chain" do
323
- should create_instance_of_call_chain(instance_of.mock(@klass))
324
- end
325
-
326
- it "#rr_instance_of sets up the RR instance_of call chain" do
327
- should create_instance_of_call_chain(rr_instance_of.mock(@klass))
328
- end
329
-
330
- it "creates a instance_of Scenario for method when passed a second argument" do
331
- should create_scenario_with_method_name(instance_of.mock(@klass, :foobar))
332
- end
333
-
334
- it "creates a instance_of Scenario for method when passed a second argument with rr_instance_of" do
335
- should create_scenario_with_method_name(rr_instance_of.mock(@klass, :foobar))
336
- end
337
-
338
- it "raises error if passed a method name and a block" do
339
- proc do
340
- instance_of.mock(@klass, :foobar) {}
341
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
342
- end
343
-
344
- def create_scenario_with_method_name(scenario)
345
- scenario.with(1, 2) {:baz}
346
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
347
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
348
- scenario.argument_expectation.expected_arguments.should == [1, 2]
349
-
350
- @klass.new.foobar(1, 2).should == :baz
351
- end
352
-
353
- def create_instance_of_call_chain(creator)
354
- scenario = creator.foobar(1, 2) {:baz}
355
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
356
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
357
- scenario.argument_expectation.expected_arguments.should == [1, 2]
358
-
359
- @klass.new.foobar(1, 2).should == :baz
360
- end
361
- end
362
- end
363
- end
@@ -1,11 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- module Extensions
5
- describe InstanceMethods, :shared => true do
6
- before do
7
- extend RR::Extensions::InstanceMethods
8
- end
9
- end
10
- end
11
- end
@@ -1,122 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- module Extensions
5
- describe InstanceMethods, " space example", :shared => true do
6
- it_should_behave_like "RR::Extensions::InstanceMethods"
7
- before do
8
- @old_space = Space.instance
9
-
10
- @space = Space.new
11
- Space.instance = @space
12
- @object1 = Object.new
13
- @object2 = Object.new
14
- @method_name = :foobar
15
- end
16
-
17
- after do
18
- Space.instance = @old_space
19
- end
20
- end
21
-
22
- describe InstanceMethods, "#verify" do
23
- it_should_behave_like "RR::Extensions::InstanceMethods space example"
24
-
25
- it "#verify verifies and deletes the doubles" do
26
- should verify_all_doubles {verify}
27
- end
28
-
29
- it "#rr_verify verifies and deletes the doubles" do
30
- should verify_all_doubles {rr_verify}
31
- end
32
-
33
- def verify_all_doubles
34
- double1 = @space.double(@object1, @method_name)
35
- double1_verify_calls = 0
36
- double1_reset_calls = 0
37
- (class << double1; self; end).class_eval do
38
- define_method(:verify) do ||
39
- double1_verify_calls += 1
40
- end
41
- define_method(:reset) do ||
42
- double1_reset_calls += 1
43
- end
44
- end
45
- double2 = @space.double(@object2, @method_name)
46
- double2_verify_calls = 0
47
- double2_reset_calls = 0
48
- (class << double2; self; end).class_eval do
49
- define_method(:verify) do ||
50
- double2_verify_calls += 1
51
- end
52
- define_method(:reset) do ||
53
- double2_reset_calls += 1
54
- end
55
- end
56
-
57
- yield
58
- double1_verify_calls.should == 1
59
- double2_verify_calls.should == 1
60
- double1_reset_calls.should == 1
61
- double1_reset_calls.should == 1
62
- end
63
- end
64
-
65
- describe InstanceMethods, "#reset" do
66
- it_should_behave_like "RR::Extensions::InstanceMethods space example"
67
-
68
- it "#reset removes the ordered scenarios" do
69
- should remove_ordered_scenarios {reset}
70
- end
71
-
72
- it "#rr_reset removes the ordered scenarios" do
73
- should remove_ordered_scenarios {rr_reset}
74
- end
75
-
76
- it "#reset resets all doubles" do
77
- should reset_all_doubles {reset}
78
- end
79
-
80
- it "#rr_reset resets all doubles" do
81
- should reset_all_doubles {rr_reset}
82
- end
83
-
84
- def remove_ordered_scenarios
85
- double1 = @space.double(@object1, :foobar1)
86
- double2 = @space.double(@object1, :foobar2)
87
-
88
- scenario1 = @space.scenario(double1)
89
- scenario2 = @space.scenario(double2)
90
-
91
- scenario1.ordered
92
- scenario2.ordered
93
-
94
- @space.ordered_scenarios.should_not be_empty
95
-
96
- yield
97
- @space.ordered_scenarios.should be_empty
98
- end
99
-
100
- def reset_all_doubles
101
- double1 = @space.double(@object1, @method_name)
102
- double1_reset_calls = 0
103
- (class << double1; self; end).class_eval do
104
- define_method(:reset) do ||
105
- double1_reset_calls += 1
106
- end
107
- end
108
- double2 = @space.double(@object2, @method_name)
109
- double2_reset_calls = 0
110
- (class << double2; self; end).class_eval do
111
- define_method(:reset) do ||
112
- double2_reset_calls += 1
113
- end
114
- end
115
-
116
- yield
117
- double1_reset_calls.should == 1
118
- double2_reset_calls.should == 1
119
- end
120
- end
121
- end
122
- end