Module: Pickles::StepDef

Defined in:
lib/cucumber/pickles/steps.rb

Class Method Summary collapse

Class Method Details

.define_table_step(allowed_table_cols) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cucumber/pickles/steps.rb', line 14

def define_table_step(allowed_table_cols)
  -> ( within, table ) do

    Waiter.wait_for_ajax

    if table.headers.length == 3 && 3.in?(allowed_table_cols)
      current_within = within

      rows = table.rows.unshift(table.headers)

      rows.each do |(within, label, value)|
        case within
        when Helpers::Regex::WITHIN
          current_within = Pickles.detect_node($1, $2, within: within)
        when "-"
          current_within = within
        end

        if label['pry']
          label['pry'] = ''

          pry binding
        end

        yield(label, value, current_within)
      end
    elsif table.headers.length == 2 && 2.in?(allowed_table_cols)
      table.rows_hash.each do |label, value|
        if label['pry']
          label['pry'] = ''

          pry binding
        end

        yield(label, value, within)
      end
    elsif table.headers.length == 1 && 1.in?(allowed_table_cols)
      table.each do |label|
        if label['pry']
          label['pry'] = ''

          pry binding
        end

        yield(label, nil, within)
      end
    else
      raise(ArgumentError, "Unsupported table format. Must contain #{allowed_table_cols.join(' || ')} cols")
    end

  end
end