Additions to rr stubbing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dynamic method stubbing | |
# user = Factory(:user) | |
# callbacks = User._create_callbacks.map(&:filter) | |
# stub_methods("user", callbacks) | |
def stub_methods(name, methods) | |
methods.each do |method| | |
eval "stub(#{name}).#{method}" | |
end | |
end | |
# Stub constant and return back its old value without warnings | |
# stub_const(User, :CONST, value) do | |
# some code... | |
# end | |
def stub_const(klass, name, value) | |
old_verbose, $VERBOSE = $VERBOSE, nil | |
old_value = klass.const_get(name) | |
klass.const_set(name, value) | |
yield | |
ensure | |
klass.const_set(name, old_value) | |
$VERBOSE = old_verbose | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment