Skip to content

Commit 2c5f1b7

Browse files
committed
+ Added Minitest.register_plugin.
+ Extended plugin system to work with modules/classes for opt-out plugins. [git-p4: depot-paths = "//src/minitest/dev/": change = 14160]
1 parent 0a1289f commit 2c5f1b7

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

lib/minitest.rb

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ def self.after_run &block
9898
@@after_run << block
9999
end
100100

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+
101109
def self.load_plugins # :nodoc:
102110
return unless defined? Gem
103111

@@ -115,9 +123,20 @@ def self.load_plugins # :nodoc:
115123
end
116124

117125
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
121140
end
122141
end
123142

@@ -185,9 +204,19 @@ def self.process_args args = [] # :nodoc:
185204
opts.separator ""
186205
opts.separator "Known extensions: #{extensions.join(", ")}"
187206

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
191220
end
192221
end
193222

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy