diff options
Diffstat (limited to 'spec/ruby/core/range/first_spec.rb')
| -rw-r--r-- | spec/ruby/core/range/first_spec.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/spec/ruby/core/range/first_spec.rb b/spec/ruby/core/range/first_spec.rb index 7cd3781d34..54bd73a4e8 100644 --- a/spec/ruby/core/range/first_spec.rb +++ b/spec/ruby/core/range/first_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/begin', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/begin' describe "Range#first" do - it_behaves_like(:range_begin, :first) + it_behaves_like :range_begin, :first it "returns the specified number of elements from the beginning" do (0..2).first(2).should == [0, 1] @@ -21,7 +21,7 @@ describe "Range#first" do end it "raises an ArgumentError when count is negative" do - lambda { (0..2).first(-1) }.should raise_error(ArgumentError) + -> { (0..2).first(-1) }.should.raise(ArgumentError) end it "calls #to_int to convert the argument" do @@ -32,7 +32,7 @@ describe "Range#first" do it "raises a TypeError if #to_int does not return an Integer" do obj = mock("to_int") obj.should_receive(:to_int).and_return("1") - lambda { (2..3).first(obj) }.should raise_error(TypeError) + -> { (2..3).first(obj) }.should.raise(TypeError) end it "truncates the value when passed a Float" do @@ -40,10 +40,14 @@ describe "Range#first" do end it "raises a TypeError when passed nil" do - lambda { (2..3).first(nil) }.should raise_error(TypeError) + -> { (2..3).first(nil) }.should.raise(TypeError) end it "raises a TypeError when passed a String" do - lambda { (2..3).first("1") }.should raise_error(TypeError) + -> { (2..3).first("1") }.should.raise(TypeError) + end + + it "raises a RangeError when called on an beginless range" do + -> { (..1).first }.should.raise(RangeError) end end |
