From 6026a74c7322b7b06594985d78c2d53e67777aeb Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 21 May 2014 14:59:24 +1000 Subject: [PATCH] Table matcher have_table_row does not wait for full duration on should_not --- spec/support/matchers/table_matchers.rb | 34 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/spec/support/matchers/table_matchers.rb b/spec/support/matchers/table_matchers.rb index 71fb297e33..d0eb28d641 100644 --- a/spec/support/matchers/table_matchers.rb +++ b/spec/support/matchers/table_matchers.rb @@ -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