6 def infect_with_assertions pos_prefix, neg_prefix, skip_re, map = {}
7 Mini::Assertions.public_instance_methods(false).each do |meth|
12 meth.sub(/^assert/, pos_prefix.to_s)
14 meth.sub(/^refute/, neg_prefix.to_s)
17 next if new_name =~ skip_re
19 regexp, replacement = map.find { |re, _| new_name =~ re }
20 new_name.sub! regexp, replacement if replacement
22 # warn "%-22p -> %p %p" % [meth, new_name, regexp]
23 self.class_eval <<-EOM
24 def #{new_name} *args, &block
25 return Mini::Spec.current.#{meth}(*args, &self) if Proc === self
26 return Mini::Spec.current.#{meth}(args.first, self) if args.size == 1
27 return Mini::Spec.current.#{meth}(self, *args)
34 Object.infect_with_assertions(:must, :wont,
35 /^(must|wont)$|wont_(throw)|
36 must_(block|not?_|nothing|raise$)/x,
37 /(must_throw)s/ => '\1',
38 /(?!not)_same/ => '_be_same_as',
39 /_in_/ => '_be_within_',
41 /_includes/ => '_include',
42 /(must|wont)_(.*_of|nil|empty)/ => '\1_be_\2',
43 /must_raises/ => 'must_raise')
46 alias :must_be_close_to :must_be_within_delta
47 alias :wont_be_close_to :wont_be_within_delta
51 def describe desc, &block
52 cls = Class.new(Mini::Spec)
53 Object.const_set desc.to_s.split(/\W+/).map { |s| s.capitalize }.join, cls
55 cls.class_eval(&block)
59 class Mini::Spec < Mini::Test::TestCase
69 def self.before(type = :each, &block)
70 raise "unsupported before type: #{type}" unless type == :each
71 define_method :setup, &block
74 def self.after(type = :each, &block)
75 raise "unsupported after type: #{type}" unless type == :each
76 define_method :teardown, &block
79 def self.it desc, &block
80 define_method "test_#{desc.gsub(/\W+/, '_').downcase}", &block