There is an RSpec method for testing helpers that combine output instead of returning it:
output = eval_erb("<% helper.dashboard_widget('My widget') { 'hello world' } %>")
output.should be_happy
This is the best way to approach the blocks that will have HTML from your views:
output = eval_erb <<-HTML
<% helper.dashboard_widget('My widget') do %>
<h1>Widget</h1>
<p>Hello World, this is my cool widget</p>
<% end %>
HTML
However, I found a cleaner way to test helpers that use concatenation but don't use HTML inside the block:
before :each do
helper.output_buffer = ''
end
it "should be awesome"
helper.dashboard_widget 'My widget' do
:awesome
end
helper.output_buffer.should match(/awesome/)
end
ERB, , .