2010-09-16 55 views
1

我在Railscast espisode#197中使用了有關如何添加動態輸入字段的方法詳細信息,但我不確定如何爲其編寫RSpec測試。建議?我如何爲Railscast編寫link_to_add_fields幫助程序的RSpec測試197

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

查看rspec請求規範(或黃瓜),因爲你試圖測試某個函數的行爲。這樣你就不必關心方法的底層實現。

相關問題