1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
require 'rspec/parameterized/table'
require 'binding_ninja'
module RSpec
module Parameterized
module TableSyntaxImplement
extend BindingNinja
def |(where_binding, other)
caller_instance = where_binding.receiver # 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
auto_inject_binding :|
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
|