def tiltle_finder(names)
within 'table tbody tr:nth-child(1)' do
page.should have_selector(
'td:nth-child(10)',
text: "#{names.label}"
)
end
end
it 'should find title' do
expect{
tiltle_finder(names)
}.to raise_error(Capybara::ExpectationNotMet)
但仍然拖着那个例外 水豚:: ExpectationNotMet
答案 0 :(得分:0)
您可以检查是否未达到预期,而不是挽救错误:
def have_title_finder(names)
within 'table tbody tr:nth-child(1)' do
have_selector(
'td:nth-child(10)',
text: "#{names.label}"
)
end
end
# ...
expect(page).not_to have_title_finder(names)
答案 1 :(得分:0)
def tiltle_finder(names)
within 'table tbody tr:nth-child(1)' do
page.find('td:nth-child(10)', text: "#{names.label}")
end
end
it 'should find title' do
expect{
tiltle_finder(names)
}.to raise_error(Capybara::ElementNotFound)
end
解决了这个