[mocha-developer] Mocking the rendering of a Rails template

James Mead jamesmead44 at gmail.com
Tue Oct 17 18:01:33 EDT 2006

On 17/10/06, Bryan Helmkamp <bhelmkamp at gmail.com> wrote:
> I'm having difficulty setting up mocks such that I can verify that
> Rails was going to render the right template file (for example
> new.rhtml) and stop Rails from performing the actual rendering.
> After peeking at Rails' internals, I tried two techniques as illustrated
> here:
> http://pastie.caboo.se/18197
> Neither worked.
> I think the first one failed because Rails doesn't setup
> response.template to be an instance of ActionView::Base until after
> the controller processing is called.
> I have no idea what is going on with the second attempt.  It's hitting
> a mock, but I have no idea where that mock is coming from.  Logically,
> it probably is coming from the any_instance magic, but in that case it
> should be expecting the render_file call.  Thoughts?
> What am I doing wrong in the second case?  Is there another way I
> could mock this?

Why do you need to get into the Rails internals?

I think it would be better to mock a part of the published API e.g. the
#render method on @controller.

Otherwise you are effectively testing Rails itself.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20061017/7a29c103/attachment-0001.html 

More information about the mocha-developer mailing list