mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
Table matcher have_table_row does not wait for full duration on should_not
This commit is contained in:
@@ -1,17 +1,37 @@
|
||||
RSpec::Matchers.define :have_table_row do |row|
|
||||
|
||||
match do |node|
|
||||
match_for_should do |node|
|
||||
@row = row
|
||||
|
||||
begin
|
||||
wait_until { node.all('tr').map { |tr| tr.all('th, td').map(&:text) }.include? row }
|
||||
rescue TimeoutError
|
||||
false
|
||||
else
|
||||
true
|
||||
false_on_timeout_error do
|
||||
wait_until { rows_under(node).include? row }
|
||||
end
|
||||
end
|
||||
|
||||
match_for_should_not do |node|
|
||||
@row = row
|
||||
|
||||
false_on_timeout_error do
|
||||
# Without this sleep, we trigger capybara's wait when looking up the table, for the full
|
||||
# period of default_wait_time.
|
||||
sleep 0.1
|
||||
wait_until { !rows_under(node).include? row }
|
||||
end
|
||||
end
|
||||
|
||||
def rows_under(node)
|
||||
node.all('tr').map { |tr| tr.all('th, td').map(&:text) }
|
||||
end
|
||||
|
||||
def false_on_timeout_error
|
||||
yield
|
||||
rescue TimeoutError
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
failure_message_for_should do |text|
|
||||
"expected to find table row #{@row}"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user