我正在尝试编写我所有的 Capybara 代码以不使用任何 CSS 或有趣的匹配器。出于验收测试的目的,我使用 Capybara 仅通过用户可见的按钮和链接文本进行导航。
所以我有一个非常简单的测试,断言管理员可以编辑任何用户:
it 'allows an administrator to edit any user' do
user = login_admin_user
user1 = FactoryGirl.create(:user)
click_link "Users"
current_path.should eq(users_path)
click_link "Edit" # This is the problem
current_path.should eq(edit_user_path(user1))
fill_in "Last name", with: "Myxzptlk"
click_button "Update User"
page.should have_content("Myxzptlk")
end
当然,上面的问题行不够具体;表中将有 2 行(user 和 user1)。我对 TDD 很陌生,那么如何使用 Capybara 仅使用可见文本来选择正确的链接?