簡體   English   中英

使用Capybara / Rspec / Rails4使用動態ID測試link_to

[英]Test w/ Capybara/Rspec/Rails4 a link_to with dynamic id

我想知道測試帶有動態ID的link_to內部的link_to單擊的最佳方法是什么?

scenario 'select customer from the list' do
  sign_in_with user
  visit customers_path
  ## and here I would like to fire this action
end

我的桌子會這樣填充

%table.table.table-striped
  %thead
    %tr
      %th
        Name
      %th

  %tbody
    - @customers.each do |customer|
      %tr
        %td
          = customer.name
        %td
          = link_to '', root_path, class: 'glyphicon glyphicon-usd pull-right', id: "customer_#{customer.id}"
          = link_to '', customer, class: 'glyphicon glyphicon-zoom-in pull-right', id: "customer_#{customer.id}"

提前致謝

水豚將與文本匹配的ID ...

    @customer = Customer.all.sample
    click_link "customer_%d"%@customer.id

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM