Skip to content

Commit

Permalink
Use binding_of_caller instead of binding_ninja
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Dec 24, 2022
1 parent 76daa96 commit 0760ea6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
64 changes: 39 additions & 25 deletions lib/rspec/parameterized/table_syntax.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require 'rspec/parameterized/table'
require 'binding_ninja'
require 'binding_of_caller'

module RSpec
module Parameterized
module TableSyntaxImplement
extend BindingNinja

def |(where_binding, other)
caller_instance = where_binding.receiver # get caller instance (ExampleGroup)
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)
Expand All @@ -21,42 +20,57 @@ def |(where_binding, other)
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("3.2.0.rc1")
refine Object do
import_methods TableSyntaxImplement
end

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

refine Array do
import_methods TableSyntaxImplement
end

refine NilClass do
import_methods TableSyntaxImplement
end

refine TrueClass do
import_methods TableSyntaxImplement
end

refine FalseClass do
import_methods TableSyntaxImplement
end
else
refine Fixnum do
refine Object do
include TableSyntaxImplement
end

refine Bignum do
refine Integer do
include TableSyntaxImplement
end
end

refine Array do
include TableSyntaxImplement
end
refine Array do
include TableSyntaxImplement
end

refine NilClass do
include TableSyntaxImplement
end
refine NilClass do
include TableSyntaxImplement
end

refine TrueClass do
include TableSyntaxImplement
end
refine TrueClass do
include TableSyntaxImplement
end

refine FalseClass do
include TableSyntaxImplement
refine FalseClass do
include TableSyntaxImplement
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion rspec-parameterized.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ I was inspired by [udzura's mock](https://gist.github.com/1881139).}
gem.add_dependency('parser')
gem.add_dependency('unparser')
gem.add_dependency('proc_to_ast')
gem.add_dependency('binding_ninja', '>= 0.2.3')
gem.add_dependency('binding_of_caller')
gem.add_development_dependency('rake', '>= 12.0.0')

gem.files = `git ls-files`.split($\)
Expand Down

0 comments on commit 0760ea6

Please sign in to comment.