# Testing helpers with RSpec

**URL:** <https://www.ruby-forum.com/t/testing-helpers-with-rspec/182306>\
**Category:** Rails\
**Created:** [January 26, 2010, 12:20pm UTC](https://www.ruby-forum.com/t/testing-helpers-with-rspec/182306 "2010-01-26T12:20:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [January 26, 2010, 12:20pm UTC](https://www.ruby-forum.com/t/testing-helpers-with-rspec/182306/1 "2010-01-26T12:20:27Z")

</div>

Hi all

I have a helper that generates HTML for dynamically adding items to a  
class. It uses Formtastic for the fields:

module Admin  
module CompetitionsHelper  
def add\_competition\_class\_link(form\_builder)  
link\_to\_function “Add competition class” do |page|  
form\_builder.semantic\_fields\_for :competition\_classes,  
CompetitionClass.new, :child\_index =\> ‘NEW\_RECORD’ do |p|  
html = render(:partial =\> ‘competition\_class\_form’, :object  
=\> p)  
page \<\< “$(’#competition\_classes’).append(’#  
{escape\_javascript(html)}’.replace(/NEW\_RECORD/g, new Date().getTime  
()));”  
end  
end  
end  
end  
end

Now I have a problem with testing this with RSpec. I can mock the  
SemanticFormBuilder but that does not really check that the correct  
HTML is being added. I also have problems mocking the block which  
leaves it unseen by Rcov and 100% coverage is lost.

Does anyone have a good way of testing things like these?

Regards

Erik
