diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-27 20:38:57 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-27 20:38:57 +0000 |
commit | 50441014ffd3645f258e56b9415b7787c910408b (patch) | |
tree | 3d5eef5ad1ea7e389dc51fc87437664b984ac184 /spec/ruby/language | |
parent | 49cd16bfaf4f03885058ce748119bc8ea2de735a (diff) | |
download | ruby-50441014ffd3645f258e56b9415b7787c910408b.tar.gz |
Update to ruby/spec@cdd6ff7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/language')
-rw-r--r-- | spec/ruby/language/def_spec.rb | 22 | ||||
-rw-r--r-- | spec/ruby/language/method_spec.rb | 15 |
2 files changed, 31 insertions, 6 deletions
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb index 95469546c7..dee60c9adf 100644 --- a/spec/ruby/language/def_spec.rb +++ b/spec/ruby/language/def_spec.rb @@ -79,6 +79,18 @@ describe "Defining a method" do end end +describe "An instance method" do + it "raises an error with too few arguments" do + def foo(a, b); end + lambda { foo 1 }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 2)') + end + + it "raises an error with too many arguments" do + def foo(a); end + lambda { foo 1, 2 }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') + end +end + describe "An instance method definition with a splat" do it "accepts an unnamed '*' argument" do def foo(*); end; @@ -106,7 +118,7 @@ describe "An instance method definition with a splat" do it "requires the presence of any arguments that precede the *" do def foo(a, b, *c); end - lambda { foo 1 }.should raise_error(ArgumentError) + lambda { foo 1 }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 2+)') end end @@ -139,7 +151,7 @@ describe "An instance method with a default argument" do def foo(a, b = 2) [a,b] end - lambda { foo }.should raise_error(ArgumentError) + lambda { foo }.should raise_error(ArgumentError, 'wrong number of arguments (given 0, expected 1..2)') foo(1).should == [1, 2] end @@ -147,7 +159,7 @@ describe "An instance method with a default argument" do def foo(a, b = 2, *c) [a,b,c] end - lambda { foo }.should raise_error(ArgumentError) + lambda { foo }.should raise_error(ArgumentError, 'wrong number of arguments (given 0, expected 1+)') foo(1).should == [1,2,[]] end @@ -717,7 +729,7 @@ describe "a method definition that sets more than one default parameter all to t end it "only allows overriding the default value of the first such parameter in each set" do - lambda { foo(1,2) }.should raise_error(ArgumentError) + lambda { foo(1,2) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 0..1)') end def bar(a=b=c=1,d=2) @@ -728,7 +740,7 @@ describe "a method definition that sets more than one default parameter all to t bar.should == [1,1,1,2] bar(3).should == [3,nil,nil,2] bar(3,4).should == [3,nil,nil,4] - lambda { bar(3,4,5) }.should raise_error(ArgumentError) + lambda { bar(3,4,5) }.should raise_error(ArgumentError, 'wrong number of arguments (given 3, expected 0..2)') end end diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb index 54f0c6ccf8..c5612ed19f 100644 --- a/spec/ruby/language/method_spec.rb +++ b/spec/ruby/language/method_spec.rb @@ -1269,7 +1269,7 @@ describe "A method" do def m(a, b = nil, c = nil, d, e: nil, **f) [a, b, c, d, e, f] end - ruby + ruby result = m(1, 2) result.should == [1, nil, nil, 2, nil, {}] @@ -1281,6 +1281,19 @@ describe "A method" do result.should == [1, nil, nil, {foo: :bar}, nil, {}] end end + + context "assigns keyword arguments from a passed Hash without modifying it" do + evaluate <<-ruby do + def m(a: nil); a; end + ruby + + options = {a: 1}.freeze + lambda do + m(options).should == 1 + end.should_not raise_error + options.should == {a: 1} + end + end end describe "A method call with a space between method name and parentheses" do |