module Respectable::Interface

Public Instance Methods

each_row(table, **options, &block) click to toggle source
# File lib/respectable.rb, line 35
def each_row(table, **options, &block)
  RSpec.deprecate(:each_row, replacement: :specify_each)

  specify_each(table, **options, &block)
end
specify_each(table, **options, &block) click to toggle source
# 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 |*, &innerblock|
        innerblock.call(*@args) if @args
      end

      @description = ""

      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, *block.source_location)
          it(@description) do
            @args = Util.eval_row_items(row, binding)
            eval(block.source, binding, *block.source_location)
          end
        IT
      end
    end