# Stub sub partials when testing partial with rspec

**URL:** <https://www.ruby-forum.com/t/stub-sub-partials-when-testing-partial-with-rspec/137015>\
**Category:** Rails\
**Created:** [May 8, 2008, 9:43am UTC](https://www.ruby-forum.com/t/stub-sub-partials-when-testing-partial-with-rspec/137015 "2008-05-08T09:43:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goremika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/839c29/32.png) [@Goremika](https://www.ruby-forum.com/u/Goremika)\
**Post date:** [May 8, 2008, 9:43am UTC](https://www.ruby-forum.com/t/stub-sub-partials-when-testing-partial-with-rspec/137015/1 "2008-05-08T09:43:16Z")

</div>

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?
