@@ -531,6 +531,10 @@ def find_registered_app_path(app_name)
531
531
# (it is the opposite of setup)
532
532
attr_reader :cleanup_handlers
533
533
534
+ # @return [Array<#call>] list of objects called just before runtime. This is
535
+ # called during test setup as well
536
+ attr_reader :prepare_handlers
537
+
534
538
# @return [Array<#call>] list of objects called when the app shuts down,
535
539
# that is when the plan is being tore down but before cleanup. This is
536
540
# called during test teardown as well
@@ -912,6 +916,7 @@ def initialize(plan: ExecutablePlan.new)
912
916
@require_handlers = [ ]
913
917
@clear_models_handlers = [ ]
914
918
@cleanup_handlers = [ ]
919
+ @prepare_handlers = [ ]
915
920
@shutdown_handlers = [ ]
916
921
@controllers = [ ]
917
922
@action_handlers = [ ]
@@ -1152,9 +1157,14 @@ def prepare
1152
1157
end
1153
1158
end
1154
1159
1160
+ run_prepare_blocks
1155
1161
call_plugins ( :prepare , self )
1156
1162
end
1157
1163
1164
+ def run_prepare_blocks
1165
+ prepare_handlers . each ( &:call )
1166
+ end
1167
+
1158
1168
# The inverse of #prepare. It gets called either at the end of #run or
1159
1169
# at the end of #setup if there is an error during loading
1160
1170
def shutdown
@@ -1244,6 +1254,20 @@ def on_clear_models(user: false, &block)
1244
1254
add_lifecyle_hook ( clear_models_handlers , block , user : user )
1245
1255
end
1246
1256
1257
+ # Registers a callback to prepare to run
1258
+ #
1259
+ # This is called just before actual execution. Do things here that
1260
+ # are required only at runtime, and not to load/interpret models
1261
+ #
1262
+ # Most operations done here must be undone in a shutdown block
1263
+ def on_prepare ( user : false , &block )
1264
+ unless block
1265
+ raise ArgumentError , "missing expected block argument"
1266
+ end
1267
+
1268
+ add_lifecyle_hook ( prepare_handlers , block , user : user )
1269
+ end
1270
+
1247
1271
# Registers a callback to perform cleanup just after an execution
1248
1272
#
1249
1273
# This is called just after plan teardown. Unlike all the other
0 commit comments