[rspec-users] Tests for render when changing view_paths

AR willyrubbit at yahoo.co.uk
Sat Aug 18 00:19:13 EDT 2007

Hi there,

I've been getting into RSpec recently and I must say what a fantastic  
product I think it is.  But, I've hit a bit of a problem.  In my  
ApplicationHelper I have a method which changes the view_paths in a  
controller so a partial can be rendered from a different base  
directory.  It simply takes an array of view_paths that a partial  
could be in, updates the view_paths for the controller doing the  
initial rendering, does the rendering, then removes the paths at the  
end.  Here's the code:

module ApplicationHelper
   def render_partial_with_alternate_view_paths(view_paths, options =  
     view_path_removes = view_paths.inject([]){ |rp, path|  
self.view_paths.include?(path) ? rp : rp.push(path) }
     self.view_paths = self.view_paths + view_path_removes
     returning render( options ) do
       self.view_paths = self.view_paths - view_path_removes

I've tried writing specifications for this in the helper, the view  
and the controller parts, but get different errors each time.  the  
closest I've managed to get so far is:

   it "should render a partial from a path in the supplied view_paths  
and leave view_paths the same afterwards" do
     options = {:partial => 'application/pod', :locals => {:the_value  
=> "sent value"}, :layout => 'application/layout' }
     original_paths = ["/path/to/rails_app/app/views"]
     extra_paths = ["/path/to/rails_app/spec/views"]
     all_paths = original_paths + extra_paths
original_paths, all_paths)
     render_partial_with_alternate_view_paths(extra_paths, options)

I've put this code in a helper spec, but I can't check what the  
partial has rendered.  I'm really confused and can't work out where  
the spec should go and what bits should be mocked out and how.

Any help would be gratefully appreciated.



More information about the rspec-users mailing list