【问题标题】:How can I write an RSpec test for link_to_add_fields helper from Railscast 197如何为 Railscast 197 中的 link_to_add_fields 助手编写 RSpec 测试
【发布时间】:2010-09-16 21:30:13
【问题描述】:

我在 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

【问题讨论】:

    标签: ruby-on-rails rspec railscasts


    【解决方案1】:

    查看 rspec 请求规范(或 cucumber),因为您试图测试某个函数的行为。这样您就不必关心方法的底层实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      • 2012-09-14
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多