UPDATE The code given doesn't actually work. I'd love to hear if anyone knows of code that will do this. I hacked around the problem a very ugly way.
Rails helper methods are defined in modules and mixed into objects...of what class? Turns out it's anonymous copies of ActionView::Base. How does one mock or stub methods on such a beast? Here's a solution I found:
class MyController
def rescue_action(e) raise e end
attr_reader :template
end
class MyControllerTest < Test::Unit::TestCase
def setup
@controller = ...
end
def test_should_stub_helper_method
@controller.template.expects(:random_helper_method).returns('')
...
end
end
Thanks to Matthew Dieter for posting about this. I had to add the attr_reader
line to get this to work.