Skip to content

Commit

Permalink
Get rid of evals
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Nov 15, 2020
1 parent f0a1592 commit 3ed3008
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
40 changes: 10 additions & 30 deletions spec/rspec/support/method_signature_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ def arity_optional(x, y, z = 1); end
end

describe 'a method with optional keyword arguments' do
eval <<-RUBY
def arity_kw(x, y:1, z:2); end
RUBY
def arity_kw(x, y:1, z:2); end

let(:test_method) { method(:arity_kw) }

Expand Down Expand Up @@ -298,9 +296,7 @@ def arity_kw(x, y:1, z:2); end
end

describe 'a method with optional argument and keyword arguments' do
eval <<-RUBY
def arity_kw(x, y = {}, z:2); end
RUBY
def arity_kw(x, y = {}, z:2); end

let(:test_method) { method(:arity_kw) }

Expand Down Expand Up @@ -392,9 +388,7 @@ def arity_kw(x, y = {}, z:2); end
end

describe 'a method with required keyword arguments' do
eval <<-RUBY
def arity_required_kw(x, y:, z:, a: 'default'); end
RUBY
def arity_required_kw(x, y:, z:, a: 'default'); end

let(:test_method) { method(:arity_required_kw) }

Expand Down Expand Up @@ -492,9 +486,7 @@ def arity_required_kw(x, y:, z:, a: 'default'); end
end

describe 'a method with required keyword arguments and a splat' do
eval <<-RUBY
def arity_required_kw_splat(w, *x, y:, z:, a: 'default'); end
RUBY
def arity_required_kw_splat(w, *x, y:, z:, a: 'default'); end

let(:test_method) { method(:arity_required_kw_splat) }

Expand Down Expand Up @@ -585,9 +577,7 @@ def arity_required_kw_splat(w, *x, y:, z:, a: 'default'); end
end

describe 'a method with required keyword arguments and a keyword arg splat' do
eval <<-RUBY
def arity_kw_arg_splat(x:, **rest); end
RUBY
def arity_kw_arg_splat(x:, **rest); end

let(:test_method) { method(:arity_kw_arg_splat) }

Expand Down Expand Up @@ -649,9 +639,7 @@ def arity_kw_arg_splat(x:, **rest); end
end

describe 'a method with a required arg and a keyword arg splat' do
eval <<-RUBY
def arity_kw_arg_splat(x, **rest); end
RUBY
def arity_kw_arg_splat(x, **rest); end

let(:test_method) { method(:arity_kw_arg_splat) }

Expand Down Expand Up @@ -924,9 +912,7 @@ def arity_block(_, &block); end
it_behaves_like 'a method verifier'

describe 'providing a matcher for optional keyword arguments' do
eval <<-RUBY
def arity_kw(x, y:1); end
RUBY
def arity_kw(x, y:1); end

let(:test_method) { method(:arity_kw) }

Expand All @@ -936,9 +922,7 @@ def arity_kw(x, y:1); end
end

describe 'providing a matcher for required keyword arguments' do
eval <<-RUBY
def arity_kw_required(x, y:); end
RUBY
def arity_kw_required(x, y:); end

let(:test_method) { method(:arity_kw_required) }

Expand All @@ -952,9 +936,7 @@ def arity_kw_required(x, y:); end
it_behaves_like 'a method verifier'

describe 'for optional keyword arguments' do
eval <<-RUBY
def arity_kw(x, y:1, z:2); end
RUBY
def arity_kw(x, y:1, z:2); end

let(:test_method) { method(:arity_kw) }

Expand All @@ -968,9 +950,7 @@ def arity_kw(x, y:1, z:2); end
end

describe 'providing a matcher for required keyword arguments' do
eval <<-RUBY
def arity_kw_required(x, y:); end
RUBY
def arity_kw_required(x, y:); end

let(:test_method) { method(:arity_kw_required) }

Expand Down
6 changes: 0 additions & 6 deletions spec/rspec/support/with_keywords_when_needed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,15 @@ def run(klass, *args, &block)
end

it "will run a block with optional keyword arguments when none are provided" do
binding.eval(<<-CODE, __FILE__, __LINE__)
run(klass, 42) { |arg, val: nil| check_argument(arg) }
CODE
end

it "will run a block with optional keyword arguments when they are provided" do
binding.eval(<<-CODE, __FILE__, __LINE__)
run(klass, val: 42) { |val: nil| check_argument(val) }
CODE
end

it "will run a block with required keyword arguments" do
binding.eval(<<-CODE, __FILE__, __LINE__)
run(klass, val: 42) { |val:| check_argument(val) }
CODE
end
end
end
Expand Down

0 comments on commit 3ed3008

Please sign in to comment.