Sha256: b0f32e5427f5c64336371b9bd74bdcb5a3b801a0ec3f15fe34e3b823bd8c9993

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'binding_of_caller'
require 'rspec/parameterized/table'

module RSpec
  module Parameterized
    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::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

    module TableSyntax
      refine Object do
        include TableSyntaxImplement
      end

      if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create("2.4.0")
        refine Integer do
          include TableSyntaxImplement
        end
      else
        refine Fixnum do
          include TableSyntaxImplement
        end

        refine Bignum do
          include TableSyntaxImplement
        end
      end

      refine Array do
        include TableSyntaxImplement
      end

      refine NilClass do
        include TableSyntaxImplement
      end

      refine TrueClass do
        include TableSyntaxImplement
      end

      refine FalseClass do
        include TableSyntaxImplement
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-parameterized-0.4.0 lib/rspec/parameterized/table_syntax.rb
rspec-parameterized-0.3.2 lib/rspec/parameterized/table_syntax.rb