I don&#39;t have a lot of experience yet with the view spec&#39;ing, but I do have the first way I will start:<br><br>Spec a view from the outermost level and Treat extracted partials as a hybrid of &quot;Extract Method&quot; and &quot;Extract Class&quot;
<br>This means that I would spec out the top-most view, extract a partial to remove duplication or enhance readability. If I find that two views start using the same partial, then I would extract the view tests that deal with the partial and use those as tests for the partial.
<br><br>-Corey<br><br><div class="gmail_quote">On Jan 13, 2008 12:14 PM, Kevin Olbrich &lt;<a href="mailto:lists@ruby-forum.com">lists@ruby-forum.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;ve been getting my head around view spec&#39;ing lately for a fairly<br>complex project that makes heavy use of partials in views and I have hit<br>up against a style puzzle.<br><br>I see two strategies for spec&#39;ing views:
<br><br>First:<br> &nbsp;Develop detailed specs for each partial and then make sure that the<br>final view expects that the appropriate partials are included and used.<br><br> &nbsp; Pros:<br> &nbsp; &nbsp;* it&#39;s DRY<br> &nbsp; &nbsp;* you get a single point of failure if an expectation is not met
<br><br> &nbsp; Cons:<br> &nbsp; &nbsp;* the final specs for a view aren&#39;t very explicit and it can be<br>challenging<br> &nbsp; &nbsp; &nbsp;to figure out all the things a view does without tracing back the<br>partials.<br><br>Second:<br> &nbsp;Develop a set of specs for each view that explicitly expect the
<br>important UI elements and treat the rest of the view as a black box<br>(i.e., you don&#39;t care if a particular partial was rendered so long as<br>the relevant UI elements are there).<br><br> &nbsp;Pros:<br> &nbsp; * It&#39;s explicit and easy to tell what each view does.
<br><br> &nbsp;Cons:<br> &nbsp; * It&#39;s not DRY.. you will get multiple points of failure if a partial<br> &nbsp; &nbsp; is changed.<br> &nbsp; * More time consuming and it&#39;s easy to miss an expectation in a view.<br><br><br>So... What are people doing? &nbsp;The first? &nbsp;The second? or some
<br>combination of the two?<br><font color="#888888">--<br>Posted via <a href="http://www.ruby-forum.com/" target="_blank">http://www.ruby-forum.com/</a>.<br>_______________________________________________<br>rspec-users mailing list
<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></font></blockquote>
</div><br><br clear="all"><br>-- <br><a href="http://www.coreyhaines.com">http://www.coreyhaines.com</a><br>The Internet&#39;s Premiere source of information about Corey Haines