Specifying output of render call

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

def render_rjs_redirect(url = ‘/’)
render :update do |page|
page << “location.href=’#{url}’”

Is it possible/advisable to specify either the block passed to render or
output of the helper, something like below? The only way I have been
so far to spec this was to create a FooController with an index action
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
way to do this?


it “should render javascript to redirect the browser” do
self.should_receive(:render).with(:update) { |page| page <<

it “should render javascript to redirect the browser” do
response.body.should == “location.href=‘example.com’”

View this message in context:
Sent from the rspec-users mailing list archive at Nabble.com.

Hey Matt,

One problem with rjs is that it’s very difficult to test. You can’t
execute it, and executing code is necessary for specification by

In this case, I would probably not unit test that code, based on the
combination of it being simple code but difficult to test. I would
probably right a “ping” test though, that just makes the request and
asserts an ok response. That at least covers syntax errors or bad
method calls. You could write a selenium test if you want I suppose.

My current favorite pattern for RJS-type stuff is to push the behavior
into the client and have the server just render JSON. This makes it
very easy to test the behavior using jspec, and leaves you with a very
natural separation of concerns.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs