Module: SpecUnit::ContextHelper

Included in:
Test::Unit::TestCase
Defined in:
lib/spec-unit/assert_helper.rb,
lib/spec-unit/context_helper.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.assert_helper(base) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/spec-unit/assert_helper.rb', line 36

def self.assert_helper(base)
  base.module_eval do
    class << self
      for meth in methods
        undef_method(meth) if meth.to_s =~ /^assert_/ || meth.to_s =~ /^assert$/
      end

      alias_method :spec_unit_method_missing, :method_missing 
      def method_missing(sym, *args, &block)
        if sym.to_s =~ /^assert_/
          self.send(:define_method, :"test_#{args[0]}") do
            if block
              send(sym, *(instance_eval(&block)))
            else
              send(sym)
            end
          end
        else
          spec_unit_method_missing sym, *args, &block
        end
      end
    end
  end
end

.included(base) ⇒ Object



3
4
5
6
# File 'lib/spec-unit/context_helper.rb', line 3

def self.included(base)
  base.extend(ClassMethods)
  assert_helper(base) if self.respond_to?(:assert_helper)
end