hsume2-state_machine 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/CHANGELOG.rdoc +413 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +717 -0
  4. data/Rakefile +77 -0
  5. data/examples/AutoShop_state.png +0 -0
  6. data/examples/Car_state.png +0 -0
  7. data/examples/TrafficLight_state.png +0 -0
  8. data/examples/Vehicle_state.png +0 -0
  9. data/examples/auto_shop.rb +11 -0
  10. data/examples/car.rb +19 -0
  11. data/examples/merb-rest/controller.rb +51 -0
  12. data/examples/merb-rest/model.rb +28 -0
  13. data/examples/merb-rest/view_edit.html.erb +24 -0
  14. data/examples/merb-rest/view_index.html.erb +23 -0
  15. data/examples/merb-rest/view_new.html.erb +13 -0
  16. data/examples/merb-rest/view_show.html.erb +17 -0
  17. data/examples/rails-rest/controller.rb +43 -0
  18. data/examples/rails-rest/migration.rb +11 -0
  19. data/examples/rails-rest/model.rb +23 -0
  20. data/examples/rails-rest/view_edit.html.erb +25 -0
  21. data/examples/rails-rest/view_index.html.erb +23 -0
  22. data/examples/rails-rest/view_new.html.erb +14 -0
  23. data/examples/rails-rest/view_show.html.erb +17 -0
  24. data/examples/traffic_light.rb +7 -0
  25. data/examples/vehicle.rb +31 -0
  26. data/init.rb +1 -0
  27. data/lib/state_machine.rb +448 -0
  28. data/lib/state_machine/alternate_machine.rb +79 -0
  29. data/lib/state_machine/assertions.rb +36 -0
  30. data/lib/state_machine/branch.rb +224 -0
  31. data/lib/state_machine/callback.rb +236 -0
  32. data/lib/state_machine/condition_proxy.rb +94 -0
  33. data/lib/state_machine/error.rb +13 -0
  34. data/lib/state_machine/eval_helpers.rb +86 -0
  35. data/lib/state_machine/event.rb +304 -0
  36. data/lib/state_machine/event_collection.rb +139 -0
  37. data/lib/state_machine/extensions.rb +149 -0
  38. data/lib/state_machine/initializers.rb +4 -0
  39. data/lib/state_machine/initializers/merb.rb +1 -0
  40. data/lib/state_machine/initializers/rails.rb +25 -0
  41. data/lib/state_machine/integrations.rb +110 -0
  42. data/lib/state_machine/integrations/active_model.rb +502 -0
  43. data/lib/state_machine/integrations/active_model/locale.rb +11 -0
  44. data/lib/state_machine/integrations/active_model/observer.rb +45 -0
  45. data/lib/state_machine/integrations/active_model/versions.rb +31 -0
  46. data/lib/state_machine/integrations/active_record.rb +424 -0
  47. data/lib/state_machine/integrations/active_record/locale.rb +20 -0
  48. data/lib/state_machine/integrations/active_record/versions.rb +143 -0
  49. data/lib/state_machine/integrations/base.rb +91 -0
  50. data/lib/state_machine/integrations/data_mapper.rb +392 -0
  51. data/lib/state_machine/integrations/data_mapper/observer.rb +210 -0
  52. data/lib/state_machine/integrations/data_mapper/versions.rb +62 -0
  53. data/lib/state_machine/integrations/mongo_mapper.rb +272 -0
  54. data/lib/state_machine/integrations/mongo_mapper/locale.rb +4 -0
  55. data/lib/state_machine/integrations/mongo_mapper/versions.rb +110 -0
  56. data/lib/state_machine/integrations/mongoid.rb +357 -0
  57. data/lib/state_machine/integrations/mongoid/locale.rb +4 -0
  58. data/lib/state_machine/integrations/mongoid/versions.rb +18 -0
  59. data/lib/state_machine/integrations/sequel.rb +428 -0
  60. data/lib/state_machine/integrations/sequel/versions.rb +36 -0
  61. data/lib/state_machine/machine.rb +1873 -0
  62. data/lib/state_machine/machine_collection.rb +87 -0
  63. data/lib/state_machine/matcher.rb +123 -0
  64. data/lib/state_machine/matcher_helpers.rb +54 -0
  65. data/lib/state_machine/node_collection.rb +157 -0
  66. data/lib/state_machine/path.rb +120 -0
  67. data/lib/state_machine/path_collection.rb +90 -0
  68. data/lib/state_machine/state.rb +271 -0
  69. data/lib/state_machine/state_collection.rb +112 -0
  70. data/lib/state_machine/transition.rb +458 -0
  71. data/lib/state_machine/transition_collection.rb +244 -0
  72. data/lib/tasks/state_machine.rake +1 -0
  73. data/lib/tasks/state_machine.rb +27 -0
  74. data/test/files/en.yml +17 -0
  75. data/test/files/switch.rb +11 -0
  76. data/test/functional/alternate_state_machine_test.rb +122 -0
  77. data/test/functional/state_machine_test.rb +993 -0
  78. data/test/test_helper.rb +4 -0
  79. data/test/unit/assertions_test.rb +40 -0
  80. data/test/unit/branch_test.rb +890 -0
  81. data/test/unit/callback_test.rb +701 -0
  82. data/test/unit/condition_proxy_test.rb +328 -0
  83. data/test/unit/error_test.rb +43 -0
  84. data/test/unit/eval_helpers_test.rb +222 -0
  85. data/test/unit/event_collection_test.rb +358 -0
  86. data/test/unit/event_test.rb +985 -0
  87. data/test/unit/integrations/active_model_test.rb +1097 -0
  88. data/test/unit/integrations/active_record_test.rb +2021 -0
  89. data/test/unit/integrations/base_test.rb +99 -0
  90. data/test/unit/integrations/data_mapper_test.rb +1909 -0
  91. data/test/unit/integrations/mongo_mapper_test.rb +1611 -0
  92. data/test/unit/integrations/mongoid_test.rb +1591 -0
  93. data/test/unit/integrations/sequel_test.rb +1523 -0
  94. data/test/unit/integrations_test.rb +61 -0
  95. data/test/unit/invalid_event_test.rb +20 -0
  96. data/test/unit/invalid_parallel_transition_test.rb +18 -0
  97. data/test/unit/invalid_transition_test.rb +77 -0
  98. data/test/unit/machine_collection_test.rb +599 -0
  99. data/test/unit/machine_test.rb +3043 -0
  100. data/test/unit/matcher_helpers_test.rb +37 -0
  101. data/test/unit/matcher_test.rb +155 -0
  102. data/test/unit/node_collection_test.rb +217 -0
  103. data/test/unit/path_collection_test.rb +266 -0
  104. data/test/unit/path_test.rb +485 -0
  105. data/test/unit/state_collection_test.rb +310 -0
  106. data/test/unit/state_machine_test.rb +31 -0
  107. data/test/unit/state_test.rb +924 -0
  108. data/test/unit/transition_collection_test.rb +2102 -0
  109. data/test/unit/transition_test.rb +1541 -0
  110. metadata +207 -0
@@ -0,0 +1,328 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class Validateable
4
+ class << self
5
+ def validate(*args, &block)
6
+ args << block if block_given?
7
+ args
8
+ end
9
+ end
10
+ end
11
+
12
+ class ConditionProxyTest < Test::Unit::TestCase
13
+ def test_should_call_class_with_same_arguments
14
+ options = {}
15
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {})
16
+ validation = condition_proxy.validate(:name, options)
17
+
18
+ assert_equal [:name, options], validation
19
+ end
20
+
21
+ def test_should_pass_block_through_to_class
22
+ options = {}
23
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {})
24
+
25
+ proxy_block = lambda {}
26
+ validation = condition_proxy.validate(:name, options, &proxy_block)
27
+
28
+ assert_equal [:name, options, proxy_block], validation
29
+ end
30
+
31
+ def test_should_pass_object_into_proxy_condition
32
+ condition_args = []
33
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {|*args| condition_args = args})
34
+ options = condition_proxy.validate[0]
35
+
36
+ object = Validateable.new
37
+ options[:if].call(object)
38
+
39
+ assert_equal [object], condition_args
40
+ end
41
+
42
+ def test_should_evaluate_symbol_condition
43
+ klass = Class.new(Validateable) do
44
+ attr_accessor :callback_called
45
+
46
+ def callback
47
+ @callback_called = true
48
+ end
49
+ end
50
+
51
+ condition_proxy = StateMachine::ConditionProxy.new(klass, :callback)
52
+ options = condition_proxy.validate[0]
53
+
54
+ object = klass.new
55
+ options[:if].call(object)
56
+
57
+ assert object.callback_called
58
+ end
59
+
60
+ def test_should_evaluate_string_condition
61
+ klass = Class.new(Validateable) do
62
+ attr_accessor :callback_called
63
+ end
64
+
65
+ condition_proxy = StateMachine::ConditionProxy.new(klass, '@callback_called = true')
66
+ options = condition_proxy.validate[0]
67
+
68
+ object = klass.new
69
+ options[:if].call(object)
70
+
71
+ assert object.callback_called
72
+ end
73
+ end
74
+
75
+ class ConditionProxyWithoutConditionsTest < Test::Unit::TestCase
76
+ def setup
77
+ @proxy_result = nil
78
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {@proxy_result})
79
+
80
+ @object = Validateable.new
81
+ @options = condition_proxy.validate[0]
82
+ end
83
+
84
+ def test_should_have_options_configuration
85
+ assert_instance_of Hash, @options
86
+ end
87
+
88
+ def test_should_have_if_option
89
+ assert_not_nil @options[:if]
90
+ end
91
+
92
+ def test_should_be_false_if_proxy_condition_is_false
93
+ @proxy_result = false
94
+ assert !@options[:if].call(@object)
95
+ end
96
+
97
+ def test_should_be_true_if_proxy_condition_is_true
98
+ @proxy_result = true
99
+ assert @options[:if].call(@object)
100
+ end
101
+
102
+ def test_should_be_true_if_proxy_condition_is_not_true
103
+ @proxy_result = 1
104
+ assert @options[:if].call(@object)
105
+ end
106
+ end
107
+
108
+ class ConditionProxyWithIfConditionTest < Test::Unit::TestCase
109
+ def setup
110
+ @proxy_result = nil
111
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {@proxy_result})
112
+
113
+ @object = Validateable.new
114
+
115
+ @condition_result = nil
116
+ @options = condition_proxy.validate(:if => lambda {@condition_result})[0]
117
+ end
118
+
119
+ def test_should_have_if_option
120
+ assert_not_nil @options[:if]
121
+ end
122
+
123
+ def test_should_be_false_if_proxy_condition_is_false
124
+ @proxy_result = false
125
+ assert !@options[:if].call(@object)
126
+ end
127
+
128
+ def test_should_be_false_if_original_condition_is_false
129
+ @condition_result = false
130
+ assert !@options[:if].call(@object)
131
+ end
132
+
133
+ def test_should_be_true_if_proxy_and_original_condition_are_true
134
+ @proxy_result = true
135
+ @condition_result = true
136
+ assert @options[:if].call(@object)
137
+ end
138
+
139
+ def test_should_evaluate_symbol_condition
140
+ klass = Class.new(Validateable) do
141
+ attr_accessor :callback
142
+ end
143
+
144
+ condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
145
+ options = condition_proxy.validate(:if => :callback)[0]
146
+
147
+ object = klass.new
148
+ object.callback = false
149
+ assert !options[:if].call(object)
150
+
151
+ object.callback = true
152
+ assert options[:if].call(object)
153
+ end
154
+
155
+ def test_should_evaluate_string_condition
156
+ klass = Class.new(Validateable) do
157
+ attr_accessor :callback
158
+ end
159
+
160
+ condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
161
+ options = condition_proxy.validate(:if => '@callback')[0]
162
+
163
+ object = klass.new
164
+ object.callback = false
165
+ assert !options[:if].call(object)
166
+
167
+ object.callback = true
168
+ assert options[:if].call(object)
169
+ end
170
+ end
171
+
172
+ class ConditionProxyWithMultipleIfConditionsTest < Test::Unit::TestCase
173
+ def setup
174
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {true})
175
+
176
+ @object = Validateable.new
177
+
178
+ @first_condition_result = nil
179
+ @second_condition_result = nil
180
+ @options = condition_proxy.validate(:if => [lambda {@first_condition_result}, lambda {@second_condition_result}])[0]
181
+ end
182
+
183
+ def test_should_be_true_if_all_conditions_are_true
184
+ @first_condition_result = true
185
+ @second_condition_result = true
186
+ assert @options[:if].call(@object)
187
+ end
188
+
189
+ def test_should_be_false_if_any_condition_is_false
190
+ @first_condition_result = true
191
+ @second_condition_result = false
192
+ assert !@options[:if].call(@object)
193
+
194
+ @first_condition_result = false
195
+ @second_condition_result = true
196
+ assert !@options[:if].call(@object)
197
+ end
198
+ end
199
+
200
+ class ConditionProxyWithUnlessConditionTest < Test::Unit::TestCase
201
+ def setup
202
+ @proxy_result = nil
203
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {@proxy_result})
204
+
205
+ @object = Validateable.new
206
+
207
+ @condition_result = nil
208
+ @options = condition_proxy.validate(:unless => lambda {@condition_result})[0]
209
+ end
210
+
211
+ def test_should_have_if_option
212
+ assert_not_nil @options[:if]
213
+ end
214
+
215
+ def test_should_be_false_if_proxy_condition_is_false
216
+ @proxy_result = false
217
+ assert !@options[:if].call(@object)
218
+ end
219
+
220
+ def test_should_be_false_if_original_condition_is_true
221
+ @condition_result = true
222
+ assert !@options[:if].call(@object)
223
+ end
224
+
225
+ def test_should_be_true_if_proxy_is_true_and_original_condition_is_false
226
+ @proxy_result = true
227
+ @condition_result = false
228
+ assert @options[:if].call(@object)
229
+ end
230
+
231
+ def test_should_evaluate_symbol_condition
232
+ klass = Class.new(Validateable) do
233
+ attr_accessor :callback
234
+ end
235
+
236
+ condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
237
+ options = condition_proxy.validate(:unless => :callback)[0]
238
+
239
+ object = klass.new
240
+ object.callback = true
241
+ assert !options[:if].call(object)
242
+
243
+ object.callback = false
244
+ assert options[:if].call(object)
245
+ end
246
+
247
+ def test_should_evaluate_string_condition
248
+ klass = Class.new(Validateable) do
249
+ attr_accessor :callback
250
+ end
251
+
252
+ condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
253
+ options = condition_proxy.validate(:unless => '@callback')[0]
254
+
255
+ object = klass.new
256
+ object.callback = true
257
+ assert !options[:if].call(object)
258
+
259
+ object.callback = false
260
+ assert options[:if].call(object)
261
+ end
262
+ end
263
+
264
+ class ConditionProxyWithMultipleUnlessConditionsTest < Test::Unit::TestCase
265
+ def setup
266
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {true})
267
+
268
+ @object = Validateable.new
269
+
270
+ @first_condition_result = nil
271
+ @second_condition_result = nil
272
+ @options = condition_proxy.validate(:unless => [lambda {@first_condition_result}, lambda {@second_condition_result}])[0]
273
+ end
274
+
275
+ def test_should_be_true_if_all_conditions_are_false
276
+ @first_condition_result = false
277
+ @second_condition_result = false
278
+ assert @options[:if].call(@object)
279
+ end
280
+
281
+ def test_should_be_false_if_any_condition_is_true
282
+ @first_condition_result = true
283
+ @second_condition_result = false
284
+ assert !@options[:if].call(@object)
285
+
286
+ @first_condition_result = false
287
+ @second_condition_result = true
288
+ assert !@options[:if].call(@object)
289
+ end
290
+ end
291
+
292
+ class ConditionProxyWithIfAndUnlessConditionsTest < Test::Unit::TestCase
293
+ def setup
294
+ condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {true})
295
+
296
+ @object = Validateable.new
297
+
298
+ @if_condition_result = nil
299
+ @unless_condition_result = nil
300
+ @options = condition_proxy.validate(:if => lambda {@if_condition_result}, :unless => lambda {@unless_condition_result})[0]
301
+ end
302
+
303
+ def test_should_be_false_if_if_condition_is_false
304
+ @if_condition_result = false
305
+ @unless_condition_result = false
306
+ assert !@options[:if].call(@object)
307
+
308
+ @if_condition_result = false
309
+ @unless_condition_result = true
310
+ assert !@options[:if].call(@object)
311
+ end
312
+
313
+ def test_should_be_false_if_unless_condition_is_true
314
+ @if_condition_result = false
315
+ @unless_condition_result = true
316
+ assert !@options[:if].call(@object)
317
+
318
+ @if_condition_result = true
319
+ @unless_condition_result = true
320
+ assert !@options[:if].call(@object)
321
+ end
322
+
323
+ def test_should_be_true_if_if_condition_is_true_and_unless_condition_is_false
324
+ @if_condition_result = true
325
+ @unless_condition_result = false
326
+ assert @options[:if].call(@object)
327
+ end
328
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class ErrorByDefaultTest < Test::Unit::TestCase
4
+ def setup
5
+ @machine = StateMachine::Machine.new(Class.new)
6
+ @collection = StateMachine::NodeCollection.new(@machine)
7
+ end
8
+
9
+ def test_should_not_have_any_nodes
10
+ assert_equal 0, @collection.length
11
+ end
12
+
13
+ def test_should_have_a_machine
14
+ assert_equal @machine, @collection.machine
15
+ end
16
+
17
+ def test_should_index_by_name
18
+ @collection << object = Struct.new(:name).new(:parked)
19
+ assert_equal object, @collection[:parked]
20
+ end
21
+ end
22
+
23
+ class ErrorWithMessageTest < Test::Unit::TestCase
24
+ def setup
25
+ @machine = StateMachine::Machine.new(Class.new)
26
+ @collection = StateMachine::NodeCollection.new(@machine)
27
+ end
28
+
29
+ def test_should_raise_exception_if_invalid_option_specified
30
+ exception = assert_raise(ArgumentError) { StateMachine::NodeCollection.new(@machine, :invalid => true) }
31
+ assert_equal 'Invalid key(s): invalid', exception.message
32
+ end
33
+
34
+ def test_should_raise_exception_on_lookup_if_invalid_index_specified
35
+ exception = assert_raise(ArgumentError) { @collection[:something, :invalid] }
36
+ assert_equal 'Invalid index: :invalid', exception.message
37
+ end
38
+
39
+ def test_should_raise_exception_on_fetch_if_invalid_index_specified
40
+ exception = assert_raise(ArgumentError) { @collection.fetch(:something, :invalid) }
41
+ assert_equal 'Invalid index: :invalid', exception.message
42
+ end
43
+ end
@@ -0,0 +1,222 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class EvalHelpersBaseTest < Test::Unit::TestCase
4
+ include StateMachine::EvalHelpers
5
+
6
+ def default_test
7
+ end
8
+ end
9
+
10
+ class EvalHelpersTest < EvalHelpersBaseTest
11
+ def setup
12
+ @object = Object.new
13
+ end
14
+
15
+ def test_should_raise_exception_if_method_is_not_symbol_string_or_proc
16
+ exception = assert_raise(ArgumentError) { evaluate_method(@object, 1) }
17
+ assert_match /Methods must/, exception.message
18
+ end
19
+ end
20
+
21
+ class EvalHelpersSymbolTest < EvalHelpersBaseTest
22
+ def setup
23
+ class << (@object = Object.new)
24
+ def callback
25
+ true
26
+ end
27
+ end
28
+ end
29
+
30
+ def test_should_call_method_on_object_with_no_arguments
31
+ assert_equal true, evaluate_method(@object, :callback, 1, 2, 3)
32
+ end
33
+ end
34
+
35
+ class EvalHelpersSymbolWithArgumentsTest < EvalHelpersBaseTest
36
+ def setup
37
+ class << (@object = Object.new)
38
+ def callback(*args)
39
+ args
40
+ end
41
+ end
42
+ end
43
+
44
+ def test_should_call_method_with_all_arguments
45
+ assert_equal [1, 2, 3], evaluate_method(@object, :callback, 1, 2, 3)
46
+ end
47
+ end
48
+
49
+ class EvalHelpersSymbolWithBlockTest < EvalHelpersBaseTest
50
+ def setup
51
+ class << (@object = Object.new)
52
+ def callback
53
+ yield
54
+ end
55
+ end
56
+ end
57
+
58
+ def test_should_call_method_on_object_with_block
59
+ assert_equal true, evaluate_method(@object, :callback) { true }
60
+ end
61
+ end
62
+
63
+ class EvalHelpersSymbolWithArgumentsAndBlockTest < EvalHelpersBaseTest
64
+ def setup
65
+ class << (@object = Object.new)
66
+ def callback(*args)
67
+ args << yield
68
+ end
69
+ end
70
+ end
71
+
72
+ def test_should_call_method_on_object_with_all_arguments_and_block
73
+ assert_equal [1, 2, 3, true], evaluate_method(@object, :callback, 1, 2, 3) { true }
74
+ end
75
+ end
76
+
77
+ class EvalHelpersSymbolTaintedMethodTest < EvalHelpersBaseTest
78
+ def setup
79
+ class << (@object = Object.new)
80
+ def callback
81
+ true
82
+ end
83
+
84
+ taint
85
+ end
86
+ end
87
+
88
+ def test_should_not_raise_security_error
89
+ assert_nothing_raised { evaluate_method(@object, :callback, 1, 2, 3) }
90
+ end
91
+ end
92
+
93
+ class EvalHelpersStringTest < EvalHelpersBaseTest
94
+ def setup
95
+ @object = Object.new
96
+ end
97
+
98
+ def test_should_evaluate_string
99
+ assert_equal 1, evaluate_method(@object, '1')
100
+ end
101
+
102
+ def test_should_evaluate_string_within_object_context
103
+ @object.instance_variable_set('@value', 1)
104
+ assert_equal 1, evaluate_method(@object, '@value')
105
+ end
106
+
107
+ def test_should_ignore_additional_arguments
108
+ assert_equal 1, evaluate_method(@object, '1', 2, 3, 4)
109
+ end
110
+ end
111
+
112
+ class EvalHelpersStringWithBlockTest < EvalHelpersBaseTest
113
+ def setup
114
+ @object = Object.new
115
+ end
116
+
117
+ def test_should_call_method_on_object_with_block
118
+ assert_equal 1, evaluate_method(@object, 'yield') { 1 }
119
+ end
120
+ end
121
+
122
+ class EvalHelpersProcTest < EvalHelpersBaseTest
123
+ def setup
124
+ @object = Object.new
125
+ @proc = lambda {|obj| obj}
126
+ end
127
+
128
+ def test_should_call_proc_with_object_as_argument
129
+ assert_equal @object, evaluate_method(@object, @proc, 1, 2, 3)
130
+ end
131
+ end
132
+
133
+ class EvalHelpersProcWithoutArgumentsTest < EvalHelpersBaseTest
134
+ def setup
135
+ @object = Object.new
136
+ @proc = lambda {|*args| args}
137
+ class << @proc
138
+ def arity
139
+ 0
140
+ end
141
+ end
142
+ end
143
+
144
+ def test_should_call_proc_with_no_arguments
145
+ assert_equal [], evaluate_method(@object, @proc, 1, 2, 3)
146
+ end
147
+ end
148
+
149
+ class EvalHelpersProcWithArgumentsTest < EvalHelpersBaseTest
150
+ def setup
151
+ @object = Object.new
152
+ @proc = lambda {|*args| args}
153
+ end
154
+
155
+ def test_should_call_method_with_all_arguments
156
+ assert_equal [@object, 1, 2, 3], evaluate_method(@object, @proc, 1, 2, 3)
157
+ end
158
+ end
159
+
160
+ class EvalHelpersProcWithBlockTest < EvalHelpersBaseTest
161
+ def setup
162
+ @object = Object.new
163
+ @proc = lambda {|obj, block| block.call}
164
+ end
165
+
166
+ def test_should_call_method_on_object_with_block
167
+ assert_equal true, evaluate_method(@object, @proc, 1, 2, 3) { true }
168
+ end
169
+ end
170
+
171
+ class EvalHelpersProcWithBlockWithoutArgumentsTest < EvalHelpersBaseTest
172
+ def setup
173
+ @object = Object.new
174
+ @proc = lambda {|*args| args}
175
+ class << @proc
176
+ def arity
177
+ 0
178
+ end
179
+ end
180
+ end
181
+
182
+ def test_should_call_proc_without_arguments
183
+ block = lambda { true }
184
+ assert_equal [], evaluate_method(@object, @proc, 1, 2, 3, &block)
185
+ end
186
+ end
187
+
188
+ class EvalHelpersProcWithBlockWithoutObjectTest < EvalHelpersBaseTest
189
+ def setup
190
+ @object = Object.new
191
+ @proc = lambda {|block| [block]}
192
+ end
193
+
194
+ def test_should_call_proc_with_block_only
195
+ block = lambda { true }
196
+ assert_equal [block], evaluate_method(@object, @proc, 1, 2, 3, &block)
197
+ end
198
+ end
199
+
200
+ class EvalHelpersProcBlockAndImplicitArgumentsTest < EvalHelpersBaseTest
201
+ def setup
202
+ @object = Object.new
203
+ @proc = lambda {|*args| args}
204
+ end
205
+
206
+ def test_should_call_method_on_object_with_all_arguments_and_block
207
+ block = lambda { true }
208
+ assert_equal [@object, 1, 2, 3, block], evaluate_method(@object, @proc, 1, 2, 3, &block)
209
+ end
210
+ end
211
+
212
+ class EvalHelpersProcBlockAndExplicitArgumentsTest < EvalHelpersBaseTest
213
+ def setup
214
+ @object = Object.new
215
+ @proc = lambda {|object, arg1, arg2, arg3, block| [object, arg1, arg2, arg3, block]}
216
+ end
217
+
218
+ def test_should_call_method_on_object_with_all_arguments_and_block
219
+ block = lambda { true }
220
+ assert_equal [@object, 1, 2, 3, block], evaluate_method(@object, @proc, 1, 2, 3, &block)
221
+ end
222
+ end