At the moment my test helper is more experimentation than production
ready code so I wouldn't use it quite yet. Just wanted to demo
instantiating a Controller object (with a Mock Request), and calling
into the partial method.

The key thing I think you might be misunderstanding about the way Merb
handles requests, is that it just returns a standard string. So
Controllers become a little more reusable in the testing context
because you can instantiate one, and then run the your controller
action directly. Since it's not going through the dispatch process, no
before filters, etc will be run since they don't make in that context.

This also enables you to call controller actions as methods from other
controller actions. For example, your update method on your controller
could directly call your edit method when it comes time to render the
edit page. This is something that's not possible in Rails, and it
causes the need for a lot of before_filters and such just to share
code between controller actions.

On an unrelated note, I saw some your previous posts reference testing
RJS methods. RJS enabled Rails apps are very difficult to port to Merb
since there is currently no javascript generating Ruby libraries
currently for Merb. Would be cool if someone wrote RJS as a plugin to
Merb (maybe they have?), but that might not be high priority on
developers minds because RJS is a pretty poor web development
practice. I got on the bandwagon early when it came out in Rails only
to realize all too well the major drawbacks of generating javascript
code on the server to be run on the client side. But thats a topic for
another thread.


On Jan 24, 2:32 pm, Phlip <[email protected]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to