@@ -98,6 +98,14 @@ def self.after_run &block
98
98
@@after_run << block
99
99
end
100
100
101
+ ##
102
+ # Register a plugin to be used. Does NOT require / load it.
103
+
104
+ def self . register_plugin name_or_mod
105
+ self . extensions << name_or_mod
106
+ nil
107
+ end
108
+
101
109
def self . load_plugins # :nodoc:
102
110
return unless defined? Gem
103
111
@@ -115,9 +123,20 @@ def self.load_plugins # :nodoc:
115
123
end
116
124
117
125
def self . init_plugins options # :nodoc:
118
- self . extensions . each do |name |
119
- msg = "plugin_#{ name } _init"
120
- send msg , options if self . respond_to? msg
126
+ self . extensions . each do |mod_or_meth |
127
+ case mod_or_meth
128
+ when Symbol , String then
129
+ name = mod_or_meth
130
+ msg = "plugin_#{ name } _init"
131
+ next unless self . respond_to? msg
132
+ send msg , options
133
+ when Module then
134
+ recv = mod_or_meth
135
+ next unless recv . respond_to? :minitest_plugin_init
136
+ recv . minitest_plugin_init options
137
+ else
138
+ raise ArgumentError , "blahblah %p" % [ mod_or_meth ]
139
+ end
121
140
end
122
141
end
123
142
@@ -185,9 +204,19 @@ def self.process_args args = [] # :nodoc:
185
204
opts . separator ""
186
205
opts . separator "Known extensions: #{ extensions . join ( ", " ) } "
187
206
188
- extensions . each do |meth |
189
- msg = "plugin_#{ meth } _options"
190
- send msg , opts , options if self . respond_to? ( msg )
207
+ extensions . each do |mod_or_meth |
208
+ case mod_or_meth
209
+ when Symbol , String then
210
+ meth = mod_or_meth
211
+ msg = "plugin_#{ meth } _options"
212
+ send msg , opts , options if respond_to? ( msg )
213
+ when Module
214
+ recv = mod_or_meth
215
+ next unless recv . respond_to? :minitest_plugin_options
216
+ recv . minitest_plugin_options opts , options
217
+ else
218
+ raise ArgumentError , "blahblah %p" % [ mod_or_meth ]
219
+ end
191
220
end
192
221
end
193
222
0 commit comments