Testing helpers with RSpec

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

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