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
end
end
end
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
self.should_receive(:view_paths).and_return(original_paths,
original_paths, all_paths)
self.should_receive(:view_paths=).with(all_paths).once.ordered
self.should_receive(:view_paths=).with(original_paths).once.ordered
self.should_receive(:render)
render_partial_with_alternate_view_paths(extra_paths, options)
end
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.
Thanks,
Ant