aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/language/def_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/def_spec.rb')
-rw-r--r--spec/ruby/language/def_spec.rb35
1 files changed, 25 insertions, 10 deletions
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb
index 82813bd36c..fc5693a2f0 100644
--- a/spec/ruby/language/def_spec.rb
+++ b/spec/ruby/language/def_spec.rb
@@ -177,17 +177,32 @@ describe "An instance method with a default argument" do
foo(2,3,3).should == [2,3,[3]]
end
- it "shadows an existing method with the same name as the local" do
- def bar
- 1
+ ruby_version_is ''...'2.7' do
+ it "warns and uses a nil value when there is an existing local method with same name" do
+ def bar
+ 1
+ end
+ -> {
+ eval "def foo(bar = bar)
+ bar
+ end"
+ }.should complain(/circular argument reference/)
+ foo.should == nil
+ foo(2).should == 2
+ end
+ end
+
+ ruby_version_is '2.7' do
+ it "raises a syntaxError an existing method with the same name as the local variable" do
+ def bar
+ 1
+ end
+ -> {
+ eval "def foo(bar = bar)
+ bar
+ end"
+ }.should raise_error(SyntaxError)
end
- -> {
- eval "def foo(bar = bar)
- bar
- end"
- }.should complain(/circular argument reference/)
- foo.should == nil
- foo(2).should == 2
end
it "calls a method with the same name as the local when explicitly using ()" do