Module: RSpec::Variants::TabularSyntax

Defined in:
lib/rspec/variants/tabular.rb

Instance Method Summary collapse

Instance Method Details

#|(other) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec/variants/tabular.rb', line 7

def |(other)
  # The first two statements are used to get the data_condition block
  # binding as well as the caller instance. The caller instance will be
  # an instance of ExampleGroup.
  data_condition_binding = binding.of_caller(1)
  caller_instance = eval('self', data_condition_binding)

  if caller_instance.instance_variable_defined?(:@__condition_table)
    table = caller_instance.instance_variable_get(:@__condition_table)
  else
    table = RSpec::Variants::Table.new
    caller_instance.instance_variable_set(:@__condition_table, table)
  end

  row = Table::Row.new(self)
  table.add_row(row)
  row.add_condition(other)
  table
end