Justin Smestad wrote:
> I do not mean to answer a question with another question but why test
> your partial? It should be written in such a reusable way that the
> code should be near bullet proof.
To help write it like that.
> If you also follow the partial sans-
> logic approach than there would be no reason to test a partial other
> than to create 'artificial code coverage' with a brittle test.
For the same reason we test low-level methods, not just the higher level ones.
> Now to answer your question, the best approach would be to render the
> partial within the scope that it will be used. Isolated testing only
> makes sense if your doing particular logic inside the partial which
> you shouldnt be in the first place. So just check
> @response.body.should include("the thingy") or better yet
> @response.body should have_xpath(//@id=...)
Confer Rails View Tests that (allegedly) call render on anything - a layout,
partial, inline, file, whatever - and return the result as a string.
Next, have_xpath works great in two steps. The first identifies the tested
panel, and the second pinpoints a feature inside it. To whit:
xpath :div, :right_menu do
xpath :a, ?. => 'Contents'
end
Only a link with text 'Contents' inside the right menu panel will do. Another
link with the same text will not foil the test.
have_xpath seems to take a block, but I couldn't (briefly) figure out how to
use
it. As a research topic, I will not settle for less than rendering a partial,
but of course in a production project I would simply render the partial inside
its page and everything, then I would use a nested XPath test to locate the
partial and then test its innards.
If this is a gap in Merb's testing, could someone fix it?
--
Phlip
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---