This project is archived and is in readonly mode.
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 => Proc.new{ |resp, out|
1.upto(10){ |i| out.write "<element>#{i}</element>" }
}
end
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
end
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
-
Andrew Bloom April 5th, 2009 @ 07:13 PM
- Tag changed from 2.3.2 to 2.3.2, actionpack, action_controller, test_process
-
Andrew Bloom April 6th, 2009 @ 05:31 AM
I wrote up a slightly more thorough explanation here: http://www.somethingunimportant....
-
Steve Madsen October 7th, 2009 @ 08:51 PM
- Tag changed from 2.3.2, actionpack, action_controller, test_process to 2.3.4, actionpack, action_controller, test_process
I can confirm that this problem still exists in 2.3.4, although this patch doesn't fix it for me because it only triggers the call to the proc due to assert_select. If you evaluate @response.body in the test or have set Mocha expectations on methods that should be called within the proc, those tests still fail.
I've reworked the patch slightly and existing tests pass, as well as the new test added by Andrew.
-
Steve Madsen October 7th, 2009 @ 08:57 PM
Minor change to my previous patch. That one caused problems for Mocha expectations because it allowed the proc to be called more than once.
-
Rohit Arondekar October 14th, 2010 @ 02:46 PM
- Importance changed from to
Any updates here?
Could somebody try and reproduce this on latest 2.x/3.x releases or branches? The ticket may be marked as stale if it's not updated in 2 months so if it's still an issue please leave a comment, preferably with a failing test for Rails.
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>