File: table_syntax_implement.rb

package info (click to toggle)
ruby-rspec-parameterized-table-syntax 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 164 kB
  • sloc: ruby: 205; sh: 4; makefile: 4
file content (24 lines) | stat: -rw-r--r-- 772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module RSpec
  module Parameterized
    module TableSyntax
      module TableSyntaxImplement
        def |(other)
          where_binding = binding.of_caller(1)          # get where block binding
          caller_instance = eval("self", where_binding) # get caller instance (ExampleGroup)

          if caller_instance.instance_variable_defined?(:@__parameter_table)
            table = caller_instance.instance_variable_get(:@__parameter_table)
          else
            table = RSpec::Parameterized::TableSyntax::Table.new
            caller_instance.instance_variable_set(:@__parameter_table, table)
          end

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