diff options
Diffstat (limited to 'spec/ruby/core/range/new_spec.rb')
| -rw-r--r-- | spec/ruby/core/range/new_spec.rb | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/spec/ruby/core/range/new_spec.rb b/spec/ruby/core/range/new_spec.rb index 26ea12867d..9a35f28c7e 100644 --- a/spec/ruby/core/range/new_spec.rb +++ b/spec/ruby/core/range/new_spec.rb @@ -25,21 +25,53 @@ describe "Range.new" do end it "raises an ArgumentError when the given start and end can't be compared by using #<=>" do - lambda { Range.new(1, mock('x')) }.should raise_error(ArgumentError) - lambda { Range.new(mock('x'), mock('y')) }.should raise_error(ArgumentError) + -> { Range.new(1, mock('x')) }.should.raise(ArgumentError) + -> { Range.new(mock('x'), mock('y')) }.should.raise(ArgumentError) b = mock('x') (a = mock('nil')).should_receive(:<=>).with(b).and_return(nil) - lambda { Range.new(a, b) }.should raise_error(ArgumentError) + -> { Range.new(a, b) }.should.raise(ArgumentError) end - ruby_version_is "2.5" do - it "does not rescue exception raised in #<=> when compares the given start and end" do - b = mock('a') - a = mock('b') - a.should_receive(:<=>).with(b).and_raise(RangeSpecs::ComparisonError) + it "does not rescue exception raised in #<=> when compares the given start and end" do + b = mock('a') + a = mock('b') + a.should_receive(:<=>).with(b).and_raise(RangeSpecs::ComparisonError) - -> { Range.new(a, b) }.should raise_error(RangeSpecs::ComparisonError) + -> { Range.new(a, b) }.should.raise(RangeSpecs::ComparisonError) + end + + describe "beginless/endless range" do + it "allows beginless left boundary" do + range = Range.new(nil, 1) + range.begin.should == nil + end + + it "distinguishes ranges with included and excluded right boundary" do + range_exclude = Range.new(nil, 1, true) + range_include = Range.new(nil, 1, false) + + range_exclude.should_not == range_include + end + + it "allows endless right boundary" do + range = Range.new(1, nil) + range.end.should == nil + end + + it "distinguishes ranges with included and excluded right boundary" do + range_exclude = Range.new(1, nil, true) + range_include = Range.new(1, nil, false) + + range_exclude.should_not == range_include + end + + it "creates a frozen range if the class is Range.class" do + Range.new(1, 2).should.frozen? + end + + it "does not create a frozen range if the class is not Range.class" do + Class.new(Range).new(1, 2).should_not.frozen? end end end |
