Class: HaveTable::HaveTable

Inherits:
Object
  • Object
show all
Defined in:
lib/have_table/have_table.rb

Instance Method Summary collapse

Instance Method Details

#failure_message_for_shouldObject



17
18
19
# File 'lib/have_table/have_table.rb', line 17

def failure_message_for_should
  "expected that #{@response} would have a table"
end

#failure_message_for_should_notObject



21
22
23
# File 'lib/have_table/have_table.rb', line 21

def failure_message_for_should_not
  "expected that #{@response} would not have a table"
end

#matches?(response, &block) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/have_table/have_table.rb', line 3

def matches?(response, &block)
  @response = response
  @document = Webrat::XML.document(response)
  @table_nodes = @document.xpath("//table")
  if (block_given?)
    # Asked: have_table { ... }
    block.bind(self).call
    return matches_conditions?
  else
    # Asked: have_table
    return @table_nodes.length > 0
  end
end

#matches_conditions?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/have_table/have_table.rb', line 35

def matches_conditions?
  any_tables_match = false
  @table_nodes.each do |table_node|
    row_sequence = RowSequence.new(table_node)
    table_matches = true
    @table_conditions.each do |row_matcher|
      unless row_matcher.matches?(row_sequence)
        table_matches = false
        break
      end
    end
    if table_matches
      any_tables_match = true
      break
    end
  end
  return any_tables_match
end

#with_row(&block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/have_table/have_table.rb', line 25

def with_row(&block)
  @table_conditions ||= []

  row_matcher = RowMatcher.new
  if block_given?
    block.bind(row_matcher).call
  end
  @table_conditions << row_matcher
end