lib/minitest/spec.rb in minitest-2.5.0 vs lib/minitest/spec.rb in minitest-2.5.1
- old
+ new
@@ -86,25 +86,46 @@
# See: register_spec_type and spec_type
TYPES = [[//, MiniTest::Spec]]
##
- # Register a new type of spec that matches the spec's description. Eg:
+ # Register a new type of spec that matches the spec's description.
+ # This method can take either a Regexp and a spec class or a spec
+ # class and a block that takes the description and returns true if
+ # it matches.
#
- # register_spec_plugin(/Controller$/, MiniTest::Spec::Rails)
+ # Eg:
+ #
+ # register_spec_type(/Controller$/, MiniTest::Spec::Rails)
+ #
+ # or:
+ #
+ # register_spec_type(MiniTest::Spec::RailsModel) do |desc|
+ # desc.superclass == ActiveRecord::Base
+ # end
- def self.register_spec_type matcher, klass
+ def self.register_spec_type(*args, &block)
+ if block then
+ matcher, klass = block, args.first
+ else
+ matcher, klass = *args
+ end
TYPES.unshift [matcher, klass]
end
##
# Figure out the spec class to use based on a spec's description. Eg:
#
# spec_type("BlahController") # => MiniTest::Spec::Rails
def self.spec_type desc
- desc = desc.to_s
- TYPES.find { |re, klass| re === desc }.last
+ TYPES.find { |matcher, klass|
+ if matcher.respond_to? :call then
+ matcher.call desc
+ else
+ matcher === desc.to_s
+ end
+ }.last
end
@@describe_stack = []
def self.describe_stack # :nodoc:
@@describe_stack