# How to render a partial for test?

**URL:** <https://www.ruby-forum.com/t/how-to-render-a-partial-for-test/76888>\
**Category:** Rails\
**Created:** [November 22, 2006, 3:07am UTC](https://www.ruby-forum.com/t/how-to-render-a-partial-for-test/76888 "2006-11-22T03:07:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [November 22, 2006, 3:07am UTC](https://www.ruby-forum.com/t/how-to-render-a-partial-for-test/76888/1 "2006-11-22T03:07:46Z")

</div>

Railists:

This snip works inside an index.rhtml.

\<%= render :partial =\> ‘chat/index’,  
:locals =\> { :panel\_id =\> 1 }  
%\>

Pretend for a moment that I know nothing about Rails. (🙂

How do I write a test case that renders a partial and puts the result  
where goodies like assert\_select can get into it?

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [November 22, 2006, 4:05am UTC](https://www.ruby-forum.com/t/how-to-render-a-partial-for-test/76888/2 "2006-11-22T04:05:49Z")

</div>

> This snip works inside an index.rhtml.
> 
> \<%= render :partial =\> ‘chat/index’,  
> :locals =\> { :panel\_id =\> 1 }  
> %\>

I now need an answer to a bigger problem. (Apologies for it’s  
impossible to Google for, because ‘xml’ will give too many false hits.)

Suppose I wanted to concoct an HTML page using an RXML template,  
because the source is so much cleaner and easier to refactor.

When that chat/index is an RXML, something in the rendering system  
drops the Content-type: html/text from the outbound rendered contents.

This truly sucks, because I can no longer use “convention over  
configuration”. I have to put my XmlMarkup stuff into a function and  
call it the old-fashioned way.

Oh, but now it’s easier to test as a partial… 😉

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [November 22, 2006, 11:44am UTC](https://www.ruby-forum.com/t/how-to-render-a-partial-for-test/76888/3 "2006-11-22T11:44:20Z")

</div>

On 11/21/06, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do I write a test case that renders a partial and puts the result  
> where goodies like assert\_select can get into it?

Use Test::Rails, part of ZenTest.

[http://zentest.rubyforge.org/ZenTest/](http://zentest.rubyforge.org/ZenTest/)

- rob

–

> **[Home](https://robsanheim.com/)**
>
> Just another WordPress site

> **[Seeking Alpha | Stock Market Analysis & Tools for Investors](https://seekingalpha.com/)**
>
> Join Seeking Alpha, the largest investing community in the world. Get stock market news and analysis, investing ideas, earnings calls, charts and portfolio analysis tools.

[http://www.ajaxian.com](http://www.ajaxian.com)
