minilab 1.0.0-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +2 -0
- data/CHANGES +2 -0
- data/LICENSE +19 -0
- data/README +107 -0
- data/Rakefile +145 -0
- data/config/environment.rb +15 -0
- data/config/objects.yml +22 -0
- data/lib/analog_io.rb +30 -0
- data/lib/digital_auxport_io.rb +49 -0
- data/lib/digital_configuration.rb +66 -0
- data/lib/digital_port_io.rb +68 -0
- data/lib/extension/extconf.rb +4 -0
- data/lib/extension/minilab_hardware.c +235 -0
- data/lib/extension/minilab_hardware.so +0 -0
- data/lib/library_translator.rb +48 -0
- data/lib/minilab.rb +149 -0
- data/lib/minilab_context.rb +39 -0
- data/lib/result_verifier.rb +14 -0
- data/test/integration/analog_input_output_test.rb +43 -0
- data/test/integration/connect_to_hardware_test.rb +13 -0
- data/test/integration/digital_input_output_test.rb +114 -0
- data/test/integration/integration_test.rb +53 -0
- data/test/integration/require_minilab_test.rb +9 -0
- data/test/system/analog_input.test +3 -0
- data/test/system/analog_output.test +37 -0
- data/test/system/digital_port_input.test +5 -0
- data/test/system/digital_port_output.test +39 -0
- data/test/system/digital_port_read_byte.test +26 -0
- data/test/system/digital_screw_terminals_input.test +2 -0
- data/test/system/digital_screw_terminals_output.test +11 -0
- data/test/system/minilab_driver.rb +85 -0
- data/test/test_helper.rb +11 -0
- data/test/unit/analog_io_test.rb +87 -0
- data/test/unit/digital_auxport_io_test.rb +114 -0
- data/test/unit/digital_configuration_test.rb +136 -0
- data/test/unit/digital_port_io_test.rb +117 -0
- data/test/unit/library_translator_test.rb +100 -0
- data/test/unit/minilab_context_test.rb +82 -0
- data/test/unit/minilab_hardware_test.rb +83 -0
- data/test/unit/minilab_test.rb +131 -0
- data/test/unit/result_verifier_test.rb +33 -0
- data/vendor/behaviors/lib/behaviors.rb +50 -0
- data/vendor/behaviors/tasks/behaviors_tasks.rake +140 -0
- data/vendor/behaviors/test/behaviors_tasks_test.rb +71 -0
- data/vendor/behaviors/test/behaviors_test.rb +50 -0
- data/vendor/behaviors/test/tasks_test/Rakefile +16 -0
- data/vendor/behaviors/test/tasks_test/doc/behaviors.html +55 -0
- data/vendor/behaviors/test/tasks_test/lib/user.rb +2 -0
- data/vendor/behaviors/test/tasks_test/test/user_test.rb +17 -0
- data/vendor/constructor/Rakefile +44 -0
- data/vendor/constructor/config/environment.rb +12 -0
- data/vendor/constructor/lib/constructor.rb +132 -0
- data/vendor/constructor/test/constructor_test.rb +366 -0
- data/vendor/constructor/test/helper.rb +3 -0
- data/vendor/diy/README +26 -0
- data/vendor/diy/Rakefile +18 -0
- data/vendor/diy/lib/constructor.rb +114 -0
- data/vendor/diy/lib/diy.rb +329 -0
- data/vendor/diy/proto/context.rb +117 -0
- data/vendor/diy/proto/context.yml +20 -0
- data/vendor/diy/test/diy_test.rb +370 -0
- data/vendor/diy/test/files/broken_construction.yml +7 -0
- data/vendor/diy/test/files/cat/cat.rb +4 -0
- data/vendor/diy/test/files/cat/extra_conflict.yml +5 -0
- data/vendor/diy/test/files/cat/heritage.rb +2 -0
- data/vendor/diy/test/files/cat/needs_input.yml +3 -0
- data/vendor/diy/test/files/cat/the_cat_lineage.rb +1 -0
- data/vendor/diy/test/files/dog/dog_model.rb +4 -0
- data/vendor/diy/test/files/dog/dog_presenter.rb +4 -0
- data/vendor/diy/test/files/dog/dog_view.rb +2 -0
- data/vendor/diy/test/files/dog/file_resolver.rb +2 -0
- data/vendor/diy/test/files/dog/other_thing.rb +2 -0
- data/vendor/diy/test/files/dog/simple.yml +11 -0
- data/vendor/diy/test/files/donkey/foo.rb +8 -0
- data/vendor/diy/test/files/donkey/foo/bar/qux.rb +7 -0
- data/vendor/diy/test/files/fud/objects.yml +13 -0
- data/vendor/diy/test/files/fud/toy.rb +15 -0
- data/vendor/diy/test/files/gnu/objects.yml +14 -0
- data/vendor/diy/test/files/gnu/thinger.rb +8 -0
- data/vendor/diy/test/files/goat/base.rb +8 -0
- data/vendor/diy/test/files/goat/can.rb +6 -0
- data/vendor/diy/test/files/goat/goat.rb +6 -0
- data/vendor/diy/test/files/goat/objects.yml +12 -0
- data/vendor/diy/test/files/goat/paper.rb +6 -0
- data/vendor/diy/test/files/goat/plane.rb +8 -0
- data/vendor/diy/test/files/goat/shirt.rb +6 -0
- data/vendor/diy/test/files/goat/wings.rb +8 -0
- data/vendor/diy/test/files/horse/holder_thing.rb +4 -0
- data/vendor/diy/test/files/horse/objects.yml +7 -0
- data/vendor/diy/test/files/yak/core_model.rb +4 -0
- data/vendor/diy/test/files/yak/core_presenter.rb +4 -0
- data/vendor/diy/test/files/yak/core_view.rb +1 -0
- data/vendor/diy/test/files/yak/data_source.rb +1 -0
- data/vendor/diy/test/files/yak/fringe_model.rb +4 -0
- data/vendor/diy/test/files/yak/fringe_presenter.rb +4 -0
- data/vendor/diy/test/files/yak/fringe_view.rb +1 -0
- data/vendor/diy/test/files/yak/my_objects.yml +21 -0
- data/vendor/diy/test/test_helper.rb +40 -0
- data/vendor/hardmock/CHANGES +8 -0
- data/vendor/hardmock/LICENSE +7 -0
- data/vendor/hardmock/README +48 -0
- data/vendor/hardmock/Rakefile +100 -0
- data/vendor/hardmock/TODO +7 -0
- data/vendor/hardmock/config/environment.rb +12 -0
- data/vendor/hardmock/homepage/demo.rb +21 -0
- data/vendor/hardmock/homepage/hardmock_sample.png +0 -0
- data/vendor/hardmock/homepage/index.html +65 -0
- data/vendor/hardmock/init.rb +3 -0
- data/vendor/hardmock/lib/hardmock.rb +634 -0
- data/vendor/hardmock/lib/method_cleanout.rb +14 -0
- data/vendor/hardmock/rcov.rake +18 -0
- data/vendor/hardmock/test/functional/assert_error_test.rb +52 -0
- data/vendor/hardmock/test/functional/auto_verify_test.rb +192 -0
- data/vendor/hardmock/test/functional/direct_mock_usage_test.rb +396 -0
- data/vendor/hardmock/test/functional/hardmock_test.rb +380 -0
- data/vendor/hardmock/test/test_helper.rb +23 -0
- data/vendor/hardmock/test/unit/expectation_builder_test.rb +18 -0
- data/vendor/hardmock/test/unit/expector_test.rb +56 -0
- data/vendor/hardmock/test/unit/method_cleanout_test.rb +35 -0
- data/vendor/hardmock/test/unit/mock_control_test.rb +172 -0
- data/vendor/hardmock/test/unit/mock_test.rb +273 -0
- data/vendor/hardmock/test/unit/simple_expectation_test.rb +345 -0
- data/vendor/hardmock/test/unit/trapper_test.rb +60 -0
- data/vendor/hardmock/test/unit/verify_error_test.rb +34 -0
- data/vendor/systir/systir.rb +403 -0
- data/vendor/systir/test/unit/ui/xml/testrunner.rb +192 -0
- data/vendor/systir/test/unit/ui/xml/xmltestrunner.xslt +109 -0
- metadata +235 -0
@@ -0,0 +1,380 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'hardmock'
|
3
|
+
class HardmockTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# HELPERS
|
13
|
+
#
|
14
|
+
|
15
|
+
def assert_mock_exists(name)
|
16
|
+
assert_not_nil @all_mocks, "@all_mocks not here yet"
|
17
|
+
mo = @all_mocks[name]
|
18
|
+
assert_not_nil mo, "Mock '#{name}' not in @all_mocks"
|
19
|
+
assert_kind_of Mock, mo, "Wrong type of object, wanted a Mock"
|
20
|
+
assert_equal name.to_s, mo._name, "Mock '#{name}' had wrong name"
|
21
|
+
ivar = self.instance_variable_get("@#{name}")
|
22
|
+
assert_not_nil ivar, "Mock '#{name}' not set as ivar"
|
23
|
+
assert_same mo, ivar, "Mock '#{name}' ivar not same as instance in @all_mocks"
|
24
|
+
assert_same @main_mock_control, mo._control, "Mock '#{name}' doesn't share the main mock control"
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# TESTS
|
29
|
+
#
|
30
|
+
|
31
|
+
def test_create_mock_and_create_mocks
|
32
|
+
assert_nil @main_mock_control, "@main_mock_control not expected yet"
|
33
|
+
|
34
|
+
h = create_mock :donkey
|
35
|
+
assert_equal [ :donkey ], h.keys
|
36
|
+
assert_not_nil @main_mock_control, "@main_mock_control should be here"
|
37
|
+
|
38
|
+
assert_mock_exists :donkey
|
39
|
+
assert_same @donkey, h[:donkey]
|
40
|
+
|
41
|
+
assert_equal [ :donkey ], @all_mocks.keys, "Wrong keyset for @all_mocks"
|
42
|
+
|
43
|
+
h2 = create_mocks :cat, 'dog' # symbol/string indifference at this level
|
44
|
+
assert_equal [:cat,:dog].to_set, h2.keys.to_set, "Wrong keyset for second hash"
|
45
|
+
assert_equal [:cat,:dog,:donkey].to_set, @all_mocks.keys.to_set, "@all_mocks wrong"
|
46
|
+
|
47
|
+
assert_mock_exists :cat
|
48
|
+
assert_same @cat, h2[:cat]
|
49
|
+
assert_mock_exists :dog
|
50
|
+
assert_same @dog, h2[:dog]
|
51
|
+
|
52
|
+
assert_mock_exists :donkey
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_expect
|
56
|
+
assert_nil @order, "Should be no @order yet"
|
57
|
+
create_mock :order
|
58
|
+
assert_not_nil @order, "@order should be built"
|
59
|
+
|
60
|
+
# Setup an expectation
|
61
|
+
@order.expects.update_stuff :key1 => 'val1', :key2 => 'val2'
|
62
|
+
|
63
|
+
# Use the mock
|
64
|
+
@order.update_stuff :key1 => 'val1', :key2 => 'val2'
|
65
|
+
|
66
|
+
# Verify
|
67
|
+
verify_mocks
|
68
|
+
|
69
|
+
# See that it's ok to do it again
|
70
|
+
verify_mocks
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_typical_multi_mock_use
|
74
|
+
create_mocks :order_builder, :order, :customer
|
75
|
+
|
76
|
+
@order_builder.expects.create_new_order.returns @order
|
77
|
+
@customer.expects.account_number.returns(1234)
|
78
|
+
@order.expects.account_no = 1234
|
79
|
+
@order.expects.save!
|
80
|
+
|
81
|
+
# Run "the code"
|
82
|
+
o = @order_builder.create_new_order
|
83
|
+
o.account_no = @customer.account_number
|
84
|
+
o.save!
|
85
|
+
|
86
|
+
verify_mocks
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_typical_multi_mock_use_out_of_order
|
90
|
+
create_mocks :order_builder, :order, :customer
|
91
|
+
|
92
|
+
@order_builder.expects.create_new_order.returns @order
|
93
|
+
@customer.expects.account_number.returns(1234)
|
94
|
+
@order.expects.account_no = 1234
|
95
|
+
@order.expects.save!
|
96
|
+
|
97
|
+
# Run "the code"
|
98
|
+
o = @order_builder.create_new_order
|
99
|
+
err = assert_raise ExpectationError do
|
100
|
+
o.save!
|
101
|
+
end
|
102
|
+
assert_match(/wrong object/i, err.message)
|
103
|
+
assert_match(/order.save!/i, err.message)
|
104
|
+
assert_match(/customer.account_number/i, err.message)
|
105
|
+
|
106
|
+
assert_error VerifyError, /unmet expectations/i do
|
107
|
+
verify_mocks
|
108
|
+
end
|
109
|
+
|
110
|
+
# Appease the verifier
|
111
|
+
@order.account_no = 1234
|
112
|
+
@order.save!
|
113
|
+
end
|
114
|
+
|
115
|
+
class UserPresenter
|
116
|
+
def initialize(args)
|
117
|
+
view = args[:view]
|
118
|
+
model = args[:model]
|
119
|
+
model.when :data_changes do
|
120
|
+
view.user_name = model.user_name
|
121
|
+
end
|
122
|
+
view.when :user_edited do
|
123
|
+
model.user_name = view.user_name
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_mvp_usage_pattern
|
129
|
+
mox = create_mocks :model, :view
|
130
|
+
|
131
|
+
data_change = @model.expects.when(:data_changes) { |evt,block| block }
|
132
|
+
user_edit = @view.expects.when(:user_edited) { |evt,block| block }
|
133
|
+
|
134
|
+
UserPresenter.new mox
|
135
|
+
|
136
|
+
# Expect user name transfer from model to view
|
137
|
+
@model.expects.user_name.returns 'Da Croz'
|
138
|
+
@view.expects.user_name = 'Da Croz'
|
139
|
+
# Trigger data change event in model
|
140
|
+
data_change.block_value.call
|
141
|
+
|
142
|
+
# Expect user name transfer from view to model
|
143
|
+
@view.expects.user_name.returns '6:8'
|
144
|
+
@model.expects.user_name = '6:8'
|
145
|
+
# Trigger edit event in view
|
146
|
+
user_edit.block_value.call
|
147
|
+
|
148
|
+
verify_mocks
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_verify_mocks_repeated_anger
|
152
|
+
mox = create_mocks :model, :view
|
153
|
+
data_change = @model.expects.when(:data_changes) { |evt,block| block }
|
154
|
+
user_edit = @view.expects.when(:user_edited) { |evt,block| block }
|
155
|
+
UserPresenter.new mox
|
156
|
+
|
157
|
+
# Expect user name transfer from model to view
|
158
|
+
@model.expects.user_name.returns 'Da Croz'
|
159
|
+
@view.expects.user_name = 'Da Croz'
|
160
|
+
|
161
|
+
assert_error ExpectationError, /model.monkey_wrench/i do
|
162
|
+
@model.monkey_wrench
|
163
|
+
end
|
164
|
+
|
165
|
+
# This should raise because of unmet expectations
|
166
|
+
assert_error VerifyError, /unmet expectations/i, /user_name/i do
|
167
|
+
verify_mocks
|
168
|
+
end
|
169
|
+
|
170
|
+
# See that the non-forced verification remains quiet
|
171
|
+
assert_nothing_raised VerifyError do
|
172
|
+
verify_mocks(false)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Finish meeting expectations and see good verification behavior
|
176
|
+
@view.user_name = "Da Croz"
|
177
|
+
verify_mocks
|
178
|
+
|
179
|
+
@model.expects.never_gonna_happen
|
180
|
+
|
181
|
+
assert_error VerifyError, /unmet expectations/i, /never_gonna_happen/i do
|
182
|
+
verify_mocks
|
183
|
+
end
|
184
|
+
|
185
|
+
# Appease the verifier
|
186
|
+
@model.never_gonna_happen
|
187
|
+
end
|
188
|
+
|
189
|
+
class UserPresenterBroken
|
190
|
+
def initialize(args)
|
191
|
+
view = args[:view]
|
192
|
+
model = args[:model]
|
193
|
+
model.when :data_changes do
|
194
|
+
view.user_name = model.user_name
|
195
|
+
end
|
196
|
+
# no view stuff, will break appropriately
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_mvp_usage_with_failures_in_constructor
|
201
|
+
mox = create_mocks :model, :view
|
202
|
+
|
203
|
+
data_change = @model.expects.when(:data_changes) { |evt,block| block }
|
204
|
+
user_edit = @view.expects.when(:user_edited) { |evt,block| block }
|
205
|
+
|
206
|
+
UserPresenterBroken.new mox
|
207
|
+
|
208
|
+
err = assert_raise VerifyError do
|
209
|
+
verify_mocks
|
210
|
+
end
|
211
|
+
assert_match(/unmet expectations/i, err.message)
|
212
|
+
assert_match(/view.when\(:user_edited\)/i, err.message)
|
213
|
+
|
214
|
+
assert_error VerifyError, /unmet expectations/i do
|
215
|
+
verify_mocks
|
216
|
+
end
|
217
|
+
|
218
|
+
# Appease the verifier
|
219
|
+
@view.when(:user_edited)
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_mvp_usage_pattern_with_convenience_trap
|
224
|
+
mox = create_mocks :model, :view
|
225
|
+
|
226
|
+
data_change = @model.trap.when(:data_changes)
|
227
|
+
user_edit = @view.trap.when(:user_edited)
|
228
|
+
|
229
|
+
UserPresenter.new mox
|
230
|
+
|
231
|
+
# Expect user name transfer from model to view
|
232
|
+
@model.expects.user_name.returns 'Da Croz'
|
233
|
+
@view.expects.user_name = 'Da Croz'
|
234
|
+
# Trigger data change event in model
|
235
|
+
data_change.trigger
|
236
|
+
|
237
|
+
# Expect user name transfer from view to model
|
238
|
+
@view.expects.user_name.returns '6:8'
|
239
|
+
@model.expects.user_name = '6:8'
|
240
|
+
# Trigger edit event in view
|
241
|
+
user_edit.trigger
|
242
|
+
|
243
|
+
verify_mocks
|
244
|
+
end
|
245
|
+
|
246
|
+
class Grinder
|
247
|
+
def initialize(objects)
|
248
|
+
@chute = objects[:chute]
|
249
|
+
@bucket = objects[:bucket]
|
250
|
+
@blade = objects[:blade]
|
251
|
+
end
|
252
|
+
|
253
|
+
def grind(slot)
|
254
|
+
@chute.each_bean(slot) do |bean|
|
255
|
+
@bucket << @blade.chop(bean)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_internal_iteration_usage
|
261
|
+
grinder = Grinder.new create_mocks(:blade, :chute, :bucket)
|
262
|
+
|
263
|
+
# Style 1: assertions on method args is done explicitly in block
|
264
|
+
@chute.expects.each_bean { |slot,block|
|
265
|
+
assert_equal :side_slot, slot, "Wrong slot"
|
266
|
+
block.call :bean1
|
267
|
+
block.call :bean2
|
268
|
+
}
|
269
|
+
|
270
|
+
@blade.expects.chop(:bean1).returns(:grounds1)
|
271
|
+
@bucket.expects('<<', :grounds1)
|
272
|
+
|
273
|
+
@blade.expects.chop(:bean2).returns(:grounds2)
|
274
|
+
@bucket.expects('<<', :grounds2)
|
275
|
+
|
276
|
+
# Run "the code"
|
277
|
+
grinder.grind(:side_slot)
|
278
|
+
|
279
|
+
verify_mocks
|
280
|
+
|
281
|
+
# Style 2: assertions on method arguments done implicitly in the expectation code
|
282
|
+
@chute.expects.each_bean(:main_slot) { |slot,block|
|
283
|
+
block.call :bean3
|
284
|
+
}
|
285
|
+
@blade.expects.chop(:bean3).returns(:grounds3)
|
286
|
+
@bucket.expects('<<', :grounds3)
|
287
|
+
grinder.grind :main_slot
|
288
|
+
verify_mocks
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_internal_iteration_using_yield
|
292
|
+
grinder = Grinder.new create_mocks(:blade, :chute, :bucket)
|
293
|
+
|
294
|
+
@chute.expects.each_bean(:side_slot).yields :bean1, :bean2
|
295
|
+
|
296
|
+
@blade.expects.chop(:bean1).returns(:grounds1)
|
297
|
+
@bucket.expects('<<', :grounds1)
|
298
|
+
|
299
|
+
@blade.expects.chop(:bean2).returns(:grounds2)
|
300
|
+
@bucket.expects('<<', :grounds2)
|
301
|
+
|
302
|
+
grinder.grind :side_slot
|
303
|
+
|
304
|
+
verify_mocks
|
305
|
+
end
|
306
|
+
|
307
|
+
class HurtLocker
|
308
|
+
attr_reader :caught
|
309
|
+
def initialize(opts)
|
310
|
+
@locker = opts[:locker]
|
311
|
+
@store = opts[:store]
|
312
|
+
end
|
313
|
+
|
314
|
+
def do_the_thing(area,data)
|
315
|
+
@locker.with_lock(area) do
|
316
|
+
@store.eat(data)
|
317
|
+
end
|
318
|
+
rescue => oops
|
319
|
+
@caught = oops
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_internal_locking_scenario
|
324
|
+
hurt = HurtLocker.new create_mocks(:locker, :store)
|
325
|
+
|
326
|
+
@locker.expects.with_lock(:main).yields
|
327
|
+
@store.expects.eat("some info")
|
328
|
+
|
329
|
+
hurt.do_the_thing(:main, "some info")
|
330
|
+
|
331
|
+
verify_mocks
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_internal_locking_scenario_with_inner_error
|
335
|
+
hurt = HurtLocker.new create_mocks(:locker, :store)
|
336
|
+
err = StandardError.new('fmshooop')
|
337
|
+
@locker.expects.with_lock(:main).yields
|
338
|
+
@store.expects.eat("some info").raises(err)
|
339
|
+
|
340
|
+
hurt.do_the_thing(:main, "some info")
|
341
|
+
|
342
|
+
assert_same err, hurt.caught, "Expected that error to be handled internally"
|
343
|
+
verify_mocks
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_returning_false_actually_returns_false_and_not_nil
|
347
|
+
create_mock :car
|
348
|
+
@car.expects.ignition_on?.returns(true)
|
349
|
+
assert_equal true, @car.ignition_on?, "Should be true"
|
350
|
+
@car.expects.ignition_on?.returns(false)
|
351
|
+
assert_equal false, @car.ignition_on?, "Should be false"
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_should_be_able_to_mock_some_methods_inherited_from_object
|
355
|
+
target_methods = %w|id clone display dup eql? ==|
|
356
|
+
create_mock :foo
|
357
|
+
target_methods.each do |m|
|
358
|
+
eval %{@foo.expects(m, "some stuff")}
|
359
|
+
eval %{@foo.#{m} "some stuff"}
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_should_support_expect_as_an_alias_for_expects
|
364
|
+
create_mock :foo
|
365
|
+
@foo.expect.boomboom
|
366
|
+
@foo.boomboom
|
367
|
+
verify_mocks
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_should_not_raise_expectation_errors_for_some_methods_defined_on_object
|
371
|
+
create_mock :foo
|
372
|
+
@foo.method(:inspect)
|
373
|
+
@foo.inspect
|
374
|
+
@foo.to_s
|
375
|
+
@foo.instance_variables
|
376
|
+
@foo.instance_eval("")
|
377
|
+
verify_mocks
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
here = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$: << here
|
3
|
+
|
4
|
+
require "#{here}/../config/environment"
|
5
|
+
require 'test/unit'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'logger'
|
8
|
+
require 'find'
|
9
|
+
require 'yaml'
|
10
|
+
require 'set'
|
11
|
+
require 'ostruct'
|
12
|
+
|
13
|
+
class Test::Unit::TestCase
|
14
|
+
include FileUtils
|
15
|
+
|
16
|
+
def poll(time_limit)
|
17
|
+
(time_limit * 10).to_i.times do
|
18
|
+
return true if yield
|
19
|
+
sleep 0.1
|
20
|
+
end
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'hardmock'
|
3
|
+
|
4
|
+
class ExpectationBuilderTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_build_expectation
|
7
|
+
builder = ExpectationBuilder.new
|
8
|
+
|
9
|
+
ex = builder.build_expectation( :stuff => 'inside' )
|
10
|
+
assert_not_nil ex, "Didn't build an expectation"
|
11
|
+
assert_kind_of SimpleExpectation, ex, "Wrong type!"
|
12
|
+
|
13
|
+
# Shhhh... fragile, yes, whatever. The functional tests do the
|
14
|
+
# real testing of this anyway
|
15
|
+
assert_equal({:stuff => 'inside'}, ex.instance_variable_get('@options'), "Hash not sent to SimpleExpectation constructor")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'hardmock'
|
3
|
+
|
4
|
+
class ExpectorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class MyControl
|
7
|
+
attr_reader :added
|
8
|
+
def add_expectation(expectation)
|
9
|
+
@added ||= []
|
10
|
+
@added << expectation
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ExpBuilder
|
15
|
+
attr_reader :options
|
16
|
+
def build_expectation(options)
|
17
|
+
@options = options
|
18
|
+
"dummy expectation"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def try_it_with(method_name)
|
23
|
+
mock = Object.new
|
24
|
+
mock_control = MyControl.new
|
25
|
+
builder = ExpBuilder.new
|
26
|
+
|
27
|
+
exp = Expector.new(mock, mock_control, builder)
|
28
|
+
output = exp.send(method_name,:with, 1, 'sauce')
|
29
|
+
|
30
|
+
assert_same mock, builder.options[:mock]
|
31
|
+
assert_equal method_name, builder.options[:method].to_s
|
32
|
+
assert_equal [:with,1,'sauce'], builder.options[:arguments]
|
33
|
+
assert_nil builder.options[:block]
|
34
|
+
assert_equal [ "dummy expectation" ], mock_control.added,
|
35
|
+
"Wrong expectation added to control"
|
36
|
+
|
37
|
+
assert_equal "dummy expectation", output, "Expectation should have been returned"
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# TESTS
|
42
|
+
#
|
43
|
+
def test_method_missing
|
44
|
+
try_it_with 'wonder_bread'
|
45
|
+
try_it_with 'whatever'
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_methods_that_wont_trigger_method_missing
|
49
|
+
mock = Object.new
|
50
|
+
mock_control = MyControl.new
|
51
|
+
builder = ExpBuilder.new
|
52
|
+
|
53
|
+
exp = Expector.new(mock, mock_control, builder)
|
54
|
+
assert_equal mock, exp.instance_eval("@mock")
|
55
|
+
end
|
56
|
+
end
|