This commit is contained in:
Thomas Walpole 2019-12-22 08:43:39 -08:00
parent 36c2d2c1a5
commit 230709be11
2 changed files with 56 additions and 7 deletions

View File

@ -19,7 +19,10 @@ Capybara.add_selector(:table, locator_type: [String, Symbol]) do
header = XPath.descendant(:th)[XPath.string.n.is(header)]
td = XPath.descendant(:tr)[header].descendant(:td)
cell_condition = XPath.string.n.is(cell_str)
cell_condition &= prev_col_position?(XPath.ancestor(:table)[1].join(xp)) if xp
if xp
prev_cell = XPath.ancestor(:table)[1].join(xp)
cell_condition &= (prev_cell & prev_col_position?(prev_cell))
end
td[cell_condition]
end
else
@ -28,7 +31,7 @@ Capybara.add_selector(:table, locator_type: [String, Symbol]) do
if prev_cell
prev_cell = XPath.ancestor(:tr)[1].preceding_sibling(:tr).join(prev_cell)
cell_condition &= prev_col_position?(prev_cell)
cell_condition &= (prev_cell & prev_col_position?(prev_cell))
end
XPath.descendant(:td)[cell_condition]

View File

@ -143,10 +143,56 @@ Capybara::SpecHelper.spec '#has_no_table?' do
])
end
it 'should consider columns' do
expect(@session).to have_no_table('Vertical Headers', with_cols:
[
{ 'First Name' => 'Joe' }
])
context 'using :with_cols' do
it 'should consider a single column' do
expect(@session).to have_no_table('Vertical Headers', with_cols:
[
{ 'First Name' => 'Joe' }
])
end
it 'should be true even if the last column does exist' do
expect(@session).to have_no_table('Vertical Headers', with_cols:
[
{
'First Name' => 'What?',
'What?' => 'Walpole',
'City' => 'Oceanside' # This line makes the example fail
}
])
end
it 'should be true if none of the columns exist' do
expect(@session).to have_no_table('Vertical Headers', with_cols:
[
{
'First Name' => 'What?',
'What?' => 'Walpole',
'City' => 'What?'
}
])
end
it 'should be true if the first column does match' do
expect(@session).to have_no_table('Vertical Headers', with_cols:
[
{
'First Name' => 'Thomas',
'Last Name' => 'What',
'City' => 'What'
}
])
end
it 'should be true if none of the columns match' do
expect(@session).to have_no_table('Vertical Headers', with_cols:
[
{
'First Name' => 'What',
'Last Name' => 'What',
'City' => 'What'
}
])
end
end
end