diff options
Diffstat (limited to 'spec/ruby/core/array/initialize_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/initialize_spec.rb | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/spec/ruby/core/array/initialize_spec.rb b/spec/ruby/core/array/initialize_spec.rb index 0c37c6136d..b9fa77b16e 100644 --- a/spec/ruby/core/array/initialize_spec.rb +++ b/spec/ruby/core/array/initialize_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "Array#initialize" do before :each do @@ -24,21 +24,21 @@ describe "Array#initialize" do end it "raises an ArgumentError if passed 3 or more arguments" do - lambda do + -> do [1, 2].send :initialize, 1, 'x', true end.should raise_error(ArgumentError) - lambda do + -> do [1, 2].send(:initialize, 1, 'x', true) {} end.should raise_error(ArgumentError) end - it "raises a RuntimeError on frozen arrays" do - lambda do + it "raises a FrozenError on frozen arrays" do + -> do ArraySpecs.frozen_array.send :initialize - end.should raise_error(RuntimeError) - lambda do + end.should raise_error(FrozenError) + -> do ArraySpecs.frozen_array.send :initialize, ArraySpecs.frozen_array - end.should raise_error(RuntimeError) + end.should raise_error(FrozenError) end it "calls #to_ary to convert the value to an array, even if it's private" do @@ -53,7 +53,9 @@ describe "Array#initialize with no arguments" do end it "does not use the given block" do - lambda{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error + -> { + -> { [1, 2, 3].send(:initialize) { raise } }.should_not raise_error + }.should complain(/#{__FILE__}:#{__LINE__-1}: warning: given block not used/, verbose: true) end end @@ -64,7 +66,7 @@ describe "Array#initialize with (array)" do end it "does not use the given block" do - lambda{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error + ->{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error end it "calls #to_ary to convert the value to an array" do @@ -81,7 +83,7 @@ describe "Array#initialize with (array)" do end it "raises a TypeError if an Array type argument and a default object" do - lambda { [].send(:initialize, [1, 2], 1) }.should raise_error(TypeError) + -> { [].send(:initialize, [1, 2], 1) }.should raise_error(TypeError) end end @@ -103,12 +105,12 @@ describe "Array#initialize with (size, object=nil)" do end it "raises an ArgumentError if size is negative" do - lambda { [].send(:initialize, -1, :a) }.should raise_error(ArgumentError) - lambda { [].send(:initialize, -1) }.should raise_error(ArgumentError) + -> { [].send(:initialize, -1, :a) }.should raise_error(ArgumentError) + -> { [].send(:initialize, -1) }.should raise_error(ArgumentError) end it "raises an ArgumentError if size is too large" do - lambda { [].send(:initialize, fixnum_max+1) }.should raise_error(ArgumentError) + -> { [].send(:initialize, fixnum_max+1) }.should raise_error(ArgumentError) end it "calls #to_int to convert the size argument to an Integer when object is given" do @@ -126,7 +128,7 @@ describe "Array#initialize with (size, object=nil)" do it "raises a TypeError if the size argument is not an Integer type" do obj = mock('nonnumeric') obj.stub!(:to_ary).and_return([1, 2]) - lambda{ [].send(:initialize, obj, :a) }.should raise_error(TypeError) + ->{ [].send(:initialize, obj, :a) }.should raise_error(TypeError) end it "yields the index of the element and sets the element to the value of the block" do @@ -134,7 +136,7 @@ describe "Array#initialize with (size, object=nil)" do end it "uses the block value instead of using the default value" do - lambda { + -> { @result = [].send(:initialize, 3, :obj) { |i| i.to_s } }.should complain(/block supersedes default value argument/) @result.should == ['0', '1', '2'] |
