Jacques Crocker wrote: > Here is a simple 5 line test helper you can use to spec partials. > http://gist.github.com/51568 > > After adding it to your spec_helpers.rb, you should be able to do > something like this > > @partial_result = request_partial("articles/my_partial")
Thanks! Now brace yourselves for the constructive criticism, even before I use it! (I just remembered I have no partial to test yet...) Architecturally, it's the same as my hack for Rails: http://broadcast.oreilly.com/2008/10/testing-rails-partials.html It adds a fake action to your root Application controller, then dispatches to this and "bounces" your args into render. However, my fake action can also do render :layout => 'application', :text => '', to test a layout in isolation from its pages. Rails lets us mix and match things in render(), while Merb apparently provides separate methods for each rendering activity. > Then @partial_result will be the html of that partial. It might be > worth wrapping it in a fake @response as well so you can use > have_selector & stuff on it. It just proxies the method call directly > to the partial() call on the controller so all the normal proxy calls > apply. Check. However... If your Application has a blanket filter that bounces the Great Washed Masses who are not logged in, the fake action might think it's defending you from hackers. I cover that for Rails in my blog entry, but it's a hack on a hack. > Helper could use a bit of improvement as well. If anyone wants to fork > the gist and add some improvements to the api (maybe a name change), > I'll collect it all and release it as merb_spec_partial plugin. > > I'll try to figure out some way to move all the instance variables > defined in your spec to the fake controller so that your partial will > have access to those variables. Also need to figure out how to allow > setting all the other stuff like params, cookies, sessions, etc. But > it should be pretty easy. About the magic instance variable system, we happen to never use that. We always pass explicit instvars in with :locals =>{ :@foo => @foo, :@bar => @bar }. But these are style things; you have to match what the brochure says! -- 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 -~----------~----~----~----~------~----~------~--~---
