Module: Respectable::Interface

Defined in:
lib/respectable.rb

Instance Method Summary collapse

Instance Method Details

#each_row(table, **options, &block) ⇒ Object



33
34
35
36
37
# File 'lib/respectable.rb', line 33

def each_row(table, **options, &block)
  RSpec.deprecate(:each_row, replacement: :specify_each)

  specify_each(table, **options, &block)
end

#specify_each(table, **options, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/respectable.rb', line 13

def specify_each(table, **options, &block)
  desc_template = options.has_key?(:desc) ? options[:desc] : Util.desc_template(block.parameters)

  define_method(:specify_each) do |*, &block|
    block.call(*@args) if @args
  end

  Util.table_data(table).each do |row|
    # TODO: can we use raw row-value? (for outline)
    desc_data = Hash[block.parameters.map(&:last).zip(row.map(&:inspect))]
    description = desc_template % desc_data if desc_template
    instance_eval("      it(description) do\n        @args = Util.eval_row_items(row, binding)\n        eval(block.source, binding, *block.source_location)\n      end\n    IT\n  end\nend\n", *block.source_location)