[rspec-users] specifying output of render call

Matt McNeil nabble.108 at xoxy.net
Mon May 5 20:18:02 EDT 2008


Hello again,

First of all, thanks much for everyone's input on my question last week
about spec'ing an invocation of super.  

Here's another question that seems resistant to my Google searching:

With this helper method (defined in a module and included in Rails
controllers):

def render_rjs_redirect(url = '/')
  render :update do |page|
    page << "location.href='#{url}'"
  end
end

Is it possible/advisable to specify either the block passed to render or the
output of the helper, something like below?  The only way I have been able
so far to spec this was to create a FooController with an index action that
called the method and then checked the response.body, but that seems like a
lot of overhead to test such a simple method.  Is there a better or obvious
way to do this?

Thanks!
Matt

it "should render javascript to redirect the browser" do
  self.should_receive(:render).with(:update) { |page| page <<
"location.href='example.com'"}
  render_rjs_redirect('example.com')
end

it "should render javascript to redirect the browser" do
  render_rjs_redirect('example.com')
  response.body.should == "location.href='example.com'"
end


-- 
View this message in context: http://www.nabble.com/specifying-output-of-render-call-tp17071496p17071496.html
Sent from the rspec-users mailing list archive at Nabble.com.



More information about the rspec-users mailing list