Stub sub partials when testing partial with rspec

Hello all
I prefer to use many partials. It makes my code more DRY
Also I use rspec, and when I have to test partial with sub partials I
have a problem.

if I stub render, then my partial will not be rendered. If i do not
stub render it tries to render sub partial (and i don’t need this)

Not very long googling did not bring the answer, so I made very dirty
and IMHO dangerous function

def block_render_except unblocked
ActionView::Partials.class_eval do
public
def self.set_unblocked partial
@@unblocked = partial
end
alias_method :orig_render_partial,:render_partial
def render_partial(partial_path, object_assigns = nil,
local_assigns = nil) #:nodoc:
if partial_path.to_s == @@unblocked
orig_render_partial(partial_path, object_assigns,
local_assigns)
else
return " "
end
end
end
ActionView::Partials.set_unblocked unblocked
end

usage:
block_render_except ‘payments/list’
render(:partial => “payments/list”)

The question is how sick am I, and is there more pretty solution of my
problem?
Also wanted to know how this approach to design view part of
application is right?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs