Fix issue #2287
This commit is contained in:
parent
36c2d2c1a5
commit
230709be11
|
@ -19,7 +19,10 @@ Capybara.add_selector(:table, locator_type: [String, Symbol]) do
|
||||||
header = XPath.descendant(:th)[XPath.string.n.is(header)]
|
header = XPath.descendant(:th)[XPath.string.n.is(header)]
|
||||||
td = XPath.descendant(:tr)[header].descendant(:td)
|
td = XPath.descendant(:tr)[header].descendant(:td)
|
||||||
cell_condition = XPath.string.n.is(cell_str)
|
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]
|
td[cell_condition]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -28,7 +31,7 @@ Capybara.add_selector(:table, locator_type: [String, Symbol]) do
|
||||||
|
|
||||||
if prev_cell
|
if prev_cell
|
||||||
prev_cell = XPath.ancestor(:tr)[1].preceding_sibling(:tr).join(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
|
end
|
||||||
|
|
||||||
XPath.descendant(:td)[cell_condition]
|
XPath.descendant(:td)[cell_condition]
|
||||||
|
|
|
@ -143,10 +143,56 @@ Capybara::SpecHelper.spec '#has_no_table?' do
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should consider columns' do
|
context 'using :with_cols' do
|
||||||
expect(@session).to have_no_table('Vertical Headers', with_cols:
|
it 'should consider a single column' do
|
||||||
[
|
expect(@session).to have_no_table('Vertical Headers', with_cols:
|
||||||
{ 'First Name' => 'Joe' }
|
[
|
||||||
])
|
{ '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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue