<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>We've been going down this route:</div><div><br class="webkit-block-placeholder"></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><a href="http://pastie.caboo.se/165265">http://pastie.caboo.se/165265</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><br class="webkit-block-placeholder"></div></div><div>We use mocha for our mocking and originally we mocked out the form builder, but the specs felt crufty. We then converted to instantiating the FormBuilder and passing it to partials that needed it.</div><div><br class="webkit-block-placeholder"></div><div>For the views that send in the FormBuilder, we use the #with passing a block and assert the "is_a?" inside (I'm still not too keen on using the param helper/matchers). This looks a bit more bulky (and is kinda ugly in having assertions in a setup) but it really greased the wheels for us.</div><div><br class="webkit-block-placeholder"></div><div>We ended up preferring to assert the presence of html vs expectations on a FormBuilder stub, and it made the view specs feel a bit more natural.</div><div><br class="webkit-block-placeholder"></div><div>One last note: we hacked the #render in rspec_on_rails to output the contents of a partial (which is why the template stubbing the render returns "form partial") and we assert the presence of that text in the response. Helps catch those rascally <% %> instead of <%= %>. I've been meaning to form together a patch and submit a proper extension, but it's as time allows. </div><div><br class="webkit-block-placeholder"></div><div>Perhaps a bit more than you were asking for, but I hope this helps</div><div><br class="webkit-block-placeholder"></div><div>-Zach</div><div><br class="webkit-block-placeholder"></div><div><br><div><div>On Mar 13, 2008, at 1:25 PM, Jonathan Linowes wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Thank you!<br><br>for the record, I refactored my code so the view does a form_for, and <br>any partials that render fields with the form builder does its own <br>fields_for. This makes the design cleaner and more testable. However, <br>I'm not sure if there's any performance cost in doing it this way <br>instead of passing the form builder around, anyone?<br><br>On Mar 13, 2008, at 5:05 AM, David Chelimsky wrote:<br><br><blockquote type="cite">On Wed, Mar 12, 2008 at 10:19 PM, Jonathan Linowes<br></blockquote><blockquote type="cite"><<a href="mailto:jonathan@parkerhill.com">jonathan@parkerhill.com</a>> wrote:<br></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><<a href="mailto:zach.dennis@gmail.com">zach.dennis@gmail.com</a>> wrote:<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">You can use mocha parameter matching to match on "anything" where<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">your<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"> form builder would be passed in. You could also use Mocha's<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">"kind_of"<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"> parameter matcher to ensure that what you expect is a FormBuilder<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"> object.<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"> Another way to do this is to not pass in your form builder, <br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">but the<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"> object needed, and then use fields_for inside the partial itself.<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">This<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"> works well in some scenarios.<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">You could also use rspec's parameter matching, which also supports<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">"anything" but not "kind_of" ;)<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> how would i use that in stub_render? eg if my view has<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> <%= render :partial => 'pages/foo', :layout => <br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">'bar', :locals =><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> { :f => f } %><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> what's the stub?<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">As of 1.1.3:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> stub_render(:partial => 'pages/foo', :layout => 'bar', :locals => <br></blockquote><blockquote type="cite">{:f => })<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">There is now, in trunk, hash_including matcher, so you *should* (I<br></blockquote><blockquote type="cite">haven't tried yet) be able to do this:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> stub_render(hash_including(:locals => {:f => }))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">That keeps it a bit less brittle, as the previous version will fail if<br></blockquote><blockquote type="cite">you add anything else to the actual render call this won't fail.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Cheers,<br></blockquote><blockquote type="cite">David<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> _______________________________________________<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> rspec-users mailing list<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">rspec-users mailing list<br></blockquote><blockquote type="cite"><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br></blockquote><blockquote type="cite"><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote><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">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br></div></body></html>