检查链接数量是否正确 Rspec
Check if correct number of links appear with Rspec
我正在 re-writing 测试从测试单元到 Rspec/capybara,我只是想找出正确的语法。我想点击 root_path 并检查是否有一个 links 到 '/'(在 header 中)。
旧测试的相关部分是:
test 'layout links' do
get root_path
assert_select 'a[href=?]', root_path, count: 1
end
我可以使用 Rspec 测试 link 是否存在:
it 'should have correct number of links' do
visit root_path
expect(page).to have_link('Site Name', root_path)
end
我尝试添加
expect(page).to have_link('Site Name', root_path, count: 1)
但它只需要 0..2 个参数
尝试通过 href
选项传递路径:
expect(page).to have_link('Site Name', href: root_path, count: 1)
我正在 re-writing 测试从测试单元到 Rspec/capybara,我只是想找出正确的语法。我想点击 root_path 并检查是否有一个 links 到 '/'(在 header 中)。
旧测试的相关部分是:
test 'layout links' do
get root_path
assert_select 'a[href=?]', root_path, count: 1
end
我可以使用 Rspec 测试 link 是否存在:
it 'should have correct number of links' do
visit root_path
expect(page).to have_link('Site Name', root_path)
end
我尝试添加
expect(page).to have_link('Site Name', root_path, count: 1)
但它只需要 0..2 个参数
尝试通过 href
选项传递路径:
expect(page).to have_link('Site Name', href: root_path, count: 1)