Class: Module
Instance Method Summary collapse
-
#classes(type = Object) ⇒ Object
:nodoc:.
-
#infect_an_assertion(meth, new_name, dont_flip = false) ⇒ Object
:nodoc:.
-
#infect_with_assertions(pos_prefix, neg_prefix, skip_re, dont_flip_re = /\c0/, map = {}) ⇒ Object
Create your own expectations from MiniTest::Assertions using a flexible set of rules.
Instance Method Details
#classes(type = Object) ⇒ Object
:nodoc:
82 83 84 85 86 |
# File 'lib/minitest/spec.rb', line 82 def classes type = Object # :nodoc: constants.map { |n| const_get n }.find_all { |c| c.class == Class and type > c } - [self] end |
#infect_an_assertion(meth, new_name, dont_flip = false) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/minitest/spec.rb', line 6 def infect_an_assertion meth, new_name, dont_flip = false # :nodoc: # warn "%-22p -> %p %p" % [meth, new_name, dont_flip] self.class_eval <<-EOM def #{new_name} *args, &block return MiniTest::Spec.current.#{meth}(*args, &self) if Proc === self return MiniTest::Spec.current.#{meth}(args.first, self) if args.size == 1 unless #{!!dont_flip} return MiniTest::Spec.current.#{meth}(self, *args) end EOM end |
#infect_with_assertions(pos_prefix, neg_prefix, skip_re, dont_flip_re = /\c0/, map = {}) ⇒ Object
Create your own expectations from MiniTest::Assertions using a flexible set of rules. If you don’t like must/wont, then this method is your friend. For an example of its usage see the bottom of minitest/spec.rb.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/minitest/spec.rb', line 25 def infect_with_assertions(pos_prefix, neg_prefix, skip_re, dont_flip_re = /\c0/, map = {}) MiniTest::Assertions.public_instance_methods(false).sort.each do |meth| meth = meth.to_s new_name = case meth when /^assert/ then meth.sub(/^assert/, pos_prefix.to_s) when /^refute/ then meth.sub(/^refute/, neg_prefix.to_s) end next unless new_name next if new_name =~ skip_re regexp, replacement = map.find { |re, _| new_name =~ re } new_name.sub! regexp, replacement if replacement puts "\n##\n# :method: #{new_name}\n# See MiniTest::Assertions##{meth}" if $0 == __FILE__ infect_an_assertion meth, new_name, new_name =~ dont_flip_re end end |