class Lemon::TestMethod

The TestMethod class is a special TestCase that requires a particular target method be tested.

Attributes

tested[RW]

Used to make sure the the method has been tested, or not.

Public Class Methods

new(settings={}, &block) click to toggle source

New unit test.

Calls superclass method Lemon::TestCase::new
# File lib/lemon/test_method.rb, line 14
def initialize(settings={}, &block)
  @tested   = false
  super(settings)
end

Public Instance Methods

class_method?() click to toggle source
# File lib/lemon/test_method.rb, line 131
def class_method?
  false
end
name() click to toggle source

If class method, returns target method's name prefixed with double colons. If instance method, then returns target method's name prefixed with hash character.

# File lib/lemon/test_method.rb, line 44
def name
  "##{target}"
end
raise_pending(procedure) click to toggle source
# File lib/lemon/test_method.rb, line 113
def raise_pending(procedure)
  if RUBY_VERSION < '1.9'
    Kernel.eval %[raise NotImplementedError, "#{target} not tested"], procedure
  else
    Kernel.eval %[raise NotImplementedError, "#{target} not tested"], procedure.binding
  end
end
run(test, &block) click to toggle source

Run test in the context of this case. Notice that run for TestMethod is more complex than a general TestCase. This is to ensure that the target method is invoked during the course of the test.

@param [TestProc] test

The test procedure instance to run.

@yield

The procedure for running the test.
Calls superclass method Lemon::TestCase#run
# File lib/lemon/test_method.rb, line 78
    def run(test, &block)
      target = self.target

      raise_pending(test.procedure) unless test.procedure

      begin
        target_class.class_eval do
          alias_method "_lemon_#{target}", target
          define_method(target) do |*a,&b|
            test.tested = true
            __send__("_lemon_#{target}",*a,&b)
          end
        end
      rescue => error
        Kernel.eval <<-END, test.to_proc.binding
          raise #{error.class}, "#{target} not tested"
        END
      end

      begin
        super(test, &block)
        #block.call

      ensure
        target_class.class_eval %{
          alias_method "#{target}", "_lemon_#{target}"
        }
      end

      raise_pending(test.procedure) unless test.tested
    end
target_class() click to toggle source

The target class.

# File lib/lemon/test_method.rb, line 124
def target_class
  @target_class ||= context.target
end
to_s() click to toggle source

Returns the prefixed method name.

# File lib/lemon/test_method.rb, line 54
def to_s
  "##{target}"
end
type() click to toggle source

Description of the type of test case.

# File lib/lemon/test_method.rb, line 30
def type
  'Method'
end
unit() click to toggle source

Returns the fully qulaified name of the target method. This is the standard interface used by Ruby Test.

# File lib/lemon/test_method.rb, line 62
def unit
  "#{context}##{target}"
end
validate_settings() click to toggle source

Validate that a context and target method have been supplied.

# File lib/lemon/test_method.rb, line 22
def validate_settings
  raise "method test has no module or class context" unless @context
  raise "#{@target} is not a method name" unless Symbol === @target
end