Class: Test::Unit::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/eymiha/test/probe.rb

Instance Method Summary collapse

Instance Method Details

#probe(klass, *methods) ⇒ Object

probe is a surgical instrument useful for testing private methods. It takes a class and a list of instance methods and makes any of them that are private into public methods, yields control, and then changes them back to private. This allows testing of private methods with minimum exposure to any aberrations caused by a change in visibility.



10
11
12
13
14
15
# File 'lib/eymiha/test/probe.rb', line 10

def probe(klass,*methods)
  methods = [ *methods ].flatten
  target_methods = klass.publicize_private_instance_methods methods
  yield
  klass.privatize_public_instance_methods target_methods
end