diff options
| author | mpalmer <mpalmer@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-23 08:18:10 +0000 |
|---|---|---|
| committer | mpalmer <mpalmer@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-23 08:18:10 +0000 |
| commit | 1d711dcfd902035b9be81debcfb5c271f78ae154 (patch) | |
| tree | fd4ab3ca7b3522bb0dab9f8d954f40326cdc294f /test/lib/mocha/any_instance_method.rb | |
| parent | a752eb2e7152ad81ad747d7c8604694d51d25fd8 (diff) | |
| download | puppet-1d711dcfd902035b9be81debcfb5c271f78ae154.tar.gz puppet-1d711dcfd902035b9be81debcfb5c271f78ae154.tar.xz puppet-1d711dcfd902035b9be81debcfb5c271f78ae154.zip | |
Partially complete #241. Add a 'purged' value for Package.ensure, and add a handler for all of the Debian providers. Also wrote sensible test cases, and so we've now got Mocha running around in our source tree.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2223 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/lib/mocha/any_instance_method.rb')
| -rw-r--r-- | test/lib/mocha/any_instance_method.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/lib/mocha/any_instance_method.rb b/test/lib/mocha/any_instance_method.rb new file mode 100644 index 000000000..4d55293b9 --- /dev/null +++ b/test/lib/mocha/any_instance_method.rb @@ -0,0 +1,35 @@ +require 'mocha/class_method' + +module Mocha + + class AnyInstanceMethod < ClassMethod + + def unstub + remove_new_method + restore_original_method + stubbee.any_instance.reset_mocha + end + + def mock + stubbee.any_instance.mocha + end + + def hide_original_method + stubbee.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.method_defined?(method) + end + + def define_new_method + stubbee.class_eval "def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end" + end + + def remove_new_method + stubbee.class_eval "remove_method :#{method}" + end + + def restore_original_method + stubbee.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.method_defined?(hidden_method) + end + + end + +end
\ No newline at end of file |
