dchelimsky at gmail.com
Fri Jan 25 07:53:54 EST 2008
On Jan 23, 2008 5:25 AM, Rob Holland <rob.holland at gmail.com> wrote:
> I'm trying to spec a controller method which renders some rjs as part
> of a render :update block. The problem I'm having is that stub_render
> or expect_render don't seem to allow and_return to work.
> The controller method does:
> if @thing.save
> render :update do |page|
> page.insert_html :bottom, 'x_thing_list', :partial
> => 'thing', :object => @thing
> page.form.reset 'x_new_thing'
> If I expect/stub_render the partial render (which I need to do if I
> want to solely test the controller in isolation), I get:
> new Insertion.Bottom("x_thing_list", null);
> The null is due to the render :partial being stubbed. Unfortunately,
> this breaks the regex that assert_rjs uses, so my test:
> response.should have_rjs(:insert, :bottom, "x_thing_list")
> fails, when it should pass.
> What I need to be able to do is:
> expect_render(:partial => 'thing', :object => @thing).and_return('"x"')
> so that the output satisfies the assert_rjs regex. I would love to
> provide a patch for this, but I cannot see why it doesn't already
> work. The expect_render return value seems to be a normal mock, I
> don't understand why return values aren't working in this case.
The trick here is that render :partial is NOT getting called on the
controller - it's getting called on the template that is yielded to
To make matters more confusing, you can't get a handle on the template
until the action is already underway - which means you can't say
template.expect_render or controller.template.expect_render.
Here's the way I would handle this: http://pastie.caboo.se/143246
> Thanks for any insights.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users