Testing fields added dynamically by cocoon using rspec and capybara

后端 未结 3 1325
春和景丽
春和景丽 2021-01-05 17:36

I was wondering whether anybody tests fields that were dynamically added by cocoon?

It\'s a great little time saver but all of the fields that are added dynamically

3条回答
  •  日久生厌
    2021-01-05 17:55

    Maybe using Capybara finders all, first and the selector input. Something like this:

    visit new_resource_path
    click_link "Add a Nested Resource"
    first("input[name='nested_resource[name]']").set("Nested Resource")
    click_button "submit"
    

    Or

    visit new_resource_path
    click_link "Add a Nested Resource"
    click_link "Add a Nested resource"
    all("input[name='nested_resource[name]']").each do |input|
      input.set("Nested Resource")
    end
    click_button "submit
    

    This is only an approach, I've never worked with cocoon. This is however, a form to test dynamic inputs.

提交回复
热议问题