This project is archived and is in readonly mode.

#2423 new
Andrew Bloom

Rendering Text with a Proc fails in testing

Reported by Andrew Bloom | April 5th, 2009 @ 07:12 PM | in 3.x

I found an untested corner of ActionController and a bug in TestProcess when I dug in.

Imagine you need to stream some XML (try not to think about all the downsides). See my simple example below and pretend it generates valid output.

def render_text_with_proc
  render :text =>{ |resp, out|
    1.upto(10){ |i| out.write "<element>#{i}</element>" }

After writing something like you see above, you then try to write a test that probably looks something like this:

def test_render_text_with_proc
  get :render_text_with_proc
  assert_response :success
  assert_select "element", 10

That test will fail with the following trace:

1) Error: test_render_text_with_proc(RenderTest): TypeError: can't convert Proc into String

./test/../lib/action_controller/vendor/html-scanner/html/tokenizer.rb:26:in `initialize'
./test/../lib/action_controller/vendor/html-scanner/html/tokenizer.rb:26:in `new'
./test/../lib/action_controller/vendor/html-scanner/html/tokenizer.rb:26:in `initialize'
./test/../lib/action_controller/vendor/html-scanner/html/document.rb:16:in `new'
./test/../lib/action_controller/vendor/html-scanner/html/document.rb:16:in `initialize'
./test/../lib/action_controller/test_process.rb:498:in `new'
./test/../lib/action_controller/test_process.rb:498:in `html_document'
./test/../lib/action_controller/assertions/selector_assertions.rb:614:in `response_from_page_or_rjs'
./test/../lib/action_controller/assertions/selector_assertions.rb:213:in `assert_select'
./test/controller/render_test.rb:952:in `test_render_text_with_proc'
./test/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:62:in `__send__'
./test/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:62:in `run'

I have attached a patch that updates TestProcess and lets this test succeed. This has been built against tags/v2.3.2.1.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>