Module: Toothbrush::Helpers

Defined in:
lib/toothbrush/helpers.rb

Instance Method Summary collapse

Instance Method Details

#ensure_table(table_selector, header_or_content, content = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/toothbrush/helpers.rb', line 3

def ensure_table(table_selector, header_or_content, content = nil)
  if content.nil?
    return _ensure_table(table_selector, header_or_content)
  else
    header = header_or_content
  end

  content.each_with_index do |row, row_index|
    row.each_with_index do |cell, cell_index|
      begin
        within("#{table_selector} tbody tr:nth-child(#{row_index+1}) td:nth-child(#{cell_index+1})") do
          page.should have_content(cell)
        end
      rescue Capybara::ElementNotFound
        within("#{table_selector} tr:nth-child(#{row_index+2}) td:nth-child(#{cell_index+1})") do
          page.should have_content(cell)
        end
      end
    end
  end
end