Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created December 9, 2012 02:58
Embed
What would you like to do?
Ugly, but works.
# ugly, but works
def test_eval_display_node
mock = MiniTest::Mock.new.expect(:print, nil, ["H"])
redefine_constant("STDOUT", mock) do
ast = 72.times.collect { Mojikun::ThumbsUpNode.new }
ast << Mojikun::DisplayNode.new
@interpreter.evaluate(ast)
end
mock.verify
end
def redefine_constant(const, value)
orig = eval(const).dup
Object.send(:remove_const, const)
Object.const_set(const, value)
yield
Object.send(:remove_const, const)
Object.const_set(const, orig)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment