diff options
Diffstat (limited to 'spec/ruby/language/def_spec.rb')
-rw-r--r-- | spec/ruby/language/def_spec.rb | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb index dee60c9adf..82813bd36c 100644 --- a/spec/ruby/language/def_spec.rb +++ b/spec/ruby/language/def_spec.rb @@ -82,12 +82,12 @@ 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)') + -> { 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)') + -> { foo 1, 2 }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') end end @@ -113,12 +113,12 @@ describe "An instance method definition with a splat" do end it "allows only a single * argument" do - lambda { eval 'def foo(a, *b, *c); end' }.should raise_error(SyntaxError) + -> { eval 'def foo(a, *b, *c); end' }.should raise_error(SyntaxError) end it "requires the presence of any arguments that precede the *" do def foo(a, b, *c); end - lambda { foo 1 }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 2+)') + -> { foo 1 }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 2+)') end end @@ -151,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, 'wrong number of arguments (given 0, expected 1..2)') + -> { foo }.should raise_error(ArgumentError, 'wrong number of arguments (given 0, expected 1..2)') foo(1).should == [1, 2] end @@ -159,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, 'wrong number of arguments (given 0, expected 1+)') + -> { foo }.should raise_error(ArgumentError, 'wrong number of arguments (given 0, expected 1+)') foo(1).should == [1,2,[]] end @@ -249,7 +249,7 @@ describe "A singleton method definition" do it "raises #{frozen_error_class} if frozen" do obj = Object.new obj.freeze - lambda { def obj.foo; end }.should raise_error(frozen_error_class) + -> { def obj.foo; end }.should raise_error(frozen_error_class) end end @@ -322,7 +322,7 @@ describe "A method defined with extreme default arguments" do end it "may use a lambda as a default" do - def foo(output = 'a', prc = lambda {|n| output * n}) + def foo(output = 'a', prc = -> n { output * n }) prc.call(5) end foo.should == 'aaaaa' @@ -368,7 +368,7 @@ describe "A singleton method defined with extreme default arguments" do it "may use a lambda as a default" do a = Object.new - def a.foo(output = 'a', prc = lambda {|n| output * n}) + def a.foo(output = 'a', prc = -> n { output * n }) prc.call(5) end a.foo.should == 'aaaaa' @@ -384,7 +384,7 @@ describe "A method definition inside a metaclass scope" do end DefSpecSingleton.a_class_method.should == DefSpecSingleton - lambda { Object.a_class_method }.should raise_error(NoMethodError) + -> { Object.a_class_method }.should raise_error(NoMethodError) end it "can create a singleton method" do @@ -394,7 +394,7 @@ describe "A method definition inside a metaclass scope" do end obj.a_singleton_method.should == obj - lambda { Object.new.a_singleton_method }.should raise_error(NoMethodError) + -> { Object.new.a_singleton_method }.should raise_error(NoMethodError) end it "raises #{frozen_error_class} if frozen" do @@ -402,7 +402,7 @@ describe "A method definition inside a metaclass scope" do obj.freeze class << obj - lambda { def foo; end }.should raise_error(frozen_error_class) + -> { def foo; end }.should raise_error(frozen_error_class) end end end @@ -438,11 +438,11 @@ describe "A nested method definition" do end end - lambda { DefSpecNested.a_class_method }.should raise_error(NoMethodError) + -> { DefSpecNested.a_class_method }.should raise_error(NoMethodError) DefSpecNested.create_class_method.should == DefSpecNested DefSpecNested.a_class_method.should == DefSpecNested - lambda { Object.a_class_method }.should raise_error(NoMethodError) - lambda { DefSpecNested.new.a_class_method }.should raise_error(NoMethodError) + -> { Object.a_class_method }.should raise_error(NoMethodError) + -> { DefSpecNested.new.a_class_method }.should raise_error(NoMethodError) end it "creates a singleton method when evaluated in the metaclass of an instance" do @@ -460,7 +460,7 @@ describe "A nested method definition" do obj.a_singleton_method.should == obj other = DefSpecNested.new - lambda { other.a_singleton_method }.should raise_error(NoMethodError) + -> { other.a_singleton_method }.should raise_error(NoMethodError) end it "creates a method in the surrounding context when evaluated in a def expr.method" do @@ -559,7 +559,7 @@ describe "A method definition inside an instance_eval" do obj.an_instance_eval_method.should == obj other = Object.new - lambda { other.an_instance_eval_method }.should raise_error(NoMethodError) + -> { other.an_instance_eval_method }.should raise_error(NoMethodError) end it "creates a singleton method when evaluated inside a metaclass" do @@ -572,7 +572,7 @@ describe "A method definition inside an instance_eval" do obj.a_metaclass_eval_method.should == obj other = Object.new - lambda { other.a_metaclass_eval_method }.should raise_error(NoMethodError) + -> { other.a_metaclass_eval_method }.should raise_error(NoMethodError) end it "creates a class method when the receiver is a class" do @@ -581,7 +581,7 @@ describe "A method definition inside an instance_eval" do end DefSpecNested.an_instance_eval_class_method.should == DefSpecNested - lambda { Object.an_instance_eval_class_method }.should raise_error(NoMethodError) + -> { Object.an_instance_eval_class_method }.should raise_error(NoMethodError) end it "creates a class method when the receiver is an anonymous class" do @@ -593,7 +593,7 @@ describe "A method definition inside an instance_eval" do end m.klass_method.should == :test - lambda { Object.klass_method }.should raise_error(NoMethodError) + -> { Object.klass_method }.should raise_error(NoMethodError) end it "creates a class method when instance_eval is within class" do @@ -606,7 +606,7 @@ describe "A method definition inside an instance_eval" do end m.klass_method.should == :test - lambda { Object.klass_method }.should raise_error(NoMethodError) + -> { Object.klass_method }.should raise_error(NoMethodError) end end @@ -619,7 +619,7 @@ describe "A method definition inside an instance_exec" do end DefSpecNested.an_instance_exec_class_method.should == 1 - lambda { Object.an_instance_exec_class_method }.should raise_error(NoMethodError) + -> { Object.an_instance_exec_class_method }.should raise_error(NoMethodError) end it "creates a class method when the receiver is an anonymous class" do @@ -633,7 +633,7 @@ describe "A method definition inside an instance_exec" do end m.klass_method.should == 1 - lambda { Object.klass_method }.should raise_error(NoMethodError) + -> { Object.klass_method }.should raise_error(NoMethodError) end it "creates a class method when instance_exec is within class" do @@ -648,7 +648,7 @@ describe "A method definition inside an instance_exec" do end m.klass_method.should == 2 - lambda { Object.klass_method }.should raise_error(NoMethodError) + -> { Object.klass_method }.should raise_error(NoMethodError) end end @@ -668,7 +668,7 @@ describe "A method definition in an eval" do other = DefSpecNested.new other.an_eval_instance_method.should == other - lambda { Object.new.an_eval_instance_method }.should raise_error(NoMethodError) + -> { Object.new.an_eval_instance_method }.should raise_error(NoMethodError) end it "creates a class method" do @@ -684,8 +684,8 @@ describe "A method definition in an eval" do DefSpecNestedB.eval_class_method.should == DefSpecNestedB DefSpecNestedB.an_eval_class_method.should == DefSpecNestedB - lambda { Object.an_eval_class_method }.should raise_error(NoMethodError) - lambda { DefSpecNestedB.new.an_eval_class_method}.should raise_error(NoMethodError) + -> { Object.an_eval_class_method }.should raise_error(NoMethodError) + -> { DefSpecNestedB.new.an_eval_class_method}.should raise_error(NoMethodError) end it "creates a singleton method" do @@ -703,7 +703,7 @@ describe "A method definition in an eval" do obj.an_eval_singleton_method.should == obj other = DefSpecNested.new - lambda { other.an_eval_singleton_method }.should raise_error(NoMethodError) + -> { other.an_eval_singleton_method }.should raise_error(NoMethodError) end end @@ -729,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, 'wrong number of arguments (given 2, expected 0..1)') + -> { 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) @@ -740,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, 'wrong number of arguments (given 3, expected 0..2)') + -> { bar(3,4,5) }.should raise_error(ArgumentError, 'wrong number of arguments (given 3, expected 0..2)') end end @@ -750,7 +750,7 @@ describe "The def keyword" do module DefSpecsLambdaVisibility private - lambda { + -> { def some_method; end }.call end |