使用/ Capybara / Rspec / Rails测试4带有动态ID的link_to

时间:2014-03-13 11:06:45

标签: ruby-on-rails rspec ruby-on-rails-4 capybara rspec-rails

我想知道在具有动态ID的迭代表中测试点击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}"

提前致谢

1 个答案:

答案 0 :(得分:0)

Capybara会将id与文本相匹配......

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