我在Railscast espisode#197中使用了关于如何添加动态输入字段的方法细节,但我不确定如何为它编写RSpec测试。建议?
def link_to_add_fields(name, f, association, path, *args)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.semantic_fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render(path + association.to_s.singularize + "_fields", :builder => builder)
end
link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields.html_safe)}\")", *args)
end
答案 0 :(得分:0)
查看rspec请求规范(或黄瓜),因为您试图测试某个函数的行为。这样您就不必关心方法的底层实现。