@@ -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
@@ -791,6 +795,7 @@ def initialize(plan: ExecutablePlan.new)
791
795
@require_handlers = [ ]
792
796
@clear_models_handlers = [ ]
793
797
@cleanup_handlers = [ ]
798
+ @prepare_handlers = [ ]
794
799
@shutdown_handlers = [ ]
795
800
@controllers = [ ]
796
801
@action_handlers = [ ]
@@ -1031,9 +1036,14 @@ def prepare
1031
1036
end
1032
1037
end
1033
1038
1039
+ run_prepare_blocks
1034
1040
call_plugins ( :prepare , self )
1035
1041
end
1036
1042
1043
+ def run_prepare_blocks
1044
+ prepare_handlers . each ( &:call )
1045
+ end
1046
+
1037
1047
# The inverse of #prepare. It gets called either at the end of #run or
1038
1048
# at the end of #setup if there is an error during loading
1039
1049
def shutdown
@@ -1123,6 +1133,20 @@ def on_clear_models(user: false, &block)
1123
1133
add_lifecyle_hook ( clear_models_handlers , block , user : user )
1124
1134
end
1125
1135
1136
+ # Registers a callback to prepare to run
1137
+ #
1138
+ # This is called just before actual execution. Do things here that
1139
+ # are required only at runtime, and not to load/interpret models
1140
+ #
1141
+ # Most operations done here must be undone in a shutdown block
1142
+ def on_prepare ( user : false , &block )
1143
+ unless block
1144
+ raise ArgumentError , "missing expected block argument"
1145
+ end
1146
+
1147
+ add_lifecyle_hook ( prepare_handlers , block , user : user )
1148
+ end
1149
+
1126
1150
# Registers a callback to perform cleanup just after an execution
1127
1151
#
1128
1152
# This is called just after plan teardown. Unlike all the other
0 commit comments