diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml index 762fe42bad..d29261079e 100644 --- a/spec/ruby/.rubocop.yml +++ b/spec/ruby/.rubocop.yml @@ -55,6 +55,11 @@ Lint/EmptyExpression: Exclude: - 'language/**/*.rb' +Lint/EmptyWhen: + Exclude: + - language/case_spec.rb + - optional/capi/spec_helper.rb + Lint/UriRegexp: Exclude: - 'library/uri/regexp_spec.rb' diff --git a/spec/ruby/.travis.yml b/spec/ruby/.travis.yml index 767d437f67..f79cd22aca 100644 --- a/spec/ruby/.travis.yml +++ b/spec/ruby/.travis.yml @@ -3,29 +3,24 @@ language: ruby install: - git clone https://github.com/ruby/mspec.git ../mspec script: - - if [ -n "$RUBOCOP" ]; then gem install rubocop -v 0.52.0 && rubocop; fi - ../mspec/bin/mspec $MSPEC_OPTS matrix: include: - - os: osx - osx_image: xcode9 - rvm: 2.4.2 - env: CHECK_LEAKS=true - - os: linux - rvm: 2.4.2 + - rvm: 2.5.0 env: MSPEC_OPTS="-R2 -ff" - - os: linux - rvm: 2.2.8 - - os: linux - rvm: 2.3.5 - - os: linux - rvm: 2.4.2 - env: CHECK_LEAKS=true RUBOCOP=true - - os: linux - rvm: ruby-head + - rvm: 2.2.9 + - rvm: 2.3.6 + - rvm: 2.4.3 + - rvm: 2.5.0 + env: CHECK_LEAKS=true + - rvm: ruby-head + - env: RUBOCOP=true + rvm: 2.4.3 + script: + - gem install rubocop -v 0.52.0 + - rubocop allow_failures: - - os: linux - rvm: ruby-head + - rvm: ruby-head branches: only: - master diff --git a/spec/ruby/core/array/append_spec.rb b/spec/ruby/core/array/append_spec.rb index 90e1688c5a..5131e71b3c 100644 --- a/spec/ruby/core/array/append_spec.rb +++ b/spec/ruby/core/array/append_spec.rb @@ -30,8 +30,8 @@ describe "Array#<<" do a.should == [:foo] end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array << 5 }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array << 5 }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/clear_spec.rb b/spec/ruby/core/array/clear_spec.rb index 851c90d654..0789adaa4e 100644 --- a/spec/ruby/core/array/clear_spec.rb +++ b/spec/ruby/core/array/clear_spec.rb @@ -41,9 +41,9 @@ describe "Array#clear" do a.untrusted?.should be_true end - it "raises a RuntimeError on a frozen array" do + it "raises a #{frozen_error_class} on a frozen array" do a = [1] a.freeze - lambda { a.clear }.should raise_error(RuntimeError) + lambda { a.clear }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/compact_spec.rb b/spec/ruby/core/array/compact_spec.rb index b80f0214ec..21106d1d6f 100644 --- a/spec/ruby/core/array/compact_spec.rb +++ b/spec/ruby/core/array/compact_spec.rb @@ -71,7 +71,7 @@ describe "Array#compact!" do a.untrusted?.should be_true end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.compact! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.compact! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/concat_spec.rb b/spec/ruby/core/array/concat_spec.rb index 86ec557bde..a92cf3c8db 100644 --- a/spec/ruby/core/array/concat_spec.rb +++ b/spec/ruby/core/array/concat_spec.rb @@ -32,13 +32,13 @@ describe "Array#concat" do [].concat(obj).should == [5, 6, 7] end - it "raises a RuntimeError when Array is frozen and modification occurs" do - lambda { ArraySpecs.frozen_array.concat [1] }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when Array is frozen and modification occurs" do + lambda { ArraySpecs.frozen_array.concat [1] }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError when Array is frozen and no modification occurs" do - lambda { ArraySpecs.frozen_array.concat([]) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when Array is frozen and no modification occurs" do + lambda { ArraySpecs.frozen_array.concat([]) }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/delete_at_spec.rb b/spec/ruby/core/array/delete_at_spec.rb index 1d73ceb33a..4c2deb13a1 100644 --- a/spec/ruby/core/array/delete_at_spec.rb +++ b/spec/ruby/core/array/delete_at_spec.rb @@ -35,8 +35,8 @@ describe "Array#delete_at" do a.delete_at(-2).should == 1 end - it "raises a RuntimeError on a frozen array" do - lambda { [1,2,3].freeze.delete_at(0) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { [1,2,3].freeze.delete_at(0) }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/delete_if_spec.rb b/spec/ruby/core/array/delete_if_spec.rb index 4276a1fb65..e8d79270b4 100644 --- a/spec/ruby/core/array/delete_if_spec.rb +++ b/spec/ruby/core/array/delete_if_spec.rb @@ -39,12 +39,12 @@ describe "Array#delete_if" do @a.freeze.delete_if.should be_an_instance_of(Enumerator) end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.delete_if {} }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.delete_if {} }.should raise_error(frozen_error_class) end - it "raises a RuntimeError on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty frozen array" do + lambda { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/delete_spec.rb b/spec/ruby/core/array/delete_spec.rb index 7b6bf3930c..cbd30d6f07 100644 --- a/spec/ruby/core/array/delete_spec.rb +++ b/spec/ruby/core/array/delete_spec.rb @@ -40,8 +40,8 @@ describe "Array#delete" do [1, 2, 3].freeze.delete(0).should == nil end - it "raises a RuntimeError on a frozen array" do - lambda { [1, 2, 3].freeze.delete(1) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { [1, 2, 3].freeze.delete(1) }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb index 6544ad9b6f..9c6a1d05a8 100644 --- a/spec/ruby/core/array/element_set_spec.rb +++ b/spec/ruby/core/array/element_set_spec.rb @@ -94,8 +94,8 @@ describe "Array#[]=" do it "checks frozen before attempting to coerce arguments" do a = [1,2,3,4].freeze - lambda {a[:foo] = 1}.should raise_error(RuntimeError) - lambda {a[:foo, :bar] = 1}.should raise_error(RuntimeError) + lambda {a[:foo] = 1}.should raise_error(frozen_error_class) + lambda {a[:foo, :bar] = 1}.should raise_error(frozen_error_class) end it "sets elements in the range arguments when passed ranges" do @@ -236,8 +236,8 @@ describe "Array#[]=" do ary.should == [5, 6, 7] end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array[0, 0] = [] }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array[0, 0] = [] }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/fill_spec.rb b/spec/ruby/core/array/fill_spec.rb index 5ff7f8a250..1c44d54421 100644 --- a/spec/ruby/core/array/fill_spec.rb +++ b/spec/ruby/core/array/fill_spec.rb @@ -43,12 +43,12 @@ describe "Array#fill" do [nil, nil, nil, nil].fill { |i| i * 2 }.should == [0, 2, 4, 6] end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.fill('x') }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.fill('x') }.should raise_error(frozen_error_class) end - it "raises a RuntimeError on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.fill('x') }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty frozen array" do + lambda { ArraySpecs.empty_frozen_array.fill('x') }.should raise_error(frozen_error_class) end it "raises an ArgumentError if 4 or more arguments are passed when no block given" do diff --git a/spec/ruby/core/array/flatten_spec.rb b/spec/ruby/core/array/flatten_spec.rb index 3b20e976b6..3c8502c827 100644 --- a/spec/ruby/core/array/flatten_spec.rb +++ b/spec/ruby/core/array/flatten_spec.rb @@ -272,15 +272,15 @@ describe "Array#flatten!" do ary.should == [1, 2, 3] end - it "raises a RuntimeError on frozen arrays when the array is modified" do + it "raises a #{frozen_error_class} on frozen arrays when the array is modified" do nested_ary = [1, 2, []] nested_ary.freeze - lambda { nested_ary.flatten! }.should raise_error(RuntimeError) + lambda { nested_ary.flatten! }.should raise_error(frozen_error_class) end # see [ruby-core:23663] - it "raises a RuntimeError on frozen arrays when the array would not be modified" do - lambda { ArraySpecs.frozen_array.flatten! }.should raise_error(RuntimeError) - lambda { ArraySpecs.empty_frozen_array.flatten! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on frozen arrays when the array would not be modified" do + lambda { ArraySpecs.frozen_array.flatten! }.should raise_error(frozen_error_class) + lambda { ArraySpecs.empty_frozen_array.flatten! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/initialize_spec.rb b/spec/ruby/core/array/initialize_spec.rb index 0c37c6136d..b51b76acd3 100644 --- a/spec/ruby/core/array/initialize_spec.rb +++ b/spec/ruby/core/array/initialize_spec.rb @@ -32,13 +32,13 @@ describe "Array#initialize" do end.should raise_error(ArgumentError) end - it "raises a RuntimeError on frozen arrays" do + it "raises a #{frozen_error_class} on frozen arrays" do lambda do ArraySpecs.frozen_array.send :initialize - end.should raise_error(RuntimeError) + end.should raise_error(frozen_error_class) lambda do ArraySpecs.frozen_array.send :initialize, ArraySpecs.frozen_array - end.should raise_error(RuntimeError) + end.should raise_error(frozen_error_class) end it "calls #to_ary to convert the value to an array, even if it's private" do diff --git a/spec/ruby/core/array/insert_spec.rb b/spec/ruby/core/array/insert_spec.rb index cdf870df2a..c7acdac275 100644 --- a/spec/ruby/core/array/insert_spec.rb +++ b/spec/ruby/core/array/insert_spec.rb @@ -67,12 +67,12 @@ describe "Array#insert" do lambda { [].insert() }.should raise_error(ArgumentError) end - it "raises a RuntimeError on frozen arrays when the array is modified" do - lambda { ArraySpecs.frozen_array.insert(0, 'x') }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on frozen arrays when the array is modified" do + lambda { ArraySpecs.frozen_array.insert(0, 'x') }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on frozen arrays when the array would not be modified" do - lambda { ArraySpecs.frozen_array.insert(0) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on frozen arrays when the array would not be modified" do + lambda { ArraySpecs.frozen_array.insert(0) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/pack/j_spec.rb b/spec/ruby/core/array/pack/j_spec.rb index 88f074724c..1fe81db61f 100644 --- a/spec/ruby/core/array/pack/j_spec.rb +++ b/spec/ruby/core/array/pack/j_spec.rb @@ -5,10 +5,7 @@ require File.expand_path('../shared/numeric_basic', __FILE__) require File.expand_path('../shared/integer', __FILE__) ruby_version_is '2.3' do - # To handle the special case of x64-mingw32 - pointer_size = RUBY_PLATFORM =~ /\bx64\b/ ? 64 : 1.size * 8 - - guard -> { pointer_size == 64 } do + platform_is pointer_size: 64 do describe "Array#pack with format 'J'" do it_behaves_like :array_pack_basic, 'J' it_behaves_like :array_pack_basic_non_float, 'J' @@ -114,7 +111,7 @@ ruby_version_is '2.3' do end end - guard -> { pointer_size == 32 } do + platform_is pointer_size: 32 do describe "Array#pack with format 'J'" do it_behaves_like :array_pack_basic, 'J' it_behaves_like :array_pack_basic_non_float, 'J' diff --git a/spec/ruby/core/array/pop_spec.rb b/spec/ruby/core/array/pop_spec.rb index ea649c6585..aa3eb031a2 100644 --- a/spec/ruby/core/array/pop_spec.rb +++ b/spec/ruby/core/array/pop_spec.rb @@ -38,12 +38,12 @@ describe "Array#pop" do a.tainted?.should be_true end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.pop }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.pop }.should raise_error(frozen_error_class) end - it "raises a RuntimeError on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty frozen array" do + lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(frozen_error_class) end it "keeps untrusted status" do @@ -152,9 +152,9 @@ describe "Array#pop" do ary.pop(0).untrusted?.should be_false end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.pop(2) }.should raise_error(RuntimeError) - lambda { ArraySpecs.frozen_array.pop(0) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.pop(2) }.should raise_error(frozen_error_class) + lambda { ArraySpecs.frozen_array.pop(0) }.should raise_error(frozen_error_class) end it "keeps untrusted status" do diff --git a/spec/ruby/core/array/reject_spec.rb b/spec/ruby/core/array/reject_spec.rb index 857cbf6a4d..2dba6f58e7 100644 --- a/spec/ruby/core/array/reject_spec.rb +++ b/spec/ruby/core/array/reject_spec.rb @@ -103,12 +103,12 @@ describe "Array#reject!" do ArraySpecs.frozen_array.reject!.should be_an_instance_of(Enumerator) end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(frozen_error_class) end - it "raises a RuntimeError on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty frozen array" do + lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(frozen_error_class) end it_behaves_like :enumeratorize, :reject! diff --git a/spec/ruby/core/array/reverse_spec.rb b/spec/ruby/core/array/reverse_spec.rb index a3a6db9506..061d9540ba 100644 --- a/spec/ruby/core/array/reverse_spec.rb +++ b/spec/ruby/core/array/reverse_spec.rb @@ -36,7 +36,7 @@ describe "Array#reverse!" do array.reverse!.should == [array, array, array, array, array, 3.0, 'two', 1] end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.reverse! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.reverse! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/rotate_spec.rb b/spec/ruby/core/array/rotate_spec.rb index 270bfeb446..56c1f7e0ee 100644 --- a/spec/ruby/core/array/rotate_spec.rb +++ b/spec/ruby/core/array/rotate_spec.rb @@ -121,9 +121,9 @@ describe "Array#rotate!" do a.should == [] end - it "raises a RuntimeError on a frozen array" do - lambda { [1, 2, 3].freeze.rotate!(0) }.should raise_error(RuntimeError) - lambda { [1].freeze.rotate!(42) }.should raise_error(RuntimeError) - lambda { [].freeze.rotate! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { [1, 2, 3].freeze.rotate!(0) }.should raise_error(frozen_error_class) + lambda { [1].freeze.rotate!(42) }.should raise_error(frozen_error_class) + lambda { [].freeze.rotate! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shared/collect.rb b/spec/ruby/core/array/shared/collect.rb index f6bcfd8904..2c75675b9d 100644 --- a/spec/ruby/core/array/shared/collect.rb +++ b/spec/ruby/core/array/shared/collect.rb @@ -110,22 +110,22 @@ describe :array_collect_b, shared: true do end describe "when frozen" do - it "raises a RuntimeError" do - lambda { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class}" do + lambda { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(frozen_error_class) end - it "raises a RuntimeError when empty" do - lambda { ArraySpecs.empty_frozen_array.send(@method) {} }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when empty" do + lambda { ArraySpecs.empty_frozen_array.send(@method) {} }.should raise_error(frozen_error_class) end - it "raises a RuntimeError when calling #each on the returned Enumerator" do + it "raises a #{frozen_error_class} when calling #each on the returned Enumerator" do enumerator = ArraySpecs.frozen_array.send(@method) - lambda { enumerator.each {|x| x } }.should raise_error(RuntimeError) + lambda { enumerator.each {|x| x } }.should raise_error(frozen_error_class) end - it "raises a RuntimeError when calling #each on the returned Enumerator when empty" do + it "raises a #{frozen_error_class} when calling #each on the returned Enumerator when empty" do enumerator = ArraySpecs.empty_frozen_array.send(@method) - lambda { enumerator.each {|x| x } }.should raise_error(RuntimeError) + lambda { enumerator.each {|x| x } }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shared/keep_if.rb b/spec/ruby/core/array/shared/keep_if.rb index 581ba31d1b..0f65d060d8 100644 --- a/spec/ruby/core/array/shared/keep_if.rb +++ b/spec/ruby/core/array/shared/keep_if.rb @@ -41,8 +41,8 @@ describe :keep_if, shared: true do @frozen.should == @origin end - it "raises a RuntimeError" do - lambda { @frozen.send(@method) { true } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class}" do + lambda { @frozen.send(@method) { true } }.should raise_error(frozen_error_class) end end @@ -52,8 +52,8 @@ describe :keep_if, shared: true do @frozen.should == @origin end - it "raises a RuntimeError" do - lambda { @frozen.send(@method) { false } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class}" do + lambda { @frozen.send(@method) { false } }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/array/shared/push.rb b/spec/ruby/core/array/shared/push.rb index 5951b71a19..effa632890 100644 --- a/spec/ruby/core/array/shared/push.rb +++ b/spec/ruby/core/array/shared/push.rb @@ -26,8 +26,8 @@ describe :array_push, shared: true do array.send(@method, :last).should == [1, 'two', 3.0, array, array, array, array, array, :last] end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(RuntimeError) - lambda { ArraySpecs.frozen_array.send(@method) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(frozen_error_class) + lambda { ArraySpecs.frozen_array.send(@method) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shared/replace.rb b/spec/ruby/core/array/shared/replace.rb index 8442d9a841..b8dae8d33e 100644 --- a/spec/ruby/core/array/shared/replace.rb +++ b/spec/ruby/core/array/shared/replace.rb @@ -52,9 +52,9 @@ describe :array_replace, shared: true do [].send(@method, ArraySpecs::ToAryArray[5, 6, 7]).should == [5, 6, 7] end - it "raises a RuntimeError on a frozen array" do + it "raises a #{frozen_error_class} on a frozen array" do lambda { ArraySpecs.frozen_array.send(@method, ArraySpecs.frozen_array) - }.should raise_error(RuntimeError) + }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shared/unshift.rb b/spec/ruby/core/array/shared/unshift.rb index 367bab4166..d7464cdaca 100644 --- a/spec/ruby/core/array/shared/unshift.rb +++ b/spec/ruby/core/array/shared/unshift.rb @@ -35,12 +35,12 @@ describe :array_unshift, shared: true do array[0..5].should == [:new, 1, 'two', 3.0, array, array] end - it "raises a RuntimeError on a frozen array when the array is modified" do - lambda { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array when the array is modified" do + lambda { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen array when the array would not be modified" do - lambda { ArraySpecs.frozen_array.send(@method) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array when the array would not be modified" do + lambda { ArraySpecs.frozen_array.send(@method) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shift_spec.rb b/spec/ruby/core/array/shift_spec.rb index a7b6f58392..45a9c44ad7 100644 --- a/spec/ruby/core/array/shift_spec.rb +++ b/spec/ruby/core/array/shift_spec.rb @@ -30,11 +30,11 @@ describe "Array#shift" do array[0..2].should == ['two', 3.0, array] end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.shift }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.shift }.should raise_error(frozen_error_class) end - it "raises a RuntimeError on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty frozen array" do + lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(frozen_error_class) end describe "passed a number n as an argument" do diff --git a/spec/ruby/core/array/shuffle_spec.rb b/spec/ruby/core/array/shuffle_spec.rb index 4c3b820186..bd6f379893 100644 --- a/spec/ruby/core/array/shuffle_spec.rb +++ b/spec/ruby/core/array/shuffle_spec.rb @@ -95,8 +95,8 @@ describe "Array#shuffle!" do a.should equal(original) end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.shuffle! }.should raise_error(RuntimeError) - lambda { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.shuffle! }.should raise_error(frozen_error_class) + lambda { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/slice_spec.rb b/spec/ruby/core/array/slice_spec.rb index f6cbd1bcc4..31d2983aef 100644 --- a/spec/ruby/core/array/slice_spec.rb +++ b/spec/ruby/core/array/slice_spec.rb @@ -150,8 +150,8 @@ describe "Array#slice!" do a.should == [1, 2] end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.slice!(0, 0) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.slice!(0, 0) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/sort_by_spec.rb b/spec/ruby/core/array/sort_by_spec.rb index 9f45f3ef4d..16fabce69f 100644 --- a/spec/ruby/core/array/sort_by_spec.rb +++ b/spec/ruby/core/array/sort_by_spec.rb @@ -23,12 +23,12 @@ describe "Array#sort_by!" do a.should be_an_instance_of(Array) end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.sort_by! {}}.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.sort_by! {}}.should raise_error(frozen_error_class) end - it "raises a RuntimeError on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.sort_by! {}}.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty frozen array" do + lambda { ArraySpecs.empty_frozen_array.sort_by! {}}.should raise_error(frozen_error_class) end it "returns the specified value when it would break in the given block" do diff --git a/spec/ruby/core/array/sort_spec.rb b/spec/ruby/core/array/sort_spec.rb index 0578742175..070b4e84a3 100644 --- a/spec/ruby/core/array/sort_spec.rb +++ b/spec/ruby/core/array/sort_spec.rb @@ -233,8 +233,8 @@ describe "Array#sort!" do a.sort!{ -1 }.should be_an_instance_of(Array) end - it "raises a RuntimeError on a frozen array" do - lambda { ArraySpecs.frozen_array.sort! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array" do + lambda { ArraySpecs.frozen_array.sort! }.should raise_error(frozen_error_class) end it "returns the specified value when it would break in the given block" do diff --git a/spec/ruby/core/array/uniq_spec.rb b/spec/ruby/core/array/uniq_spec.rb index 199b084376..001ca73731 100644 --- a/spec/ruby/core/array/uniq_spec.rb +++ b/spec/ruby/core/array/uniq_spec.rb @@ -188,20 +188,20 @@ describe "Array#uniq!" do [ "a", "b", "c" ].uniq!.should == nil end - it "raises a RuntimeError on a frozen array when the array is modified" do + it "raises a #{frozen_error_class} on a frozen array when the array is modified" do dup_ary = [1, 1, 2] dup_ary.freeze - lambda { dup_ary.uniq! }.should raise_error(RuntimeError) + lambda { dup_ary.uniq! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen array when the array would not be modified" do - lambda { ArraySpecs.frozen_array.uniq!}.should raise_error(RuntimeError) - lambda { ArraySpecs.empty_frozen_array.uniq!}.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen array when the array would not be modified" do + lambda { ArraySpecs.frozen_array.uniq!}.should raise_error(frozen_error_class) + lambda { ArraySpecs.empty_frozen_array.uniq!}.should raise_error(frozen_error_class) end it "doesn't yield to the block on a frozen array" do - lambda { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(RuntimeError) + lambda { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(frozen_error_class) end it "compares elements based on the value returned from the block" do diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb index d2201cd6cd..40973995c1 100644 --- a/spec/ruby/core/dir/shared/glob.rb +++ b/spec/ruby/core/dir/shared/glob.rb @@ -275,6 +275,78 @@ describe :dir_glob, shared: true do Dir.send(@method, "special/こんにちは{,.txt}").should == ["special/こんにちは.txt"] end end + + ruby_version_is "2.5" do + context ":base option passed" do + before :each do + @mock_dir = File.expand_path tmp('dir_glob_mock') + + %w[ + a/b/x + a/b/c/y + a/b/c/d/z + ].each do |path| + file = File.join @mock_dir, path + mkdir_p File.dirname(file) + touch file + end + end + + after :each do + rm_r @mock_dir + end + + it "matches entries only from within the specified directory" do + path = File.join(@mock_dir, "a/b/c") + Dir.send(@method, "*", base: path).sort.should == %w( d y ) + end + + it "accepts both relative and absolute pathes" do + require 'pathname' + + path_abs = File.join(@mock_dir, "a/b/c") + path_rel = Pathname.new(path_abs).relative_path_from(Pathname.new(Dir.pwd)) + + result_abs = Dir.send(@method, "*", base: path_abs).sort + result_rel = Dir.send(@method, "*", base: path_rel).sort + + result_abs.should == %w( d y ) + result_rel.should == %w( d y ) + end + + it "returns [] if specified path does not exist" do + path = File.join(@mock_dir, "fake-name") + File.exist?(path).should == false + + Dir.send(@method, "*", base: path).should == [] + end + + it "returns [] if specified path is a file" do + path = File.join(@mock_dir, "a/b/x") + File.exist?(path).should == true + + Dir.send(@method, "*", base: path).should == [] + end + + it "raises TypeError whene cannot convert value to string" do + -> { + Dir.send(@method, "*", base: []) + }.should raise_error(TypeError) + end + + it "handles '' as current directory path" do + Dir.chdir @mock_dir do + Dir.send(@method, "*", base: "").should == %w( a ) + end + end + + it "handles nil as current directory path" do + Dir.chdir @mock_dir do + Dir.send(@method, "*", base: nil).should == %w( a ) + end + end + end + end end describe :dir_glob_recursive, shared: true do diff --git a/spec/ruby/core/exception/interrupt_spec.rb b/spec/ruby/core/exception/interrupt_spec.rb index ef24743936..27c8a4aed1 100644 --- a/spec/ruby/core/exception/interrupt_spec.rb +++ b/spec/ruby/core/exception/interrupt_spec.rb @@ -20,7 +20,7 @@ describe "Interrupt.new" do end end -describe "rescueing Interrupt" do +describe "rescuing Interrupt" do before do @original_sigint_proc = Signal.trap(:INT, :SIG_DFL) end diff --git a/spec/ruby/core/exception/signal_exception_spec.rb b/spec/ruby/core/exception/signal_exception_spec.rb index 3b2d1aad61..84e5cb0ad9 100644 --- a/spec/ruby/core/exception/signal_exception_spec.rb +++ b/spec/ruby/core/exception/signal_exception_spec.rb @@ -60,7 +60,7 @@ describe "SignalException.new" do end end -describe "rescueing SignalException" do +describe "rescuing SignalException" do it "raises a SignalException when sent a signal" do begin Process.kill :TERM, Process.pid diff --git a/spec/ruby/core/exception/standard_error_spec.rb b/spec/ruby/core/exception/standard_error_spec.rb index 9b3af4b322..326844c65a 100644 --- a/spec/ruby/core/exception/standard_error_spec.rb +++ b/spec/ruby/core/exception/standard_error_spec.rb @@ -47,4 +47,10 @@ describe "StandardError" do it "is a superclass of ZeroDivisionError" do StandardError.should be_ancestor_of(ZeroDivisionError) end + + ruby_version_is '2.5' do + it "is a superclass of FrozenError" do + StandardError.should be_ancestor_of(FrozenError) + end + end end diff --git a/spec/ruby/core/file/utime_spec.rb b/spec/ruby/core/file/utime_spec.rb index e586029715..1d9ccd9f71 100644 --- a/spec/ruby/core/file/utime_spec.rb +++ b/spec/ruby/core/file/utime_spec.rb @@ -34,6 +34,14 @@ describe "File.utime" do File.utime(@atime, @mtime, mock_to_path(@file1), mock_to_path(@file2)) end + it "accepts numeric atime and mtime arguments" do + File.utime(@atime.to_i, @mtime.to_i, @file1, @file2) + File.atime(@file1).to_i.should be_close(@atime.to_i, 2) + File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2) + File.atime(@file2).to_i.should be_close(@atime.to_i, 2) + File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2) + end + platform_is :linux do platform_is wordsize: 64 do it "allows Time instances in the far future to set mtime and atime" do diff --git a/spec/ruby/core/float/divide_spec.rb b/spec/ruby/core/float/divide_spec.rb index 0acd7b20b4..34d6ef45e1 100644 --- a/spec/ruby/core/float/divide_spec.rb +++ b/spec/ruby/core/float/divide_spec.rb @@ -1,7 +1,10 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/coerce.rb', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) describe "Float#/" do + it_behaves_like :float_arithmetic_exception_in_coerce, :/ + it "returns self divided by other" do (5.75 / -2).should be_close(-2.875,TOLERANCE) (451.0 / 9.3).should be_close(48.494623655914,TOLERANCE) diff --git a/spec/ruby/core/float/fixtures/classes.rb b/spec/ruby/core/float/fixtures/classes.rb new file mode 100644 index 0000000000..2d80184e7d --- /dev/null +++ b/spec/ruby/core/float/fixtures/classes.rb @@ -0,0 +1,4 @@ +module FloatSpecs + class CoerceError < StandardError + end +end diff --git a/spec/ruby/core/float/gt_spec.rb b/spec/ruby/core/float/gt_spec.rb index 9725c6acd7..96ea805f90 100644 --- a/spec/ruby/core/float/gt_spec.rb +++ b/spec/ruby/core/float/gt_spec.rb @@ -1,6 +1,9 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) describe "Float#>" do + it_behaves_like :float_comparison_exception_in_coerce, :> + it "returns true if self is greater than other" do (1.5 > 1).should == true (2.5 > 3).should == false diff --git a/spec/ruby/core/float/gte_spec.rb b/spec/ruby/core/float/gte_spec.rb index 2c14651dd7..1903308763 100644 --- a/spec/ruby/core/float/gte_spec.rb +++ b/spec/ruby/core/float/gte_spec.rb @@ -1,6 +1,9 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) describe "Float#>=" do + it_behaves_like :float_comparison_exception_in_coerce, :>= + it "returns true if self is greater than or equal to other" do (5.2 >= 5.2).should == true (9.71 >= 1).should == true diff --git a/spec/ruby/core/float/lt_spec.rb b/spec/ruby/core/float/lt_spec.rb index e2e43b0fb7..d83fee0d4a 100644 --- a/spec/ruby/core/float/lt_spec.rb +++ b/spec/ruby/core/float/lt_spec.rb @@ -1,6 +1,9 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) describe "Float#<" do + it_behaves_like :float_comparison_exception_in_coerce, :< + it "returns true if self is less than other" do (71.3 < 91.8).should == true (192.6 < -500).should == false diff --git a/spec/ruby/core/float/lte_spec.rb b/spec/ruby/core/float/lte_spec.rb index e2e44b2257..3d5f830633 100644 --- a/spec/ruby/core/float/lte_spec.rb +++ b/spec/ruby/core/float/lte_spec.rb @@ -1,6 +1,9 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) describe "Float#<=" do + it_behaves_like :float_comparison_exception_in_coerce, :>= + it "returns true if self is less than or equal to other" do (2.0 <= 3.14159).should == true (-2.7183 <= -24).should == false diff --git a/spec/ruby/core/float/minus_spec.rb b/spec/ruby/core/float/minus_spec.rb index d5c0d863ed..49a81e2fc8 100644 --- a/spec/ruby/core/float/minus_spec.rb +++ b/spec/ruby/core/float/minus_spec.rb @@ -1,6 +1,9 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) describe "Float#-" do + it_behaves_like :float_arithmetic_exception_in_coerce, :- + it "returns self minus other" do (9_237_212.5280 - 5_280).should be_close(9231932.528, TOLERANCE) (2_560_496.1691 - bignum_value).should be_close(-9223372036852215808.000, TOLERANCE) diff --git a/spec/ruby/core/float/multiply_spec.rb b/spec/ruby/core/float/multiply_spec.rb index 14680534c4..f13beb7641 100644 --- a/spec/ruby/core/float/multiply_spec.rb +++ b/spec/ruby/core/float/multiply_spec.rb @@ -1,6 +1,9 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) describe "Float#*" do + it_behaves_like :float_arithmetic_exception_in_coerce, :* + it "returns self multiplied by other" do (4923.98221 * 2).should be_close(9847.96442, TOLERANCE) (6712.5 * 0.25).should be_close(1678.125, TOLERANCE) diff --git a/spec/ruby/core/float/plus_spec.rb b/spec/ruby/core/float/plus_spec.rb index a49124d303..743ac5f618 100644 --- a/spec/ruby/core/float/plus_spec.rb +++ b/spec/ruby/core/float/plus_spec.rb @@ -1,6 +1,9 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) describe "Float#+" do + it_behaves_like :float_arithmetic_exception_in_coerce, :+ + it "returns self plus other" do (491.213 + 2).should be_close(493.213, TOLERANCE) (9.99 + bignum_value).should be_close(9223372036854775808.000, TOLERANCE) diff --git a/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb new file mode 100644 index 0000000000..0d9f32af16 --- /dev/null +++ b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb @@ -0,0 +1,34 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +describe :float_arithmetic_exception_in_coerce, shared: true do + ruby_version_is ""..."2.5" do + it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) + + # e.g. 1.0 > b + -> { 1.0.send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into Float/) + end + + it "does not rescue Exception and StandardError siblings raised in other#coerce" do + [Exception, NoMemoryError].each do |exception| + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(exception) + + # e.g. 1.0 > b + -> { 1.0.send(@method, b) }.should raise_error(exception) + end + end + end + + ruby_version_is "2.5" do + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) + + # e.g. 1.0 > b + -> { 1.0.send(@method, b) }.should raise_error(FloatSpecs::CoerceError) + end + end +end + diff --git a/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb new file mode 100644 index 0000000000..688e5dc0d1 --- /dev/null +++ b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb @@ -0,0 +1,36 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +describe :float_comparison_exception_in_coerce, shared: true do + ruby_version_is ""..."2.5" do + it "rescues exception (StandardError and subclasses) raised in other#coerce and raises ArgumentError" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) + + # e.g. 1.0 > b + -> { + -> { 1.0.send(@method, b) }.should raise_error(ArgumentError, /comparison of Float with MockObject failed/) + }.should complain(/Numerical comparison operators will no more rescue exceptions of #coerce/) + end + + it "does not rescue Exception and StandardError siblings raised in other#coerce" do + [Exception, NoMemoryError].each do |exception| + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(exception) + + # e.g. 1.0 > b + -> { 1.0.send(@method, b) }.should raise_error(exception) + end + end + end + + ruby_version_is "2.5" do + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) + + # e.g. 1.0 > b + -> { 1.0.send(@method, b) }.should raise_error(FloatSpecs::CoerceError) + end + end +end + diff --git a/spec/ruby/core/hash/clear_spec.rb b/spec/ruby/core/hash/clear_spec.rb index ea8235451a..1d57dfbcc6 100644 --- a/spec/ruby/core/hash/clear_spec.rb +++ b/spec/ruby/core/hash/clear_spec.rb @@ -25,8 +25,8 @@ describe "Hash#clear" do h.default_proc.should_not == nil end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.clear }.should raise_error(RuntimeError) - lambda { HashSpecs.empty_frozen_hash.clear }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.clear }.should raise_error(frozen_error_class) + lambda { HashSpecs.empty_frozen_hash.clear }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/compact_spec.rb b/spec/ruby/core/hash/compact_spec.rb index d9ef8a2987..15c2e651c4 100644 --- a/spec/ruby/core/hash/compact_spec.rb +++ b/spec/ruby/core/hash/compact_spec.rb @@ -52,8 +52,8 @@ ruby_version_is "2.4" do @hash.freeze end - it "keeps pairs and raises a RuntimeError" do - ->{ @hash.compact! }.should raise_error(RuntimeError) + it "keeps pairs and raises a #{frozen_error_class}" do + ->{ @hash.compact! }.should raise_error(frozen_error_class) @hash.should == @initial_pairs end end diff --git a/spec/ruby/core/hash/compare_by_identity_spec.rb b/spec/ruby/core/hash/compare_by_identity_spec.rb index a518e0cdb3..34541037b9 100644 --- a/spec/ruby/core/hash/compare_by_identity_spec.rb +++ b/spec/ruby/core/hash/compare_by_identity_spec.rb @@ -80,9 +80,9 @@ describe "Hash#compare_by_identity" do @h[o].should == :o end - it "raises a RuntimeError on frozen hashes" do + it "raises a #{frozen_error_class} on frozen hashes" do @h = @h.freeze - lambda { @h.compare_by_identity }.should raise_error(RuntimeError) + lambda { @h.compare_by_identity }.should raise_error(frozen_error_class) end # Behaviour confirmed in bug #1871 diff --git a/spec/ruby/core/hash/default_proc_spec.rb b/spec/ruby/core/hash/default_proc_spec.rb index 0bd20d43af..64287cbc7c 100644 --- a/spec/ruby/core/hash/default_proc_spec.rb +++ b/spec/ruby/core/hash/default_proc_spec.rb @@ -73,8 +73,8 @@ describe "Hash#default_proc=" do end.should raise_error(TypeError) end - it "raises a RuntimeError if self is frozen" do - lambda { {}.freeze.default_proc = Proc.new {} }.should raise_error(RuntimeError) - lambda { {}.freeze.default_proc = nil }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if self is frozen" do + lambda { {}.freeze.default_proc = Proc.new {} }.should raise_error(frozen_error_class) + lambda { {}.freeze.default_proc = nil }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/default_spec.rb b/spec/ruby/core/hash/default_spec.rb index 6c1c7377b7..45e0b9d1fe 100644 --- a/spec/ruby/core/hash/default_spec.rb +++ b/spec/ruby/core/hash/default_spec.rb @@ -39,8 +39,8 @@ describe "Hash#default=" do end end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.default = nil }.should raise_error(RuntimeError) - lambda { HashSpecs.empty_frozen_hash.default = nil }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.default = nil }.should raise_error(frozen_error_class) + lambda { HashSpecs.empty_frozen_hash.default = nil }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/delete_if_spec.rb b/spec/ruby/core/hash/delete_if_spec.rb index d739e4fbab..2edc88a205 100644 --- a/spec/ruby/core/hash/delete_if_spec.rb +++ b/spec/ruby/core/hash/delete_if_spec.rb @@ -34,9 +34,9 @@ describe "Hash#delete_if" do each_pairs.should == delete_pairs end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.delete_if { false } }.should raise_error(RuntimeError) - lambda { HashSpecs.empty_frozen_hash.delete_if { true } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.delete_if { false } }.should raise_error(frozen_error_class) + lambda { HashSpecs.empty_frozen_hash.delete_if { true } }.should raise_error(frozen_error_class) end it_behaves_like(:hash_iteration_no_block, :delete_if) diff --git a/spec/ruby/core/hash/delete_spec.rb b/spec/ruby/core/hash/delete_spec.rb index a41fad3586..e673e12f67 100644 --- a/spec/ruby/core/hash/delete_spec.rb +++ b/spec/ruby/core/hash/delete_spec.rb @@ -37,8 +37,8 @@ describe "Hash#delete" do { key => 5 }.delete(key).should == 5 end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.delete("foo") }.should raise_error(RuntimeError) - lambda { HashSpecs.empty_frozen_hash.delete("foo") }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.delete("foo") }.should raise_error(frozen_error_class) + lambda { HashSpecs.empty_frozen_hash.delete("foo") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/initialize_spec.rb b/spec/ruby/core/hash/initialize_spec.rb index aa943d333d..cafe2f0af9 100644 --- a/spec/ruby/core/hash/initialize_spec.rb +++ b/spec/ruby/core/hash/initialize_spec.rb @@ -24,17 +24,17 @@ describe "Hash#initialize" do h.send(:initialize).should equal(h) end - it "raises a RuntimeError if called on a frozen instance" do + it "raises a #{frozen_error_class} if called on a frozen instance" do block = lambda { HashSpecs.frozen_hash.instance_eval { initialize() }} - block.should raise_error(RuntimeError) + block.should raise_error(frozen_error_class) block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(nil) } } - block.should raise_error(RuntimeError) + block.should raise_error(frozen_error_class) block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(5) } } - block.should raise_error(RuntimeError) + block.should raise_error(frozen_error_class) block = lambda { HashSpecs.frozen_hash.instance_eval { initialize { 5 } } } - block.should raise_error(RuntimeError) + block.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/keep_if_spec.rb b/spec/ruby/core/hash/keep_if_spec.rb index 6b3a1925d3..7a9db092e2 100644 --- a/spec/ruby/core/hash/keep_if_spec.rb +++ b/spec/ruby/core/hash/keep_if_spec.rb @@ -27,9 +27,9 @@ describe "Hash#keep_if" do h.keep_if { true }.should equal(h) end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.keep_if { true } }.should raise_error(RuntimeError) - lambda { HashSpecs.empty_frozen_hash.keep_if { false } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.keep_if { true } }.should raise_error(frozen_error_class) + lambda { HashSpecs.empty_frozen_hash.keep_if { false } }.should raise_error(frozen_error_class) end it_behaves_like(:hash_iteration_no_block, :keep_if) diff --git a/spec/ruby/core/hash/rehash_spec.rb b/spec/ruby/core/hash/rehash_spec.rb index 09315737b6..5b15af923a 100644 --- a/spec/ruby/core/hash/rehash_spec.rb +++ b/spec/ruby/core/hash/rehash_spec.rb @@ -35,8 +35,8 @@ describe "Hash#rehash" do h[k2].should == v2 end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.rehash }.should raise_error(RuntimeError) - lambda { HashSpecs.empty_frozen_hash.rehash }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.rehash }.should raise_error(frozen_error_class) + lambda { HashSpecs.empty_frozen_hash.rehash }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb index 21dd7425aa..557435a019 100644 --- a/spec/ruby/core/hash/reject_spec.rb +++ b/spec/ruby/core/hash/reject_spec.rb @@ -87,12 +87,12 @@ describe "Hash#reject!" do reject_bang_pairs.should == delete_if_pairs end - it "raises a RuntimeError if called on a frozen instance that is modified" do - lambda { HashSpecs.empty_frozen_hash.reject! { true } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance that is modified" do + lambda { HashSpecs.empty_frozen_hash.reject! { true } }.should raise_error(frozen_error_class) end - it "raises a RuntimeError if called on a frozen instance that would not be modified" do - lambda { HashSpecs.frozen_hash.reject! { false } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do + lambda { HashSpecs.frozen_hash.reject! { false } }.should raise_error(frozen_error_class) end it_behaves_like(:hash_iteration_no_block, :reject!) diff --git a/spec/ruby/core/hash/select_spec.rb b/spec/ruby/core/hash/select_spec.rb index 449607b606..8a73116bc1 100644 --- a/spec/ruby/core/hash/select_spec.rb +++ b/spec/ruby/core/hash/select_spec.rb @@ -70,12 +70,12 @@ describe "Hash#select!" do { a: 1 }.select! { |k,v| v <= 1 }.should == nil end - it "raises a RuntimeError if called on an empty frozen instance" do - lambda { HashSpecs.empty_frozen_hash.select! { false } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on an empty frozen instance" do + lambda { HashSpecs.empty_frozen_hash.select! { false } }.should raise_error(frozen_error_class) end - it "raises a RuntimeError if called on a frozen instance that would not be modified" do - lambda { HashSpecs.frozen_hash.select! { true } }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do + lambda { HashSpecs.frozen_hash.select! { true } }.should raise_error(frozen_error_class) end it_behaves_like(:hash_iteration_no_block, :select!) diff --git a/spec/ruby/core/hash/shared/replace.rb b/spec/ruby/core/hash/shared/replace.rb index 463c861395..eb51130781 100644 --- a/spec/ruby/core/hash/shared/replace.rb +++ b/spec/ruby/core/hash/shared/replace.rb @@ -37,15 +37,15 @@ describe :hash_replace, shared: true do hash_a.default.should == hash_b.default end - it "raises a RuntimeError if called on a frozen instance that would not be modified" do + it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do lambda do HashSpecs.frozen_hash.send(@method, HashSpecs.frozen_hash) - end.should raise_error(RuntimeError) + end.should raise_error(frozen_error_class) end - it "raises a RuntimeError if called on a frozen instance that is modified" do + it "raises a #{frozen_error_class} if called on a frozen instance that is modified" do lambda do HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash) - end.should raise_error(RuntimeError) + end.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/shared/store.rb b/spec/ruby/core/hash/shared/store.rb index b43dcbc93e..6f8390fd95 100644 --- a/spec/ruby/core/hash/shared/store.rb +++ b/spec/ruby/core/hash/shared/store.rb @@ -86,8 +86,8 @@ describe :hash_store, shared: true do h.keys.last.should_not equal(key2) end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(frozen_error_class) end it "does not raise an exception if changing the value of an existing key during iteration" do diff --git a/spec/ruby/core/hash/shared/update.rb b/spec/ruby/core/hash/shared/update.rb index b1e3793028..be03ac019e 100644 --- a/spec/ruby/core/hash/shared/update.rb +++ b/spec/ruby/core/hash/shared/update.rb @@ -34,10 +34,10 @@ describe :hash_update, shared: true do merge_bang_pairs.should == merge_pairs end - it "raises a RuntimeError on a frozen instance that is modified" do + it "raises a #{frozen_error_class} on a frozen instance that is modified" do lambda do HashSpecs.frozen_hash.send(@method, 1 => 2) - end.should raise_error(RuntimeError) + end.should raise_error(frozen_error_class) end it "checks frozen status before coercing an object with #to_hash" do @@ -47,13 +47,13 @@ describe :hash_update, shared: true do def obj.to_hash() raise Exception, "should not receive #to_hash" end obj.freeze - lambda { HashSpecs.frozen_hash.send(@method, obj) }.should raise_error(RuntimeError) + lambda { HashSpecs.frozen_hash.send(@method, obj) }.should raise_error(frozen_error_class) end # see redmine #1571 - it "raises a RuntimeError on a frozen instance that would not be modified" do + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do lambda do HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash) - end.should raise_error(RuntimeError) + end.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/shift_spec.rb b/spec/ruby/core/hash/shift_spec.rb index 3991da9656..8476ef890a 100644 --- a/spec/ruby/core/hash/shift_spec.rb +++ b/spec/ruby/core/hash/shift_spec.rb @@ -57,8 +57,8 @@ describe "Hash#shift" do h.should == {:c => 3} end - it "raises a RuntimeError if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.shift }.should raise_error(RuntimeError) - lambda { HashSpecs.empty_frozen_hash.shift }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if called on a frozen instance" do + lambda { HashSpecs.frozen_hash.shift }.should raise_error(frozen_error_class) + lambda { HashSpecs.empty_frozen_hash.shift }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/transform_keys_spec.rb b/spec/ruby/core/hash/transform_keys_spec.rb index 379638bd4b..7888486d42 100644 --- a/spec/ruby/core/hash/transform_keys_spec.rb +++ b/spec/ruby/core/hash/transform_keys_spec.rb @@ -91,12 +91,12 @@ ruby_version_is "2.5" do @hash.freeze end - it "raises a RuntimeError on an empty hash" do - ->{ {}.freeze.transform_keys!(&:upcase) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty hash" do + ->{ {}.freeze.transform_keys!(&:upcase) }.should raise_error(frozen_error_class) end - it "keeps pairs and raises a RuntimeError" do - ->{ @hash.transform_keys!(&:upcase) }.should raise_error(RuntimeError) + it "keeps pairs and raises a #{frozen_error_class}" do + ->{ @hash.transform_keys!(&:upcase) }.should raise_error(frozen_error_class) @hash.should == @initial_pairs end diff --git a/spec/ruby/core/hash/transform_values_spec.rb b/spec/ruby/core/hash/transform_values_spec.rb index a9098a9f2d..5f928becb2 100644 --- a/spec/ruby/core/hash/transform_values_spec.rb +++ b/spec/ruby/core/hash/transform_values_spec.rb @@ -80,12 +80,12 @@ ruby_version_is "2.4" do @hash.freeze end - it "raises a RuntimeError on an empty hash" do - ->{ {}.freeze.transform_values!(&:succ) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on an empty hash" do + ->{ {}.freeze.transform_values!(&:succ) }.should raise_error(frozen_error_class) end - it "keeps pairs and raises a RuntimeError" do - ->{ @hash.transform_values!(&:succ) }.should raise_error(RuntimeError) + it "keeps pairs and raises a #{frozen_error_class}" do + ->{ @hash.transform_values!(&:succ) }.should raise_error(frozen_error_class) @hash.should == @initial_pairs end diff --git a/spec/ruby/core/integer/allbits_spec.rb b/spec/ruby/core/integer/allbits_spec.rb index 54c99265ba..a8ae19be15 100644 --- a/spec/ruby/core/integer/allbits_spec.rb +++ b/spec/ruby/core/integer/allbits_spec.rb @@ -1,37 +1,39 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe "Integer#allbits?" do - it "returns true iff all the bits of the argument are set in the receiver" do - 42.allbits?(42).should == true - 0b1010_1010.allbits?(0b1000_0010).should == true - 0b1010_1010.allbits?(0b1000_0001).should == false - 0b1000_0010.allbits?(0b1010_1010).should == false - (0b1010_1010 | bignum_value).allbits?(0b1000_0010 | bignum_value).should == true - (0b1010_1010 | bignum_value).allbits?(0b1000_0001 | bignum_value).should == false - (0b1000_0010 | bignum_value).allbits?(0b1010_1010 | bignum_value).should == false - end +ruby_version_is '2.5' do + describe "Integer#allbits?" do + it "returns true iff all the bits of the argument are set in the receiver" do + 42.allbits?(42).should == true + 0b1010_1010.allbits?(0b1000_0010).should == true + 0b1010_1010.allbits?(0b1000_0001).should == false + 0b1000_0010.allbits?(0b1010_1010).should == false + (0b1010_1010 | bignum_value).allbits?(0b1000_0010 | bignum_value).should == true + (0b1010_1010 | bignum_value).allbits?(0b1000_0001 | bignum_value).should == false + (0b1000_0010 | bignum_value).allbits?(0b1010_1010 | bignum_value).should == false + end - it "handles negative values using two's complement notation" do - (~0b1).allbits?(42).should == true - (-42).allbits?(-42).should == true - (~0b1010_1010).allbits?(~0b1110_1011).should == true - (~0b1010_1010).allbits?(~0b1000_0010).should == false - (~(0b1010_1010 | bignum_value)).allbits?(~(0b1110_1011 | bignum_value)).should == true - (~(0b1010_1010 | bignum_value)).allbits?(~(0b1000_0010 | bignum_value)).should == false - end + it "handles negative values using two's complement notation" do + (~0b1).allbits?(42).should == true + (-42).allbits?(-42).should == true + (~0b1010_1010).allbits?(~0b1110_1011).should == true + (~0b1010_1010).allbits?(~0b1000_0010).should == false + (~(0b1010_1010 | bignum_value)).allbits?(~(0b1110_1011 | bignum_value)).should == true + (~(0b1010_1010 | bignum_value)).allbits?(~(0b1000_0010 | bignum_value)).should == false + end - it "coerces the rhs using to_int" do - obj = mock("the int 0b10") - obj.should_receive(:to_int).and_return(0b10) - 0b110.allbits?(obj).should == true - end + it "coerces the rhs using to_int" do + obj = mock("the int 0b10") + obj.should_receive(:to_int).and_return(0b10) + 0b110.allbits?(obj).should == true + end - it "raises a TypeError when given a non-Integer" do - lambda { - (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) - 13.allbits?(obj) - }.should raise_error(TypeError) - lambda { 13.allbits?("10") }.should raise_error(TypeError) - lambda { 13.allbits?(:symbol) }.should raise_error(TypeError) + it "raises a TypeError when given a non-Integer" do + lambda { + (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) + 13.allbits?(obj) + }.should raise_error(TypeError) + lambda { 13.allbits?("10") }.should raise_error(TypeError) + lambda { 13.allbits?(:symbol) }.should raise_error(TypeError) + end end end diff --git a/spec/ruby/core/integer/anybits_spec.rb b/spec/ruby/core/integer/anybits_spec.rb index 409e2e65c5..e2fd009a5f 100644 --- a/spec/ruby/core/integer/anybits_spec.rb +++ b/spec/ruby/core/integer/anybits_spec.rb @@ -1,36 +1,38 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe "Integer#anybits?" do - it "returns true iff all the bits of the argument are set in the receiver" do - 42.anybits?(42).should == true - 0b1010_1010.anybits?(0b1000_0010).should == true - 0b1010_1010.anybits?(0b1000_0001).should == true - 0b1000_0010.anybits?(0b0010_1100).should == false - different_bignum = (2 * bignum_value) & (~bignum_value) - (0b1010_1010 | different_bignum).anybits?(0b1000_0010 | bignum_value).should == true - (0b1010_1010 | different_bignum).anybits?(0b0010_1100 | bignum_value).should == true - (0b1000_0010 | different_bignum).anybits?(0b0010_1100 | bignum_value).should == false - end +ruby_version_is '2.5' do + describe "Integer#anybits?" do + it "returns true iff all the bits of the argument are set in the receiver" do + 42.anybits?(42).should == true + 0b1010_1010.anybits?(0b1000_0010).should == true + 0b1010_1010.anybits?(0b1000_0001).should == true + 0b1000_0010.anybits?(0b0010_1100).should == false + different_bignum = (2 * bignum_value) & (~bignum_value) + (0b1010_1010 | different_bignum).anybits?(0b1000_0010 | bignum_value).should == true + (0b1010_1010 | different_bignum).anybits?(0b0010_1100 | bignum_value).should == true + (0b1000_0010 | different_bignum).anybits?(0b0010_1100 | bignum_value).should == false + end - it "handles negative values using two's complement notation" do - (~42).anybits?(42).should == false - (-42).anybits?(-42).should == true - (~0b100).anybits?(~0b1).should == true - (~(0b100 | bignum_value)).anybits?(~(0b1 | bignum_value)).should == true - end + it "handles negative values using two's complement notation" do + (~42).anybits?(42).should == false + (-42).anybits?(-42).should == true + (~0b100).anybits?(~0b1).should == true + (~(0b100 | bignum_value)).anybits?(~(0b1 | bignum_value)).should == true + end - it "coerces the rhs using to_int" do - obj = mock("the int 0b10") - obj.should_receive(:to_int).and_return(0b10) - 0b110.anybits?(obj).should == true - end + it "coerces the rhs using to_int" do + obj = mock("the int 0b10") + obj.should_receive(:to_int).and_return(0b10) + 0b110.anybits?(obj).should == true + end - it "raises a TypeError when given a non-Integer" do - lambda { - (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) - 13.anybits?(obj) - }.should raise_error(TypeError) - lambda { 13.anybits?("10") }.should raise_error(TypeError) - lambda { 13.anybits?(:symbol) }.should raise_error(TypeError) + it "raises a TypeError when given a non-Integer" do + lambda { + (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) + 13.anybits?(obj) + }.should raise_error(TypeError) + lambda { 13.anybits?("10") }.should raise_error(TypeError) + lambda { 13.anybits?(:symbol) }.should raise_error(TypeError) + end end end diff --git a/spec/ruby/core/integer/divide_spec.rb b/spec/ruby/core/integer/divide_spec.rb new file mode 100644 index 0000000000..6c81d5474f --- /dev/null +++ b/spec/ruby/core/integer/divide_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) + +describe "Integer#/" do + it_behaves_like :integer_arithmetic_exception_in_coerce, :/ +end + diff --git a/spec/ruby/core/integer/fixtures/classes.rb b/spec/ruby/core/integer/fixtures/classes.rb new file mode 100644 index 0000000000..6ebfbd1565 --- /dev/null +++ b/spec/ruby/core/integer/fixtures/classes.rb @@ -0,0 +1,4 @@ +module IntegerSpecs + class CoerceError < StandardError + end +end diff --git a/spec/ruby/core/integer/gt_spec.rb b/spec/ruby/core/integer/gt_spec.rb new file mode 100644 index 0000000000..ec0834d346 --- /dev/null +++ b/spec/ruby/core/integer/gt_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) + +describe "Integer#>" do + it_behaves_like :integer_comparison_exception_in_coerce, :> +end + diff --git a/spec/ruby/core/integer/gte_spec.rb b/spec/ruby/core/integer/gte_spec.rb new file mode 100644 index 0000000000..a49535f823 --- /dev/null +++ b/spec/ruby/core/integer/gte_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) + +describe "Integer#>=" do + it_behaves_like :integer_comparison_exception_in_coerce, :>= +end + diff --git a/spec/ruby/core/integer/lt_spec.rb b/spec/ruby/core/integer/lt_spec.rb new file mode 100644 index 0000000000..3b778d7f6c --- /dev/null +++ b/spec/ruby/core/integer/lt_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) + +describe "Integer#<" do + it_behaves_like :integer_comparison_exception_in_coerce, :< +end diff --git a/spec/ruby/core/integer/lte_spec.rb b/spec/ruby/core/integer/lte_spec.rb new file mode 100644 index 0000000000..d62780c78c --- /dev/null +++ b/spec/ruby/core/integer/lte_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__) + +describe "Integer#<=" do + it_behaves_like :integer_comparison_exception_in_coerce, :<= +end diff --git a/spec/ruby/core/integer/minus_spec.rb b/spec/ruby/core/integer/minus_spec.rb new file mode 100644 index 0000000000..6e8fa69759 --- /dev/null +++ b/spec/ruby/core/integer/minus_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) + +describe "Integer#-" do + it_behaves_like :integer_arithmetic_exception_in_coerce, :- +end + diff --git a/spec/ruby/core/integer/multiply_spec.rb b/spec/ruby/core/integer/multiply_spec.rb new file mode 100644 index 0000000000..cfce2418a4 --- /dev/null +++ b/spec/ruby/core/integer/multiply_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) + +describe "Integer#*" do + it_behaves_like :integer_arithmetic_exception_in_coerce, :* +end diff --git a/spec/ruby/core/integer/nobits_spec.rb b/spec/ruby/core/integer/nobits_spec.rb index 5b5d82a040..cfa63a4b94 100644 --- a/spec/ruby/core/integer/nobits_spec.rb +++ b/spec/ruby/core/integer/nobits_spec.rb @@ -1,36 +1,38 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe "Integer#nobits?" do - it "returns true iff all no bits of the argument are set in the receiver" do - 42.nobits?(42).should == false - 0b1010_1010.nobits?(0b1000_0010).should == false - 0b1010_1010.nobits?(0b1000_0001).should == false - 0b0100_0101.nobits?(0b1010_1010).should == true - different_bignum = (2 * bignum_value) & (~bignum_value) - (0b1010_1010 | different_bignum).nobits?(0b1000_0010 | bignum_value).should == false - (0b1010_1010 | different_bignum).nobits?(0b1000_0001 | bignum_value).should == false - (0b0100_0101 | different_bignum).nobits?(0b1010_1010 | bignum_value).should == true - end +ruby_version_is '2.5' do + describe "Integer#nobits?" do + it "returns true iff all no bits of the argument are set in the receiver" do + 42.nobits?(42).should == false + 0b1010_1010.nobits?(0b1000_0010).should == false + 0b1010_1010.nobits?(0b1000_0001).should == false + 0b0100_0101.nobits?(0b1010_1010).should == true + different_bignum = (2 * bignum_value) & (~bignum_value) + (0b1010_1010 | different_bignum).nobits?(0b1000_0010 | bignum_value).should == false + (0b1010_1010 | different_bignum).nobits?(0b1000_0001 | bignum_value).should == false + (0b0100_0101 | different_bignum).nobits?(0b1010_1010 | bignum_value).should == true + end - it "handles negative values using two's complement notation" do - (~0b1101).nobits?(0b1101).should == true - (-42).nobits?(-42).should == false - (~0b1101).nobits?(~0b10).should == false - (~(0b1101 | bignum_value)).nobits?(~(0b10 | bignum_value)).should == false - end + it "handles negative values using two's complement notation" do + (~0b1101).nobits?(0b1101).should == true + (-42).nobits?(-42).should == false + (~0b1101).nobits?(~0b10).should == false + (~(0b1101 | bignum_value)).nobits?(~(0b10 | bignum_value)).should == false + end - it "coerces the rhs using to_int" do - obj = mock("the int 0b10") - obj.should_receive(:to_int).and_return(0b10) - 0b110.nobits?(obj).should == false - end + it "coerces the rhs using to_int" do + obj = mock("the int 0b10") + obj.should_receive(:to_int).and_return(0b10) + 0b110.nobits?(obj).should == false + end - it "raises a TypeError when given a non-Integer" do - lambda { - (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) - 13.nobits?(obj) - }.should raise_error(TypeError) - lambda { 13.nobits?("10") }.should raise_error(TypeError) - lambda { 13.nobits?(:symbol) }.should raise_error(TypeError) + it "raises a TypeError when given a non-Integer" do + lambda { + (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) + 13.nobits?(obj) + }.should raise_error(TypeError) + lambda { 13.nobits?("10") }.should raise_error(TypeError) + lambda { 13.nobits?(:symbol) }.should raise_error(TypeError) + end end end diff --git a/spec/ruby/core/integer/plus_spec.rb b/spec/ruby/core/integer/plus_spec.rb new file mode 100644 index 0000000000..c292943d06 --- /dev/null +++ b/spec/ruby/core/integer/plus_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__) + +describe "Integer#+" do + it_behaves_like :integer_arithmetic_exception_in_coerce, :+ +end diff --git a/spec/ruby/core/integer/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/integer/shared/arithmetic_exception_in_coerce.rb new file mode 100644 index 0000000000..dd3f55d444 --- /dev/null +++ b/spec/ruby/core/integer/shared/arithmetic_exception_in_coerce.rb @@ -0,0 +1,33 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +describe :integer_arithmetic_exception_in_coerce, shared: true do + ruby_version_is ""..."2.5" do + it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError) + + # e.g. 1 + b + -> { 1.send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into #{1.class}/) + end + + it "does not rescue Exception and StandardError siblings raised in other#coerce" do + [Exception, NoMemoryError].each do |exception| + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(exception) + + # e.g. 1 + b + -> { 1.send(@method, b) }.should raise_error(exception) + end + end + end + + ruby_version_is "2.5" do + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError) + + # e.g. 1 + b + -> { 1.send(@method, b) }.should raise_error(IntegerSpecs::CoerceError) + end + end +end diff --git a/spec/ruby/core/integer/shared/comparison_exception_in_coerce.rb b/spec/ruby/core/integer/shared/comparison_exception_in_coerce.rb new file mode 100644 index 0000000000..f99d680d6d --- /dev/null +++ b/spec/ruby/core/integer/shared/comparison_exception_in_coerce.rb @@ -0,0 +1,35 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +describe :integer_comparison_exception_in_coerce, shared: true do + ruby_version_is ""..."2.5" do + it "rescues exception (StandardError and subclasses) raised in other#coerce and raises ArgumentError" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError) + + # e.g. 1 > b + -> { + -> { 1.send(@method, b) }.should raise_error(ArgumentError, /comparison of #{1.class} with MockObject failed/) + }.should complain(/Numerical comparison operators will no more rescue exceptions of #coerce/) + end + + it "does not rescue Exception and StandardError siblings raised in other#coerce" do + [Exception, NoMemoryError].each do |exception| + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(exception) + + # e.g. 1 > b + -> { 1.send(@method, b) }.should raise_error(exception) + end + end + end + + ruby_version_is "2.5" do + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError) + + # e.g. 1 > b + -> { 1.send(@method, b) }.should raise_error(IntegerSpecs::CoerceError) + end + end +end diff --git a/spec/ruby/core/io/syswrite_spec.rb b/spec/ruby/core/io/syswrite_spec.rb index 879423de2e..e4936441ce 100644 --- a/spec/ruby/core/io/syswrite_spec.rb +++ b/spec/ruby/core/io/syswrite_spec.rb @@ -49,6 +49,23 @@ describe "IO#syswrite on a file" do end end +describe "IO#syswrite on a pipe" do + it "returns the written bytes if the fd is in nonblock mode and write would block" do + require 'io/nonblock' + r, w = IO.pipe + begin + w.nonblock = true + larger_than_pipe_capacity = 100 * 1024 + written = w.syswrite("a"*larger_than_pipe_capacity) + written.should > 0 + written.should < larger_than_pipe_capacity + ensure + w.close + r.close + end + end +end + describe "IO#syswrite" do it_behaves_like :io_write, :syswrite end diff --git a/spec/ruby/core/kernel/extend_spec.rb b/spec/ruby/core/kernel/extend_spec.rb index 482eef32e9..f47c739223 100644 --- a/spec/ruby/core/kernel/extend_spec.rb +++ b/spec/ruby/core/kernel/extend_spec.rb @@ -72,8 +72,8 @@ describe "Kernel#extend" do lambda { @frozen.extend }.should raise_error(ArgumentError) end - it "raises a RuntimeError" do - lambda { @frozen.extend @module }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class}" do + lambda { @frozen.extend @module }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/kernel/instance_variable_set_spec.rb b/spec/ruby/core/kernel/instance_variable_set_spec.rb index bac1bb5f99..0b6ae57546 100644 --- a/spec/ruby/core/kernel/instance_variable_set_spec.rb +++ b/spec/ruby/core/kernel/instance_variable_set_spec.rb @@ -82,12 +82,12 @@ describe "Kernel#instance_variable_set" do @frozen.ivar.should equal(:origin) end - it "raises a RuntimeError when passed replacement is identical to stored object" do - lambda { @frozen.instance_variable_set(:@ivar, :origin) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed replacement is identical to stored object" do + lambda { @frozen.instance_variable_set(:@ivar, :origin) }.should raise_error(frozen_error_class) end - it "raises a RuntimeError when passed replacement is different from stored object" do - lambda { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed replacement is different from stored object" do + lambda { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb index 0c2fb3286b..539eadc407 100644 --- a/spec/ruby/core/kernel/taint_spec.rb +++ b/spec/ruby/core/kernel/taint_spec.rb @@ -13,9 +13,9 @@ describe "Kernel#taint" do o.tainted?.should == true end - it "raises RuntimeError on an untainted, frozen object" do + it "raises #{frozen_error_class} on an untainted, frozen object" do o = Object.new.freeze - lambda { o.taint }.should raise_error(RuntimeError) + lambda { o.taint }.should raise_error(frozen_error_class) end it "does not raise an error on a tainted, frozen object" do diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb index a9fda5c5c6..81ac9cc730 100644 --- a/spec/ruby/core/kernel/trust_spec.rb +++ b/spec/ruby/core/kernel/trust_spec.rb @@ -13,9 +13,9 @@ describe "Kernel#trust" do o.untrusted?.should == false end - it "raises RuntimeError on an untrusted, frozen object" do + it "raises #{frozen_error_class} on an untrusted, frozen object" do o = Object.new.untrust.freeze - lambda { o.trust }.should raise_error(RuntimeError) + lambda { o.trust }.should raise_error(frozen_error_class) end it "does not raise an error on a trusted, frozen object" do diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb index 5abe5d63fc..d54714cee4 100644 --- a/spec/ruby/core/kernel/untaint_spec.rb +++ b/spec/ruby/core/kernel/untaint_spec.rb @@ -13,9 +13,9 @@ describe "Kernel#untaint" do o.tainted?.should == false end - it "raises RuntimeError on a tainted, frozen object" do + it "raises #{frozen_error_class} on a tainted, frozen object" do o = Object.new.taint.freeze - lambda { o.untaint }.should raise_error(RuntimeError) + lambda { o.untaint }.should raise_error(frozen_error_class) end it "does not raise an error on an untainted, frozen object" do diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb index 280a465807..903567a5ed 100644 --- a/spec/ruby/core/kernel/untrust_spec.rb +++ b/spec/ruby/core/kernel/untrust_spec.rb @@ -13,9 +13,9 @@ describe "Kernel#untrust" do o.untrusted?.should == true end - it "raises RuntimeError on a trusted, frozen object" do + it "raises #{frozen_error_class} on a trusted, frozen object" do o = Object.new.freeze - lambda { o.untrust }.should raise_error(RuntimeError) + lambda { o.untrust }.should raise_error(frozen_error_class) end it "does not raise an error on an untrusted, frozen object" do diff --git a/spec/ruby/core/method/case_compare_spec.rb b/spec/ruby/core/method/case_compare_spec.rb new file mode 100644 index 0000000000..f75eff873c --- /dev/null +++ b/spec/ruby/core/method/case_compare_spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) +require File.expand_path('../shared/call', __FILE__) + +ruby_version_is "2.5" do + describe "Method#===" do + it_behaves_like(:method_call, :===) + end +end diff --git a/spec/ruby/core/module/alias_method_spec.rb b/spec/ruby/core/module/alias_method_spec.rb index d3c0529418..32fc345890 100644 --- a/spec/ruby/core/module/alias_method_spec.rb +++ b/spec/ruby/core/module/alias_method_spec.rb @@ -49,9 +49,9 @@ describe "Module#alias_method" do } end - it "raises RuntimeError if frozen" do + it "raises #{frozen_error_class} if frozen" do @class.freeze - lambda { @class.make_alias :uno, :public_one }.should raise_error(RuntimeError) + lambda { @class.make_alias :uno, :public_one }.should raise_error(frozen_error_class) end it "converts the names using #to_str" do diff --git a/spec/ruby/core/module/append_features_spec.rb b/spec/ruby/core/module/append_features_spec.rb index ceb8c3f8eb..122804ad36 100644 --- a/spec/ruby/core/module/append_features_spec.rb +++ b/spec/ruby/core/module/append_features_spec.rb @@ -65,8 +65,8 @@ describe "Module#append_features" do @other = Module.new.freeze end - it "raises a RuntimeError before appending self" do - lambda { @receiver.send(:append_features, @other) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} before appending self" do + lambda { @receiver.send(:append_features, @other) }.should raise_error(frozen_error_class) @other.ancestors.should_not include(@receiver) end end diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index a72ae7735b..d79e7605be 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -329,8 +329,8 @@ describe "Module#autoload" do end describe "on a frozen module" do - it "raises a RuntimeError before setting the name" do - lambda { @frozen_module.autoload :Foo, @non_existent }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} before setting the name" do + lambda { @frozen_module.autoload :Foo, @non_existent }.should raise_error(frozen_error_class) @frozen_module.should_not have_constant(:Foo) end end diff --git a/spec/ruby/core/module/class_variable_set_spec.rb b/spec/ruby/core/module/class_variable_set_spec.rb index 6d36298f5f..a65bd28a28 100644 --- a/spec/ruby/core/module/class_variable_set_spec.rb +++ b/spec/ruby/core/module/class_variable_set_spec.rb @@ -25,13 +25,13 @@ describe "Module#class_variable_set" do c.send(:class_variable_get, "@@mvar").should == :new_mvar end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do lambda { Class.new.freeze.send(:class_variable_set, :@@test, "test") - }.should raise_error(RuntimeError) + }.should raise_error(frozen_error_class) lambda { Module.new.freeze.send(:class_variable_set, :@@test, "test") - }.should raise_error(RuntimeError) + }.should raise_error(frozen_error_class) end it "raises a NameError when the given name is not allowed" do diff --git a/spec/ruby/core/module/const_set_spec.rb b/spec/ruby/core/module/const_set_spec.rb index 6f4f6f980f..c6c80bf5df 100644 --- a/spec/ruby/core/module/const_set_spec.rb +++ b/spec/ruby/core/module/const_set_spec.rb @@ -78,8 +78,8 @@ describe "Module#const_set" do @name = :Foo end - it "raises a RuntimeError before setting the name" do - lambda { @frozen.const_set @name, nil }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} before setting the name" do + lambda { @frozen.const_set @name, nil }.should raise_error(frozen_error_class) @frozen.should_not have_constant(@name) end end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 64ac5306f0..be0e2f0a0b 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -247,10 +247,10 @@ describe "Module#define_method" do lambda { obj.proc_style_test :arg }.should raise_error(ArgumentError) end - it "raises a RuntimeError if frozen" do + it "raises a #{frozen_error_class} if frozen" do lambda { Class.new { freeze; define_method(:foo) {} } - }.should raise_error(RuntimeError) + }.should raise_error(frozen_error_class) end it "accepts a Method (still bound)" do diff --git a/spec/ruby/core/module/remove_method_spec.rb b/spec/ruby/core/module/remove_method_spec.rb index d82e0c65ca..b2e91bcc1f 100644 --- a/spec/ruby/core/module/remove_method_spec.rb +++ b/spec/ruby/core/module/remove_method_spec.rb @@ -97,12 +97,12 @@ describe "Module#remove_method" do @frozen = @module.dup.freeze end - it "raises a RuntimeError when passed a name" do - lambda { @frozen.send :remove_method, :method_to_remove }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed a name" do + lambda { @frozen.send :remove_method, :method_to_remove }.should raise_error(frozen_error_class) end - it "raises a RuntimeError when passed a missing name" do - lambda { @frozen.send :remove_method, :not_exist }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed a missing name" do + lambda { @frozen.send :remove_method, :not_exist }.should raise_error(frozen_error_class) end it "raises a TypeError when passed a not name" do diff --git a/spec/ruby/core/module/undef_method_spec.rb b/spec/ruby/core/module/undef_method_spec.rb index 54c3d37c7f..bb2cbc1f24 100644 --- a/spec/ruby/core/module/undef_method_spec.rb +++ b/spec/ruby/core/module/undef_method_spec.rb @@ -68,12 +68,12 @@ describe "Module#undef_method" do @frozen = @module.dup.freeze end - it "raises a RuntimeError when passed a name" do - lambda { @frozen.send :undef_method, :method_to_undef }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed a name" do + lambda { @frozen.send :undef_method, :method_to_undef }.should raise_error(frozen_error_class) end - it "raises a RuntimeError when passed a missing name" do - lambda { @frozen.send :undef_method, :not_exist }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed a missing name" do + lambda { @frozen.send :undef_method, :not_exist }.should raise_error(frozen_error_class) end it "raises a TypeError when passed a not name" do diff --git a/spec/ruby/core/range/fixtures/classes.rb b/spec/ruby/core/range/fixtures/classes.rb index de46d7d4a9..b62704ca39 100644 --- a/spec/ruby/core/range/fixtures/classes.rb +++ b/spec/ruby/core/range/fixtures/classes.rb @@ -62,4 +62,7 @@ module RangeSpecs class MyRange < Range end + + class ComparisonError < RuntimeError + end end diff --git a/spec/ruby/core/range/new_spec.rb b/spec/ruby/core/range/new_spec.rb index f0d24e4aeb..8ec4605102 100644 --- a/spec/ruby/core/range/new_spec.rb +++ b/spec/ruby/core/range/new_spec.rb @@ -1,4 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) describe "Range.new" do it "constructs a range using the given start and end" do @@ -31,4 +32,14 @@ describe "Range.new" do (a = mock('nil')).should_receive(:<=>).with(b).and_return(nil) lambda { Range.new(a, b) }.should raise_error(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) + + -> { Range.new(a, b) }.should raise_error(RangeSpecs::ComparisonError) + end + end end diff --git a/spec/ruby/core/rational/comparison_spec.rb b/spec/ruby/core/rational/comparison_spec.rb index 47e3ab043d..3c11abe4a4 100644 --- a/spec/ruby/core/rational/comparison_spec.rb +++ b/spec/ruby/core/rational/comparison_spec.rb @@ -14,6 +14,7 @@ end describe "Rational#<=> when passed an Object that responds to #coerce" do it_behaves_like(:rational_cmp_coerce, :<=>) + it_behaves_like(:rational_cmp_coerce_exception, :<=>) end describe "Rational#<=> when passed a non-Numeric Object that doesn't respond to #coerce" do diff --git a/spec/ruby/core/rational/divide_spec.rb b/spec/ruby/core/rational/divide_spec.rb index 75e447878c..8e38513440 100644 --- a/spec/ruby/core/rational/divide_spec.rb +++ b/spec/ruby/core/rational/divide_spec.rb @@ -1,7 +1,9 @@ require File.expand_path('../../../shared/rational/divide', __FILE__) +require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__) describe "Rational#/" do it_behaves_like(:rational_divide, :/) + it_behaves_like :rational_arithmetic_exception_in_coerce, :/ end describe "Rational#/ when passed an Integer" do diff --git a/spec/ruby/core/rational/minus_spec.rb b/spec/ruby/core/rational/minus_spec.rb index 9e28cb1c4f..9d14b25c47 100644 --- a/spec/ruby/core/rational/minus_spec.rb +++ b/spec/ruby/core/rational/minus_spec.rb @@ -1,5 +1,7 @@ require File.expand_path('../../../shared/rational/minus', __FILE__) +require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__) describe "Rational#-" do it_behaves_like(:rational_minus, :-) + it_behaves_like :rational_arithmetic_exception_in_coerce, :- end diff --git a/spec/ruby/core/rational/multiply_spec.rb b/spec/ruby/core/rational/multiply_spec.rb index c45491fde3..1245908c89 100644 --- a/spec/ruby/core/rational/multiply_spec.rb +++ b/spec/ruby/core/rational/multiply_spec.rb @@ -1,7 +1,9 @@ require File.expand_path('../../../shared/rational/multiply', __FILE__) +require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__) describe "Rational#*" do it_behaves_like(:rational_multiply, :*) + it_behaves_like :rational_arithmetic_exception_in_coerce, :* end describe "Rational#* passed a Rational" do diff --git a/spec/ruby/core/rational/plus_spec.rb b/spec/ruby/core/rational/plus_spec.rb index b82c44bbad..2564e1161b 100644 --- a/spec/ruby/core/rational/plus_spec.rb +++ b/spec/ruby/core/rational/plus_spec.rb @@ -1,7 +1,9 @@ require File.expand_path('../../../shared/rational/plus', __FILE__) +require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__) describe "Rational#+" do it_behaves_like(:rational_plus, :+) + it_behaves_like :rational_arithmetic_exception_in_coerce, :+ end describe "Rational#+ with a Rational" do diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb index 497e1453cd..971b06281e 100644 --- a/spec/ruby/core/string/capitalize_spec.rb +++ b/spec/ruby/core/string/capitalize_spec.rb @@ -61,10 +61,10 @@ describe "String#capitalize!" do "H".capitalize!.should == nil end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do ["", "Hello", "hello"].each do |a| a.freeze - lambda { a.capitalize! }.should raise_error(RuntimeError) + lambda { a.capitalize! }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/casecmp_spec.rb b/spec/ruby/core/string/casecmp_spec.rb index c77d97815c..f556c79346 100644 --- a/spec/ruby/core/string/casecmp_spec.rb +++ b/spec/ruby/core/string/casecmp_spec.rb @@ -180,5 +180,17 @@ ruby_version_is "2.4" do end end end + + ruby_version_is "2.4" ... "2.5" do + it "raises a TypeError if other can't be converted to a string" do + lambda { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError) + end + end + + ruby_version_is "2.5" do + it "returns nil if other can't be converted to a string" do + "abc".casecmp?(mock('abc')).should be_nil + end + end end end diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb index 5daa8c5a40..4f7486b0f7 100644 --- a/spec/ruby/core/string/chomp_spec.rb +++ b/spec/ruby/core/string/chomp_spec.rb @@ -310,19 +310,19 @@ describe "String#chomp!" do end end - it "raises a RuntimeError on a frozen instance when it is modified" do + it "raises a #{frozen_error_class} on a frozen instance when it is modified" do a = "string\n\r" a.freeze - lambda { a.chomp! }.should raise_error(RuntimeError) + lambda { a.chomp! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen instance when it would not be modified" do + it "raises a #{frozen_error_class} on a frozen instance when it would not be modified" do a = "string\n\r" a.freeze - lambda { a.chomp!(nil) }.should raise_error(RuntimeError) - lambda { a.chomp!("x") }.should raise_error(RuntimeError) + lambda { a.chomp!(nil) }.should raise_error(frozen_error_class) + lambda { a.chomp!("x") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb index 4e9a39f866..6afee99685 100644 --- a/spec/ruby/core/string/chop_spec.rb +++ b/spec/ruby/core/string/chop_spec.rb @@ -115,14 +115,14 @@ describe "String#chop!" do "".chop!.should be_nil end - it "raises a RuntimeError on a frozen instance that is modified" do - lambda { "string\n\r".freeze.chop! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that is modified" do + lambda { "string\n\r".freeze.chop! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen instance that would not be modified" do + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do a = "" a.freeze - lambda { a.chop! }.should raise_error(RuntimeError) + lambda { a.chop! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/clear_spec.rb b/spec/ruby/core/string/clear_spec.rb index 6a8b6018d0..c1bab8f39e 100644 --- a/spec/ruby/core/string/clear_spec.rb +++ b/spec/ruby/core/string/clear_spec.rb @@ -30,10 +30,10 @@ with_feature :encoding do s.should == "" end - it "raises a RuntimeError if self is frozen" do + it "raises a #{frozen_error_class} if self is frozen" do @s.freeze - lambda { @s.clear }.should raise_error(RuntimeError) - lambda { "".freeze.clear }.should raise_error(RuntimeError) + lambda { @s.clear }.should raise_error(frozen_error_class) + lambda { "".freeze.clear }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/delete_prefix_spec.rb b/spec/ruby/core/string/delete_prefix_spec.rb index 94d486eace..973fc951cb 100644 --- a/spec/ruby/core/string/delete_prefix_spec.rb +++ b/spec/ruby/core/string/delete_prefix_spec.rb @@ -72,10 +72,10 @@ ruby_version_is '2.5' do 'hello'.delete_prefix!(o).should == 'o' end - it "raises a RuntimeError when self is frozen" do - lambda { 'hello'.freeze.delete_prefix!('hell') }.should raise_error(RuntimeError) - lambda { 'hello'.freeze.delete_prefix!('') }.should raise_error(RuntimeError) - lambda { ''.freeze.delete_prefix!('') }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when self is frozen" do + lambda { 'hello'.freeze.delete_prefix!('hell') }.should raise_error(frozen_error_class) + lambda { 'hello'.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) + lambda { ''.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/delete_spec.rb b/spec/ruby/core/string/delete_spec.rb index 536d4a95af..049f56e926 100644 --- a/spec/ruby/core/string/delete_spec.rb +++ b/spec/ruby/core/string/delete_spec.rb @@ -109,11 +109,11 @@ describe "String#delete!" do a.should == "hello" end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a.delete!("") }.should raise_error(RuntimeError) - lambda { a.delete!("aeiou", "^e") }.should raise_error(RuntimeError) + lambda { a.delete!("") }.should raise_error(frozen_error_class) + lambda { a.delete!("aeiou", "^e") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/delete_suffix_spec.rb b/spec/ruby/core/string/delete_suffix_spec.rb index 49689a8da1..72adcacc55 100644 --- a/spec/ruby/core/string/delete_suffix_spec.rb +++ b/spec/ruby/core/string/delete_suffix_spec.rb @@ -72,10 +72,10 @@ ruby_version_is '2.5' do 'hello'.delete_suffix!(o).should == 'h' end - it "raises a RuntimeError when self is frozen" do - lambda { 'hello'.freeze.delete_suffix!('ello') }.should raise_error(RuntimeError) - lambda { 'hello'.freeze.delete_suffix!('') }.should raise_error(RuntimeError) - lambda { ''.freeze.delete_suffix!('') }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when self is frozen" do + lambda { 'hello'.freeze.delete_suffix!('ello') }.should raise_error(frozen_error_class) + lambda { 'hello'.freeze.delete_suffix!('') }.should raise_error(frozen_error_class) + lambda { ''.freeze.delete_suffix!('') }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb index f591c0fa09..adb5f83cfa 100644 --- a/spec/ruby/core/string/downcase_spec.rb +++ b/spec/ruby/core/string/downcase_spec.rb @@ -60,9 +60,9 @@ describe "String#downcase!" do a.should == "hello" end - it "raises a RuntimeError when self is frozen" do - lambda { "HeLlo".freeze.downcase! }.should raise_error(RuntimeError) - lambda { "hello".freeze.downcase! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when self is frozen" do + lambda { "HeLlo".freeze.downcase! }.should raise_error(frozen_error_class) + lambda { "hello".freeze.downcase! }.should raise_error(frozen_error_class) end with_feature :encoding do diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb index fea03607f2..9c02afed8d 100644 --- a/spec/ruby/core/string/element_set_spec.rb +++ b/spec/ruby/core/string/element_set_spec.rb @@ -50,11 +50,11 @@ describe "String#[]= with Fixnum index" do str.should == "hello" end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a[0] = "bam" }.should raise_error(RuntimeError) + lambda { a[0] = "bam" }.should raise_error(frozen_error_class) end it "calls to_int on index" do diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb index d051dd58c9..5b6fa7e50c 100644 --- a/spec/ruby/core/string/encode_spec.rb +++ b/spec/ruby/core/string/encode_spec.rb @@ -107,13 +107,13 @@ with_feature :encoding do it_behaves_like :string_encode, :encode! - it "raises a RuntimeError when called on a frozen String" do - lambda { "foo".freeze.encode!("euc-jp") }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when called on a frozen String" do + lambda { "foo".freeze.encode!("euc-jp") }.should raise_error(frozen_error_class) end # http://redmine.ruby-lang.org/issues/show/1836 - it "raises a RuntimeError when called on a frozen String when it's a no-op" do - lambda { "foo".freeze.encode!("utf-8") }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when called on a frozen String when it's a no-op" do + lambda { "foo".freeze.encode!("utf-8") }.should raise_error(frozen_error_class) end describe "when passed no options" do diff --git a/spec/ruby/core/string/force_encoding_spec.rb b/spec/ruby/core/string/force_encoding_spec.rb index d163c75ac3..a2464dc904 100644 --- a/spec/ruby/core/string/force_encoding_spec.rb +++ b/spec/ruby/core/string/force_encoding_spec.rb @@ -45,9 +45,9 @@ with_feature :encoding do str.dup.force_encoding('utf-16le').should_not == str.encode('utf-16le') end - it "raises a RuntimeError if self is frozen" do + it "raises a #{frozen_error_class} if self is frozen" do str = "abcd".freeze - lambda { str.force_encoding(str.encoding) }.should raise_error(RuntimeError) + lambda { str.force_encoding(str.encoding) }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb index 026b037b6c..319dc2e3e1 100644 --- a/spec/ruby/core/string/gsub_spec.rb +++ b/spec/ruby/core/string/gsub_spec.rb @@ -603,13 +603,13 @@ describe "String#gsub! with pattern and replacement" do end # See [ruby-core:23666] - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do s = "hello" s.freeze - lambda { s.gsub!(/ROAR/, "x") }.should raise_error(RuntimeError) - lambda { s.gsub!(/e/, "e") }.should raise_error(RuntimeError) - lambda { s.gsub!(/[aeiou]/, '*') }.should raise_error(RuntimeError) + lambda { s.gsub!(/ROAR/, "x") }.should raise_error(frozen_error_class) + lambda { s.gsub!(/e/, "e") }.should raise_error(frozen_error_class) + lambda { s.gsub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class) end end @@ -640,13 +640,13 @@ describe "String#gsub! with pattern and block" do end # See [ruby-core:23663] - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do s = "hello" s.freeze - lambda { s.gsub!(/ROAR/) { "x" } }.should raise_error(RuntimeError) - lambda { s.gsub!(/e/) { "e" } }.should raise_error(RuntimeError) - lambda { s.gsub!(/[aeiou]/) { '*' } }.should raise_error(RuntimeError) + lambda { s.gsub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class) + lambda { s.gsub!(/e/) { "e" } }.should raise_error(frozen_error_class) + lambda { s.gsub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class) end it "uses the compatible encoding if they are compatible" do diff --git a/spec/ruby/core/string/insert_spec.rb b/spec/ruby/core/string/insert_spec.rb index c207fcc13b..8bae38f074 100644 --- a/spec/ruby/core/string/insert_spec.rb +++ b/spec/ruby/core/string/insert_spec.rb @@ -57,10 +57,10 @@ describe "String#insert with index, other" do lambda { "abcd".insert(-6, mock('x')) }.should raise_error(TypeError) end - it "raises a RuntimeError if self is frozen" do + it "raises a #{frozen_error_class} if self is frozen" do str = "abcd".freeze - lambda { str.insert(4, '') }.should raise_error(RuntimeError) - lambda { str.insert(4, 'X') }.should raise_error(RuntimeError) + lambda { str.insert(4, '') }.should raise_error(frozen_error_class) + lambda { str.insert(4, 'X') }.should raise_error(frozen_error_class) end with_feature :encoding do diff --git a/spec/ruby/core/string/lstrip_spec.rb b/spec/ruby/core/string/lstrip_spec.rb index 7ef94be567..b35e359928 100644 --- a/spec/ruby/core/string/lstrip_spec.rb +++ b/spec/ruby/core/string/lstrip_spec.rb @@ -38,13 +38,13 @@ describe "String#lstrip!" do a.should == "hello" end - it "raises a RuntimeError on a frozen instance that is modified" do - lambda { " hello ".freeze.lstrip! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that is modified" do + lambda { " hello ".freeze.lstrip! }.should raise_error(frozen_error_class) end # see [ruby-core:23657] - it "raises a RuntimeError on a frozen instance that would not be modified" do - lambda { "hello".freeze.lstrip! }.should raise_error(RuntimeError) - lambda { "".freeze.lstrip! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do + lambda { "hello".freeze.lstrip! }.should raise_error(frozen_error_class) + lambda { "".freeze.lstrip! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/prepend_spec.rb b/spec/ruby/core/string/prepend_spec.rb index 17e97fd844..81618a4d7c 100644 --- a/spec/ruby/core/string/prepend_spec.rb +++ b/spec/ruby/core/string/prepend_spec.rb @@ -20,12 +20,12 @@ describe "String#prepend" do lambda { 'hello '.prepend mock('x') }.should raise_error(TypeError) end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a.prepend "" }.should raise_error(RuntimeError) - lambda { a.prepend "test" }.should raise_error(RuntimeError) + lambda { a.prepend "" }.should raise_error(frozen_error_class) + lambda { a.prepend "test" }.should raise_error(frozen_error_class) end it "works when given a subclass instance" do diff --git a/spec/ruby/core/string/reverse_spec.rb b/spec/ruby/core/string/reverse_spec.rb index c37e815ba3..5b183fef4f 100644 --- a/spec/ruby/core/string/reverse_spec.rb +++ b/spec/ruby/core/string/reverse_spec.rb @@ -32,14 +32,14 @@ describe "String#reverse!" do "".reverse!.should == "" end - it "raises a RuntimeError on a frozen instance that is modified" do - lambda { "anna".freeze.reverse! }.should raise_error(RuntimeError) - lambda { "hello".freeze.reverse! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that is modified" do + lambda { "anna".freeze.reverse! }.should raise_error(frozen_error_class) + lambda { "hello".freeze.reverse! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen instance that would not be modified" do - lambda { "".freeze.reverse! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do + lambda { "".freeze.reverse! }.should raise_error(frozen_error_class) end with_feature :encoding do diff --git a/spec/ruby/core/string/rstrip_spec.rb b/spec/ruby/core/string/rstrip_spec.rb index 9dd686ce55..aa3f70a166 100644 --- a/spec/ruby/core/string/rstrip_spec.rb +++ b/spec/ruby/core/string/rstrip_spec.rb @@ -40,13 +40,13 @@ describe "String#rstrip!" do a.should == "hello" end - it "raises a RuntimeError on a frozen instance that is modified" do - lambda { " hello ".freeze.rstrip! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that is modified" do + lambda { " hello ".freeze.rstrip! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen instance that would not be modified" do - lambda { "hello".freeze.rstrip! }.should raise_error(RuntimeError) - lambda { "".freeze.rstrip! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do + lambda { "hello".freeze.rstrip! }.should raise_error(frozen_error_class) + lambda { "".freeze.rstrip! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/setbyte_spec.rb b/spec/ruby/core/string/setbyte_spec.rb index 6373d74be1..e27ab38d67 100644 --- a/spec/ruby/core/string/setbyte_spec.rb +++ b/spec/ruby/core/string/setbyte_spec.rb @@ -75,10 +75,10 @@ describe "String#setbyte" do str1.should_not == "ledgehog" end - it "raises a RuntimeError if self is frozen" do + it "raises a #{frozen_error_class} if self is frozen" do str = "cold".freeze str.frozen?.should be_true - lambda { str.setbyte(3,96) }.should raise_error(RuntimeError) + lambda { str.setbyte(3,96) }.should raise_error(frozen_error_class) end it "raises a TypeError unless the second argument is an Integer" do diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb index 7da995fdc7..d7b9cdfec3 100644 --- a/spec/ruby/core/string/shared/concat.rb +++ b/spec/ruby/core/string/shared/concat.rb @@ -17,12 +17,12 @@ describe :string_concat, shared: true do lambda { 'hello '.send(@method, mock('x')) }.should raise_error(TypeError) end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a.send(@method, "") }.should raise_error(RuntimeError) - lambda { a.send(@method, "test") }.should raise_error(RuntimeError) + lambda { a.send(@method, "") }.should raise_error(frozen_error_class) + lambda { a.send(@method, "test") }.should raise_error(frozen_error_class) end it "returns a String when given a subclass instance" do @@ -87,12 +87,12 @@ describe :string_concat, shared: true do lambda { "".send(@method, x) }.should raise_error(TypeError) end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a.send(@method, 0) }.should raise_error(RuntimeError) - lambda { a.send(@method, 33) }.should raise_error(RuntimeError) + lambda { a.send(@method, 0) }.should raise_error(frozen_error_class) + lambda { a.send(@method, 33) }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/shared/replace.rb b/spec/ruby/core/string/shared/replace.rb index 9f5446fbbe..a583b88b5a 100644 --- a/spec/ruby/core/string/shared/replace.rb +++ b/spec/ruby/core/string/shared/replace.rb @@ -62,14 +62,14 @@ describe :string_replace, shared: true do lambda { "hello".send(@method, mock('x')) }.should raise_error(TypeError) end - it "raises a RuntimeError on a frozen instance that is modified" do + it "raises a #{frozen_error_class} on a frozen instance that is modified" do a = "hello".freeze - lambda { a.send(@method, "world") }.should raise_error(RuntimeError) + lambda { a.send(@method, "world") }.should raise_error(frozen_error_class) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen instance when self-replacing" do + it "raises a #{frozen_error_class} on a frozen instance when self-replacing" do a = "hello".freeze - lambda { a.send(@method, a) }.should raise_error(RuntimeError) + lambda { a.send(@method, a) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb index 4854cb7146..0ab659864d 100644 --- a/spec/ruby/core/string/shared/succ.rb +++ b/spec/ruby/core/string/shared/succ.rb @@ -81,8 +81,8 @@ describe :string_succ_bang, shared: true do end end - it "raises a RuntimeError if self is frozen" do - lambda { "".freeze.send(@method) }.should raise_error(RuntimeError) - lambda { "abcd".freeze.send(@method) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if self is frozen" do + lambda { "".freeze.send(@method) }.should raise_error(frozen_error_class) + lambda { "abcd".freeze.send(@method) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb index 8018cc2140..fce64bd382 100644 --- a/spec/ruby/core/string/slice_spec.rb +++ b/spec/ruby/core/string/slice_spec.rb @@ -53,10 +53,10 @@ describe "String#slice! with index" do a.should == "hello" end - it "raises a RuntimeError if self is frozen" do - lambda { "hello".freeze.slice!(1) }.should raise_error(RuntimeError) - lambda { "hello".freeze.slice!(10) }.should raise_error(RuntimeError) - lambda { "".freeze.slice!(0) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if self is frozen" do + lambda { "hello".freeze.slice!(1) }.should raise_error(frozen_error_class) + lambda { "hello".freeze.slice!(10) }.should raise_error(frozen_error_class) + lambda { "".freeze.slice!(0) }.should raise_error(frozen_error_class) end it "calls to_int on index" do @@ -119,14 +119,14 @@ describe "String#slice! with index, length" do a.should == "hello" end - it "raises a RuntimeError if self is frozen" do - lambda { "hello".freeze.slice!(1, 2) }.should raise_error(RuntimeError) - lambda { "hello".freeze.slice!(10, 3) }.should raise_error(RuntimeError) - lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(RuntimeError) - lambda { "hello".freeze.slice!(4, -3) }.should raise_error(RuntimeError) - lambda { "hello".freeze.slice!(10, 3) }.should raise_error(RuntimeError) - lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(RuntimeError) - lambda { "hello".freeze.slice!(4, -3) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if self is frozen" do + lambda { "hello".freeze.slice!(1, 2) }.should raise_error(frozen_error_class) + lambda { "hello".freeze.slice!(10, 3) }.should raise_error(frozen_error_class) + lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(frozen_error_class) + lambda { "hello".freeze.slice!(4, -3) }.should raise_error(frozen_error_class) + lambda { "hello".freeze.slice!(10, 3) }.should raise_error(frozen_error_class) + lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(frozen_error_class) + lambda { "hello".freeze.slice!(4, -3) }.should raise_error(frozen_error_class) end it "calls to_int on idx and length" do @@ -250,13 +250,13 @@ describe "String#slice! Range" do end - it "raises a RuntimeError on a frozen instance that is modified" do - lambda { "hello".freeze.slice!(1..3) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that is modified" do + lambda { "hello".freeze.slice!(1..3) }.should raise_error(frozen_error_class) end # see redmine #1551 - it "raises a RuntimeError on a frozen instance that would not be modified" do - lambda { "hello".freeze.slice!(10..20)}.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do + lambda { "hello".freeze.slice!(10..20)}.should raise_error(frozen_error_class) end end @@ -320,12 +320,12 @@ describe "String#slice! with Regexp" do $~.should == nil end - it "raises a RuntimeError on a frozen instance that is modified" do - lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that is modified" do + lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(frozen_error_class) end - it "raises a RuntimeError on a frozen instance that would not be modified" do - lambda { "this is a string".freeze.slice!(/zzz/) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do + lambda { "this is a string".freeze.slice!(/zzz/) }.should raise_error(frozen_error_class) end end @@ -412,10 +412,10 @@ describe "String#slice! with Regexp, index" do $~.should == nil end - it "raises a RuntimeError if self is frozen" do - lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(RuntimeError) - lambda { "this is a string".freeze.slice!(/zzz/, 0)}.should raise_error(RuntimeError) - lambda { "this is a string".freeze.slice!(/(.)/, 2)}.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if self is frozen" do + lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(frozen_error_class) + lambda { "this is a string".freeze.slice!(/zzz/, 0)}.should raise_error(frozen_error_class) + lambda { "this is a string".freeze.slice!(/(.)/, 2)}.should raise_error(frozen_error_class) end end @@ -468,9 +468,9 @@ describe "String#slice! with String" do r.should be_an_instance_of(StringSpecs::MyString) end - it "raises a RuntimeError if self is frozen" do - lambda { "hello hello".freeze.slice!('llo') }.should raise_error(RuntimeError) - lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(RuntimeError) - lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if self is frozen" do + lambda { "hello hello".freeze.slice!('llo') }.should raise_error(frozen_error_class) + lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(frozen_error_class) + lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb index d6b3fb6de6..01b9fe72ff 100644 --- a/spec/ruby/core/string/squeeze_spec.rb +++ b/spec/ruby/core/string/squeeze_spec.rb @@ -103,11 +103,11 @@ describe "String#squeeze!" do lambda { s.squeeze!("^e-b") }.should raise_error(ArgumentError) end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do a = "yellow moon" a.freeze - lambda { a.squeeze!("") }.should raise_error(RuntimeError) - lambda { a.squeeze! }.should raise_error(RuntimeError) + lambda { a.squeeze!("") }.should raise_error(frozen_error_class) + lambda { a.squeeze! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb index 747fd8cdf2..36eb38e4e4 100644 --- a/spec/ruby/core/string/strip_spec.rb +++ b/spec/ruby/core/string/strip_spec.rb @@ -48,13 +48,13 @@ describe "String#strip!" do a.should == "\x00 goodbye" end - it "raises a RuntimeError on a frozen instance that is modified" do - lambda { " hello ".freeze.strip! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that is modified" do + lambda { " hello ".freeze.strip! }.should raise_error(frozen_error_class) end # see #1552 - it "raises a RuntimeError on a frozen instance that would not be modified" do - lambda {"hello".freeze.strip! }.should raise_error(RuntimeError) - lambda {"".freeze.strip! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do + lambda {"hello".freeze.strip! }.should raise_error(frozen_error_class) + lambda {"".freeze.strip! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/sub_spec.rb b/spec/ruby/core/string/sub_spec.rb index deaa7e27f1..ceda4ec794 100644 --- a/spec/ruby/core/string/sub_spec.rb +++ b/spec/ruby/core/string/sub_spec.rb @@ -326,13 +326,13 @@ describe "String#sub! with pattern, replacement" do a.should == "hello" end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do s = "hello" s.freeze - lambda { s.sub!(/ROAR/, "x") }.should raise_error(RuntimeError) - lambda { s.sub!(/e/, "e") }.should raise_error(RuntimeError) - lambda { s.sub!(/[aeiou]/, '*') }.should raise_error(RuntimeError) + lambda { s.sub!(/ROAR/, "x") }.should raise_error(frozen_error_class) + lambda { s.sub!(/e/, "e") }.should raise_error(frozen_error_class) + lambda { s.sub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class) end end @@ -379,13 +379,13 @@ describe "String#sub! with pattern and block" do lambda { str.sub!(//) { str << 'x' } }.should raise_error(RuntimeError) end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do s = "hello" s.freeze - lambda { s.sub!(/ROAR/) { "x" } }.should raise_error(RuntimeError) - lambda { s.sub!(/e/) { "e" } }.should raise_error(RuntimeError) - lambda { s.sub!(/[aeiou]/) { '*' } }.should raise_error(RuntimeError) + lambda { s.sub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class) + lambda { s.sub!(/e/) { "e" } }.should raise_error(frozen_error_class) + lambda { s.sub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb index c2b583acab..d9127856d3 100644 --- a/spec/ruby/core/string/swapcase_spec.rb +++ b/spec/ruby/core/string/swapcase_spec.rb @@ -57,10 +57,10 @@ describe "String#swapcase!" do "".swapcase!.should == nil end - it "raises a RuntimeError when self is frozen" do + it "raises a #{frozen_error_class} when self is frozen" do ["", "hello"].each do |a| a.freeze - lambda { a.swapcase! }.should raise_error(RuntimeError) + lambda { a.swapcase! }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb index ea2ffa71b9..e387ea2356 100644 --- a/spec/ruby/core/string/tr_s_spec.rb +++ b/spec/ruby/core/string/tr_s_spec.rb @@ -127,10 +127,10 @@ describe "String#tr_s!" do s.should == "hello" end - it "raises a RuntimeError if self is frozen" do + it "raises a #{frozen_error_class} if self is frozen" do s = "hello".freeze - lambda { s.tr_s!("el", "ar") }.should raise_error(RuntimeError) - lambda { s.tr_s!("l", "r") }.should raise_error(RuntimeError) - lambda { s.tr_s!("", "") }.should raise_error(RuntimeError) + lambda { s.tr_s!("el", "ar") }.should raise_error(frozen_error_class) + lambda { s.tr_s!("l", "r") }.should raise_error(frozen_error_class) + lambda { s.tr_s!("", "") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb index 16d2d318e1..55556c6e4f 100644 --- a/spec/ruby/core/string/tr_spec.rb +++ b/spec/ruby/core/string/tr_spec.rb @@ -122,10 +122,10 @@ describe "String#tr!" do s.should == "hello" end - it "raises a RuntimeError if self is frozen" do + it "raises a #{frozen_error_class} if self is frozen" do s = "abcdefghijklmnopqR".freeze - lambda { s.tr!("cdefg", "12") }.should raise_error(RuntimeError) - lambda { s.tr!("R", "S") }.should raise_error(RuntimeError) - lambda { s.tr!("", "") }.should raise_error(RuntimeError) + lambda { s.tr!("cdefg", "12") }.should raise_error(frozen_error_class) + lambda { s.tr!("R", "S") }.should raise_error(frozen_error_class) + lambda { s.tr!("", "") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/unpack/j_spec.rb b/spec/ruby/core/string/unpack/j_spec.rb index 49c460aeb3..23d26d896e 100644 --- a/spec/ruby/core/string/unpack/j_spec.rb +++ b/spec/ruby/core/string/unpack/j_spec.rb @@ -4,10 +4,7 @@ require File.expand_path('../shared/basic', __FILE__) require File.expand_path('../shared/integer', __FILE__) ruby_version_is '2.3' do - # To handle the special case of x64-mingw32 - pointer_size = RUBY_PLATFORM =~ /\bx64\b/ ? 64 : 1.size * 8 - - if pointer_size == 64 then + platform_is pointer_size: 64 do little_endian do describe "String#unpack with format 'J'" do describe "with modifier '_'" do @@ -141,7 +138,7 @@ ruby_version_is '2.3' do end end - if pointer_size == 32 then + platform_is pointer_size: 32 do little_endian do describe "String#unpack with format 'J'" do describe "with modifier '_'" do diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb index 0094380664..31fd7fb8da 100644 --- a/spec/ruby/core/string/upcase_spec.rb +++ b/spec/ruby/core/string/upcase_spec.rb @@ -61,8 +61,8 @@ describe "String#upcase!" do a.should == "HELLO" end - it "raises a RuntimeError when self is frozen" do - lambda { "HeLlo".freeze.upcase! }.should raise_error(RuntimeError) - lambda { "HELLO".freeze.upcase! }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when self is frozen" do + lambda { "HeLlo".freeze.upcase! }.should raise_error(frozen_error_class) + lambda { "HELLO".freeze.upcase! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb index f43e764cb8..a77b3ac651 100644 --- a/spec/ruby/core/struct/new_spec.rb +++ b/spec/ruby/core/struct/new_spec.rb @@ -131,4 +131,47 @@ describe "Struct.new" do lambda { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError) end end + + ruby_version_is "2.5" do + context "keyword_init: true option" do + before :all do + @struct_with_kwa = Struct.new(:name, :legs, keyword_init: true) + @struct_without_kwa = Struct.new(:name, :legs, keyword_init: false) + end + + it "creates a class that accepts keyword arguments to initialize" do + obj = @struct_with_kwa.new(name: "elefant", legs: 4) + obj.name.should == "elefant" + obj.legs.should == 4 + end + + describe "new class instantiation" do + it "accepts arguments as hash as well" do + obj = @struct_with_kwa.new({name: "elefant", legs: 4}) + obj.name.should == "elefant" + obj.legs.should == 4 + end + + it "raises ArgumentError when passed not declared keyword argument" do + -> { + @struct_with_kwa.new(name: "elefant", legs: 4, foo: "bar") + }.should raise_error(ArgumentError, /unknown keywords: foo/) + end + + it "raises ArgumentError when passed a list of arguments" do + -> { + @struct_with_kwa.new("elefant", 4) + }.should raise_error(ArgumentError, /wrong number of arguments/) + end + end + end + + context "keyword_init: false option" do + it "behaves like it does without :keyword_init option" do + obj = @struct_without_kwa.new("elefant", 4) + obj.name.should == "elefant" + obj.legs.should == 4 + end + end + end end diff --git a/spec/ruby/core/struct/shared/equal_value.rb b/spec/ruby/core/struct/shared/equal_value.rb index 711862cb44..a7e0856df5 100644 --- a/spec/ruby/core/struct/shared/equal_value.rb +++ b/spec/ruby/core/struct/shared/equal_value.rb @@ -16,6 +16,13 @@ describe :struct_equal_value, shared: true do car.send(@method, different_car).should == false end + it "returns false if other is of a different class" do + car = StructClasses::Car.new("Honda", "Accord", "1998") + klass = Struct.new(:make, :model, :year) + clone = klass.new("Honda", "Accord", "1998") + car.send(@method, clone).should == false + end + it "handles recursive structures by returning false if a difference can be found" do x = StructClasses::Car.new("Honda", "Accord", "1998") x[:make] = x diff --git a/spec/ruby/core/thread/element_set_spec.rb b/spec/ruby/core/thread/element_set_spec.rb index ed92a84fa3..097f8def13 100644 --- a/spec/ruby/core/thread/element_set_spec.rb +++ b/spec/ruby/core/thread/element_set_spec.rb @@ -6,13 +6,13 @@ describe "Thread#[]=" do Thread.current[:value] = nil end - it "raises a RuntimeError if the thread is frozen" do + it "raises a #{frozen_error_class} if the thread is frozen" do Thread.new do th = Thread.current th.freeze -> { th[:foo] = "bar" - }.should raise_error(RuntimeError, /frozen/) + }.should raise_error(frozen_error_class, /frozen/) end.join end diff --git a/spec/ruby/core/time/shared/gm.rb b/spec/ruby/core/time/shared/gm.rb index 72012caa66..eaea374902 100644 --- a/spec/ruby/core/time/shared/gm.rb +++ b/spec/ruby/core/time/shared/gm.rb @@ -26,4 +26,30 @@ describe :time_gm, shared: true do time.usec.should == 0 time.nsec.should == 999 end + + platform_is :linux do + it "handles real leap seconds" do + with_timezone 'right/UTC' do + time = Time.send(@method, 1972, 6, 30, 23, 59, 60) + + time.sec.should == 60 + time.min.should == 59 + time.hour.should == 23 + time.day.should == 30 + time.month.should == 6 + end + end + + it "handles bad leap seconds by carrying values forward" do + with_timezone 'UTC' do + time = Time.send(@method, 1972, 6, 30, 23, 59, 60) + + time.sec.should == 0 + time.min.should == 0 + time.hour.should == 0 + time.day.should == 1 + time.month.should == 7 + end + end + end end diff --git a/spec/ruby/fixtures/rational.rb b/spec/ruby/fixtures/rational.rb index d0d05d0437..844d7f9820 100644 --- a/spec/ruby/fixtures/rational.rb +++ b/spec/ruby/fixtures/rational.rb @@ -8,4 +8,7 @@ module RationalSpecs @value end end + + class CoerceError < StandardError + end end diff --git a/spec/ruby/language/case_spec.rb b/spec/ruby/language/case_spec.rb index 25f5d0efc4..212964070d 100644 --- a/spec/ruby/language/case_spec.rb +++ b/spec/ruby/language/case_spec.rb @@ -3,15 +3,15 @@ require File.expand_path('../../spec_helper', __FILE__) describe "The 'case'-construct" do it "evaluates the body of the when clause matching the case target expression" do case 1 - when 2; false - when 1; true + when 2; false + when 1; true end.should == true end it "evaluates the body of the when clause whose array expression includes the case target expression" do case 2 - when 3, 4; false - when 1, 2; true + when 3, 4; false + when 1, 2; true end.should == true end @@ -21,7 +21,7 @@ describe "The 'case'-construct" do def bar; @calls << :bar; end case true - when foo, bar; + when foo, bar; end @calls.should == [:foo, :bar] @@ -29,31 +29,31 @@ describe "The 'case'-construct" do it "evaluates the body of the when clause whose range expression includes the case target expression" do case 5 - when 21..30; false - when 1..20; true + when 21..30; false + when 1..20; true end.should == true end it "returns nil when no 'then'-bodies are given" do case "a" - when "a" - when "b" + when "a" + when "b" end.should == nil end it "evaluates the 'else'-body when no other expression matches" do case "c" - when "a"; 'foo' - when "b"; 'bar' - else 'zzz' + when "a"; 'foo' + when "b"; 'bar' + else 'zzz' end.should == 'zzz' end it "returns nil when no expression matches and 'else'-body is empty" do case "c" - when "a"; "a" - when "b"; "b" - else + when "a"; "a" + when "b"; "b" + else end.should == nil end @@ -70,105 +70,143 @@ describe "The 'case'-construct" do it "returns the statement following 'then'" do case "a" - when "a" then 'foo' - when "b" then 'bar' + when "a" then 'foo' + when "b" then 'bar' end.should == 'foo' end it "tests classes with case equality" do case "a" - when String - 'foo' - when Symbol - 'bar' + when String + 'foo' + when Symbol + 'bar' end.should == 'foo' end it "tests with matching regexps" do case "hello" - when /abc/; false - when /^hell/; true + when /abc/; false + when /^hell/; true end.should == true end + it "tests with matching regexps and sets $~ and captures" do + case "foo42" + when /oo(\d+)/ + $~.should be_kind_of(MatchData) + $1.should == "42" + else + flunk + end + $~.should be_kind_of(MatchData) + $1.should == "42" + end + + it "tests with a regexp interpolated within another regexp" do + digits = '\d+' + case "foo44" + when /oo(#{digits})/ + $~.should be_kind_of(MatchData) + $1.should == "44" + else + flunk + end + $~.should be_kind_of(MatchData) + $1.should == "44" + end + + it "tests with a string interpolated in a regexp" do + digits_regexp = /\d+/ + case "foo43" + when /oo(#{digits_regexp})/ + $~.should be_kind_of(MatchData) + $1.should == "43" + else + flunk + end + $~.should be_kind_of(MatchData) + $1.should == "43" + end + it "does not test with equality when given classes" do case :symbol.class - when Symbol - "bar" - when String - "bar" - else - "foo" + when Symbol + "bar" + when String + "bar" + else + "foo" end.should == "foo" end it "takes lists of values" do case 'z' - when 'a', 'b', 'c', 'd' - "foo" - when 'x', 'y', 'z' - "bar" + when 'a', 'b', 'c', 'd' + "foo" + when 'x', 'y', 'z' + "bar" end.should == "bar" case 'b' - when 'a', 'b', 'c', 'd' - "foo" - when 'x', 'y', 'z' - "bar" + when 'a', 'b', 'c', 'd' + "foo" + when 'x', 'y', 'z' + "bar" end.should == "foo" end it "expands arrays to lists of values" do case 'z' - when *['a', 'b', 'c', 'd'] - "foo" - when *['x', 'y', 'z'] - "bar" + when *['a', 'b', 'c', 'd'] + "foo" + when *['x', 'y', 'z'] + "bar" end.should == "bar" end it "takes an expanded array in addition to a list of values" do case 'f' - when 'f', *['a', 'b', 'c', 'd'] - "foo" - when *['x', 'y', 'z'] - "bar" + when 'f', *['a', 'b', 'c', 'd'] + "foo" + when *['x', 'y', 'z'] + "bar" end.should == "foo" case 'b' - when 'f', *['a', 'b', 'c', 'd'] - "foo" - when *['x', 'y', 'z'] - "bar" + when 'f', *['a', 'b', 'c', 'd'] + "foo" + when *['x', 'y', 'z'] + "bar" end.should == "foo" end it "takes an expanded array before additional listed values" do case 'f' - when *['a', 'b', 'c', 'd'], 'f' - "foo" - when *['x', 'y', 'z'] - "bar" + when *['a', 'b', 'c', 'd'], 'f' + "foo" + when *['x', 'y', 'z'] + "bar" end.should == 'foo' end it "expands arrays from variables before additional listed values" do a = ['a', 'b', 'c'] case 'a' - when *a, 'd', 'e' - "foo" - when 'x' - "bar" + when *a, 'd', 'e' + "foo" + when 'x' + "bar" end.should == "foo" end it "expands arrays from variables before a single additional listed value" do a = ['a', 'b', 'c'] case 'a' - when *a, 'd' - "foo" - when 'x' - "bar" + when *a, 'd' + "foo" + when 'x' + "bar" end.should == "foo" end @@ -177,10 +215,10 @@ describe "The 'case'-construct" do b = ['d', 'e', 'f'] case 'f' - when *a, *b, 'g', 'h' - "foo" - when 'x' - "bar" + when *a, *b, 'g', 'h' + "foo" + when 'x' + "bar" end.should == "foo" end @@ -190,26 +228,26 @@ describe "The 'case'-construct" do b = ['f'] case 'f' - when 'f', *a|b - "foo" - when *['x', 'y', 'z'] - "bar" + when 'f', *a|b + "foo" + when *['x', 'y', 'z'] + "bar" end.should == "foo" end it "never matches when clauses with no values" do case nil - when *[] - "foo" + when *[] + "foo" end.should == nil end it "lets you define a method after the case statement" do case (def foo; 'foo'; end; 'f') - when 'a' - 'foo' - when 'f' - 'bar' + when 'a' + 'foo' + when 'f' + 'bar' end.should == 'bar' end @@ -217,8 +255,8 @@ describe "The 'case'-construct" do lambda { eval <<-CODE case 4 - else - true + else + true end CODE }.should raise_error(SyntaxError) @@ -228,9 +266,9 @@ describe "The 'case'-construct" do lambda { eval <<-CODE case 4 - else - true - when 4; false + else + true + when 4; false end CODE }.should raise_error(SyntaxError) @@ -287,56 +325,56 @@ end describe "The 'case'-construct with no target expression" do it "evaluates the body of the first clause when at least one of its condition expressions is true" do case - when true, false; 'foo' + when true, false; 'foo' end.should == 'foo' end it "evaluates the body of the first when clause that is not false/nil" do case - when false; 'foo' - when 2; 'bar' - when 1 == 1; 'baz' + when false; 'foo' + when 2; 'bar' + when 1 == 1; 'baz' end.should == 'bar' case - when false; 'foo' - when nil; 'foo' - when 1 == 1; 'bar' + when false; 'foo' + when nil; 'foo' + when 1 == 1; 'bar' end.should == 'bar' end it "evaluates the body of the else clause if all when clauses are false/nil" do case - when false; 'foo' - when nil; 'foo' - when 1 == 2; 'bar' - else 'baz' + when false; 'foo' + when nil; 'foo' + when 1 == 2; 'bar' + else 'baz' end.should == 'baz' end it "evaluates multiple conditional expressions as a boolean disjunction" do case - when true, false; 'foo' - else 'bar' + when true, false; 'foo' + else 'bar' end.should == 'foo' case - when false, true; 'foo' - else 'bar' + when false, true; 'foo' + else 'bar' end.should == 'foo' end it "evaluates true as only 'true' when true is the first clause" do case 1 - when true; "bad" - when Integer; "good" + when true; "bad" + when Integer; "good" end.should == "good" end it "evaluates false as only 'false' when false is the first clause" do case nil - when false; "bad" - when nil; "good" + when false; "bad" + when nil; "good" end.should == "good" end @@ -352,17 +390,17 @@ describe "The 'case'-construct with no target expression" do a2 = ['b', 'a', 'r'] case 'f' - when *a1, *['x', 'y', 'z'] - "foo" - when *a2, *['x', 'y', 'z'] - "bar" + when *a1, *['x', 'y', 'z'] + "foo" + when *a2, *['x', 'y', 'z'] + "bar" end.should == "foo" case 'b' - when *a1, *['x', 'y', 'z'] - "foo" - when *a2, *['x', 'y', 'z'] - "bar" + when *a1, *['x', 'y', 'z'] + "foo" + when *a2, *['x', 'y', 'z'] + "bar" end.should == "bar" end diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb index 55ee283b90..c31a2afb41 100644 --- a/spec/ruby/language/def_spec.rb +++ b/spec/ruby/language/def_spec.rb @@ -234,10 +234,10 @@ describe "A singleton method definition" do (obj==2).should == 2 end - it "raises RuntimeError if frozen" do + it "raises #{frozen_error_class} if frozen" do obj = Object.new obj.freeze - lambda { def obj.foo; end }.should raise_error(RuntimeError) + lambda { def obj.foo; end }.should raise_error(frozen_error_class) end end @@ -385,12 +385,12 @@ describe "A method definition inside a metaclass scope" do lambda { Object.new.a_singleton_method }.should raise_error(NoMethodError) end - it "raises RuntimeError if frozen" do + it "raises #{frozen_error_class} if frozen" do obj = Object.new obj.freeze class << obj - lambda { def foo; end }.should raise_error(RuntimeError) + lambda { def foo; end }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb index 0c8e657786..05f3075459 100644 --- a/spec/ruby/language/defined_spec.rb +++ b/spec/ruby/language/defined_spec.rb @@ -543,16 +543,12 @@ describe "The defined? keyword for variables" do defined?($+).should be_nil end - it "returns nil for $1-$9" do + it "returns nil for any last match global" do defined?($1).should be_nil - defined?($2).should be_nil - defined?($3).should be_nil defined?($4).should be_nil - defined?($5).should be_nil - defined?($6).should be_nil defined?($7).should be_nil - defined?($8).should be_nil - defined?($9).should be_nil + defined?($10).should be_nil + defined?($200).should be_nil end end @@ -587,13 +583,10 @@ describe "The defined? keyword for variables" do end it "returns nil for non-captures" do - defined?($3).should be_nil defined?($4).should be_nil - defined?($5).should be_nil - defined?($6).should be_nil defined?($7).should be_nil - defined?($8).should be_nil - defined?($9).should be_nil + defined?($10).should be_nil + defined?($200).should be_nil end end @@ -622,16 +615,12 @@ describe "The defined? keyword for variables" do defined?($+).should be_nil end - it "returns nil for $1-$9" do + it "returns nil for any last match global" do defined?($1).should be_nil - defined?($2).should be_nil - defined?($3).should be_nil defined?($4).should be_nil - defined?($5).should be_nil - defined?($6).should be_nil defined?($7).should be_nil - defined?($8).should be_nil - defined?($9).should be_nil + defined?($10).should be_nil + defined?($200).should be_nil end end @@ -666,13 +655,10 @@ describe "The defined? keyword for variables" do end it "returns nil for non-captures" do - defined?($3).should be_nil defined?($4).should be_nil - defined?($5).should be_nil - defined?($6).should be_nil defined?($7).should be_nil - defined?($8).should be_nil - defined?($9).should be_nil + defined?($10).should be_nil + defined?($200).should be_nil end end it "returns 'global-variable' for a global variable that has been assigned" do diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index f827fb2eb5..91cffce2e6 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -30,11 +30,11 @@ $` String The string preceding the match in a successful is local to the current scope. [r/o, thread] $' String The string following the match in a successful pattern match. This variable is local to the current scope. [r/o, thread] -$1 to $9 String The contents of successive groups matched in a successful pattern match. In +$1 to $ String The contents of successive groups matched in a successful pattern match. In "cat" =~/(c|a)(t|z)/, $1 will be set to “a” and $2 to “t”. This variable is local to the current scope. [r/o, thread] $~ MatchData An object that encapsulates the results of a successful pattern match. The - variables $&, $`, $', and $1 to $9 are all derived from $~. Assigning to $~ + variables $&, $`, $', and $1 to $ are all derived from $~. Assigning to $~ changes the values of these derived variables. This variable is local to the current scope. [thread] =end @@ -645,6 +645,33 @@ describe "Predefined global $," do end end +describe "Predefined global $." do + it "can be assigned an Integer" do + $. = 123 + $..should == 123 + end + + it "can be assigned a Float" do + $. = 123.5 + $..should == 123 + end + + it "should call #to_int to convert the object to an Integer" do + obj = mock("good-value") + obj.should_receive(:to_int).and_return(321) + + $. = obj + $..should == 321 + end + + it "raises TypeError if object can't be converted to an Integer" do + obj = mock("bad-value") + obj.should_receive(:to_int).and_return('abc') + + lambda { $. = obj }.should raise_error(TypeError) + end +end + describe "Predefined global $_" do it "is set to the last line read by e.g. StringIO#gets" do stdin = StringIO.new("foo\nbar\n", "r") diff --git a/spec/ruby/language/regexp/back-references_spec.rb b/spec/ruby/language/regexp/back-references_spec.rb index 607f4463fd..b4fb3b66a5 100644 --- a/spec/ruby/language/regexp/back-references_spec.rb +++ b/spec/ruby/language/regexp/back-references_spec.rb @@ -7,7 +7,7 @@ describe "Regexps with back-references" do $~.to_a.should == ["ll"] end - it "saves captures in numbered $[1-9] variables" do + it "saves captures in numbered $[1-N] variables" do "1234567890" =~ /(1)(2)(3)(4)(5)(6)(7)(8)(9)(0)/ $~.to_a.should == ["1234567890", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] $1.should == "1" @@ -19,6 +19,7 @@ describe "Regexps with back-references" do $7.should == "7" $8.should == "8" $9.should == "9" + $10.should == "0" end it "will not clobber capture variables across threads" do diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb index 646a700785..15b73aac7f 100644 --- a/spec/ruby/language/send_spec.rb +++ b/spec/ruby/language/send_spec.rb @@ -403,6 +403,29 @@ describe "Invoking a method" do specs.rest_len(0,*a,4,*5,6,7,*c,-1).should == 11 end + it "expands the Array elements from the splat after executing the arguments and block if no other arguments follow the splat" do + def self.m(*args, &block) + [args, block] + end + + args = [1, nil] + m(*args, &args.pop).should == [[1], nil] + + args = [1, nil] + order = [] + m(*(order << :args; args), &(order << :block; args.pop)).should == [[1], nil] + order.should == [:args, :block] + end + + it "evaluates the splatted arguments before the block if there are other arguments after the splat" do + def self.m(*args, &block) + [args, block] + end + + args = [1, nil] + m(*args, 2, &args.pop).should == [[1, nil, 2], nil] + end + it "expands an array to arguments grouped in parentheses" do specs.destructure2([40,2]).should == 42 end diff --git a/spec/ruby/library/date/constants_spec.rb b/spec/ruby/library/date/constants_spec.rb index ae343f07ec..8c31b056d8 100644 --- a/spec/ruby/library/date/constants_spec.rb +++ b/spec/ruby/library/date/constants_spec.rb @@ -36,11 +36,11 @@ describe "Date constants" do [Date::MONTHNAMES, Date::DAYNAMES, Date::ABBR_MONTHNAMES, Date::ABBR_DAYNAMES].each do |ary| lambda { ary << "Unknown" - }.should raise_error(RuntimeError, /frozen/) + }.should raise_error(frozen_error_class, /frozen/) ary.compact.each do |name| lambda { name << "modified" - }.should raise_error(RuntimeError, /frozen/) + }.should raise_error(frozen_error_class, /frozen/) end end end diff --git a/spec/ruby/library/mathn/mathn_spec.rb b/spec/ruby/library/mathn/mathn_spec.rb new file mode 100644 index 0000000000..aedf88ea7b --- /dev/null +++ b/spec/ruby/library/mathn/mathn_spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +describe "mathn" do + ruby_version_is "2.5" do + it "is no longer part of the standard library" do + -> { require "mathn" }.should raise_error(LoadError) + end + end +end diff --git a/spec/ruby/library/set/compare_by_identity_spec.rb b/spec/ruby/library/set/compare_by_identity_spec.rb index 437af9dd0b..2a62880a9d 100644 --- a/spec/ruby/library/set/compare_by_identity_spec.rb +++ b/spec/ruby/library/set/compare_by_identity_spec.rb @@ -92,11 +92,11 @@ ruby_version_is '2.4' do set.to_a.sort.should == [a1, a2].sort end - it "raises a RuntimeError on frozen sets" do + it "raises a #{frozen_error_class} on frozen sets" do set = Set.new.freeze lambda { set.compare_by_identity - }.should raise_error(RuntimeError, /frozen Hash/) + }.should raise_error(frozen_error_class, /frozen Hash/) end it "persists over #dups" do diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb index 8b661a3790..face3a510a 100644 --- a/spec/ruby/library/stringio/initialize_spec.rb +++ b/spec/ruby/library/stringio/initialize_spec.rb @@ -110,9 +110,9 @@ describe "StringIO#initialize when passed [Object, mode]" do io.closed_write?.should be_false end - it "raises a RuntimeError when passed a frozen String in truncate mode as StringIO backend" do + it "raises a #{frozen_error_class} when passed a frozen String in truncate mode as StringIO backend" do io = StringIO.allocate - lambda { io.send(:initialize, "example".freeze, IO::TRUNC) }.should raise_error(RuntimeError) + lambda { io.send(:initialize, "example".freeze, IO::TRUNC) }.should raise_error(frozen_error_class) end it "tries to convert the passed mode to a String using #to_str" do diff --git a/spec/ruby/library/stringio/open_spec.rb b/spec/ruby/library/stringio/open_spec.rb index 136ff5f972..95b715e583 100644 --- a/spec/ruby/library/stringio/open_spec.rb +++ b/spec/ruby/library/stringio/open_spec.rb @@ -134,8 +134,8 @@ describe "StringIO.open when passed [Object, mode]" do io.closed_write?.should be_false end - it "raises a RuntimeError when passed a frozen String in truncate mode as StringIO backend" do - lambda { StringIO.open("example".freeze, IO::TRUNC) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed a frozen String in truncate mode as StringIO backend" do + lambda { StringIO.open("example".freeze, IO::TRUNC) }.should raise_error(frozen_error_class) end it "tries to convert the passed mode to a String using #to_str" do diff --git a/spec/ruby/library/stringio/reopen_spec.rb b/spec/ruby/library/stringio/reopen_spec.rb index abdecdf9de..00e14f3425 100644 --- a/spec/ruby/library/stringio/reopen_spec.rb +++ b/spec/ruby/library/stringio/reopen_spec.rb @@ -48,8 +48,8 @@ describe "StringIO#reopen when passed [Object, Integer]" do lambda { @io.reopen("burn".freeze, IO::WRONLY | IO::APPEND) }.should raise_error(Errno::EACCES) end - it "raises a RuntimeError when trying to reopen self with a frozen String in truncate-mode" do - lambda { @io.reopen("burn".freeze, IO::RDONLY | IO::TRUNC) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when trying to reopen self with a frozen String in truncate-mode" do + lambda { @io.reopen("burn".freeze, IO::RDONLY | IO::TRUNC) }.should raise_error(frozen_error_class) end it "does not raise IOError when passed a frozen String in read-mode" do diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb index 025829a2b1..604bf880e5 100644 --- a/spec/ruby/library/stringio/shared/read.rb +++ b/spec/ruby/library/stringio/shared/read.rb @@ -27,8 +27,8 @@ describe :stringio_read, shared: true do lambda { @io.send(@method, 7, Object.new) }.should raise_error(TypeError) end - it "raises an error when passed a frozen String as buffer" do - lambda { @io.send(@method, 7, "".freeze) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} error when passed a frozen String as buffer" do + lambda { @io.send(@method, 7, "".freeze) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/library/weakref/fixtures/classes.rb b/spec/ruby/library/weakref/fixtures/classes.rb index 560c58b041..9a1d3ce370 100644 --- a/spec/ruby/library/weakref/fixtures/classes.rb +++ b/spec/ruby/library/weakref/fixtures/classes.rb @@ -15,8 +15,7 @@ class WeakRefSpec weak = nil 10_000.times do weaks << make_weakref - GC.start - GC.start + 10.times { GC.start } break if weak = weaks.find { |w| !w.weakref_alive? } end weak diff --git a/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb b/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb index e436441409..f94e48c051 100644 --- a/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb @@ -12,7 +12,7 @@ platform_is :windows do end it "returns expected value for Scripting Runtime's 'name' method" do - pointer_size = RUBY_PLATFORM =~ /\bx64\b/ ? 64 : 1.size * 8 + pointer_size = PlatformGuard::POINTER_SIZE @m_file_name.offset_vtbl.should == pointer_size end diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb index 2fd898ad94..d0f9c0b814 100644 --- a/spec/ruby/optional/capi/array_spec.rb +++ b/spec/ruby/optional/capi/array_spec.rb @@ -83,8 +83,8 @@ describe "C-API Array function" do @s.rb_ary_cat([1, 2], 3, 4).should == [1, 2, 3, 4] end - it "raises a RuntimeError if the array is frozen" do - lambda { @s.rb_ary_cat([].freeze, 1) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if the array is frozen" do + lambda { @s.rb_ary_cat([].freeze, 1) }.should raise_error(frozen_error_class) end end @@ -130,8 +130,8 @@ describe "C-API Array function" do @s.rb_ary_rotate([1, 2, 3, 4], -3).should == [2, 3, 4, 1] end - it "raises a RuntimeError if the array is frozen" do - lambda { @s.rb_ary_rotate([].freeze, 1) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if the array is frozen" do + lambda { @s.rb_ary_rotate([].freeze, 1) }.should raise_error(frozen_error_class) end end @@ -214,9 +214,9 @@ describe "C-API Array function" do a.should == [nil, nil, 7] end - it "raises a RuntimeError if the array is frozen" do + it "raises a #{frozen_error_class} if the array is frozen" do a = [1, 2, 3].freeze - lambda { @s.rb_ary_store(a, 1, 5) }.should raise_error(RuntimeError) + lambda { @s.rb_ary_store(a, 1, 5) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/optional/capi/ext/numeric_spec.c b/spec/ruby/optional/capi/ext/numeric_spec.c index 2f0f504549..0b7fbabd1c 100644 --- a/spec/ruby/optional/capi/ext/numeric_spec.c +++ b/spec/ruby/optional/capi/ext/numeric_spec.c @@ -5,6 +5,10 @@ extern "C" { #endif +static VALUE numeric_spec_size_of_VALUE(VALUE self) { + return INT2FIX(sizeof(VALUE)); +} + #ifdef HAVE_NUM2CHR static VALUE numeric_spec_NUM2CHR(VALUE self, VALUE value) { return INT2FIX(NUM2CHR(value)); @@ -17,6 +21,16 @@ static VALUE numeric_spec_rb_int2inum_14(VALUE self) { } #endif +#ifdef HAVE_RB_UINT2INUM +static VALUE numeric_spec_rb_uint2inum_14(VALUE self) { + return rb_uint2inum(14); +} + +static VALUE numeric_spec_rb_uint2inum_n14(VALUE self) { + return rb_uint2inum(-14); +} +#endif + #ifdef HAVE_RB_INTEGER static VALUE numeric_spec_rb_Integer(VALUE self, VALUE str) { return rb_Integer(str); @@ -106,6 +120,8 @@ void Init_numeric_spec(void) { VALUE cls; cls = rb_define_class("CApiNumericSpecs", rb_cObject); + rb_define_method(cls, "size_of_VALUE", numeric_spec_size_of_VALUE, 0); + #ifdef HAVE_NUM2CHR rb_define_method(cls, "NUM2CHR", numeric_spec_NUM2CHR, 1); #endif @@ -114,6 +130,11 @@ void Init_numeric_spec(void) { rb_define_method(cls, "rb_int2inum_14", numeric_spec_rb_int2inum_14, 0); #endif +#ifdef HAVE_RB_UINT2INUM + rb_define_method(cls, "rb_uint2inum_14", numeric_spec_rb_uint2inum_14, 0); + rb_define_method(cls, "rb_uint2inum_n14", numeric_spec_rb_uint2inum_n14, 0); +#endif + #ifdef HAVE_RB_INTEGER rb_define_method(cls, "rb_Integer", numeric_spec_rb_Integer, 1); #endif diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h index 341cff0428..50bc9033f0 100644 --- a/spec/ruby/optional/capi/ext/rubyspec.h +++ b/spec/ruby/optional/capi/ext/rubyspec.h @@ -409,6 +409,7 @@ #define HAVE_NUM2CHR 1 #define HAVE_RB_CMPINT 1 #define HAVE_RB_INT2INUM 1 +#define HAVE_RB_UINT2INUM 1 #define HAVE_RB_INTEGER 1 #define HAVE_RB_LL2INUM 1 #define HAVE_RB_NUM2DBL 1 diff --git a/spec/ruby/optional/capi/module_spec.rb b/spec/ruby/optional/capi/module_spec.rb index fbb5bd690d..909fa62b89 100644 --- a/spec/ruby/optional/capi/module_spec.rb +++ b/spec/ruby/optional/capi/module_spec.rb @@ -307,12 +307,12 @@ describe "CApiModule" do @frozen = @class.dup.freeze end - it "raises a RuntimeError when passed a name" do - lambda { @m.rb_undef_method @frozen, "ruby_test_method" }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed a name" do + lambda { @m.rb_undef_method @frozen, "ruby_test_method" }.should raise_error(frozen_error_class) end - it "raises a RuntimeError when passed a missing name" do - lambda { @m.rb_undef_method @frozen, "not_exist" }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} when passed a missing name" do + lambda { @m.rb_undef_method @frozen, "not_exist" }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/optional/capi/numeric_spec.rb b/spec/ruby/optional/capi/numeric_spec.rb index 1d4a44d7a2..ff7880a986 100644 --- a/spec/ruby/optional/capi/numeric_spec.rb +++ b/spec/ruby/optional/capi/numeric_spec.rb @@ -195,6 +195,13 @@ describe "CApiNumericSpecs" do @s.rb_num2ulong(-2147442171).should == 2147525125 end + it "converts positive Bignums if the values is less than 64bits" do + @s.rb_num2ulong(0xffff_ffff).should == 0xffff_ffff + @s.rb_num2ulong(2**30).should == 2**30 + @s.rb_num2ulong(fixnum_max+1).should == fixnum_max+1 + @s.rb_num2ulong(fixnum_max).should == fixnum_max + end + it "raises a RangeError if the value is more than 32bits" do lambda { @s.rb_num2ulong(0xffff_ffff+1) }.should raise_error(RangeError) end @@ -209,6 +216,13 @@ describe "CApiNumericSpecs" do @s.rb_num2ulong(-9223372036854734331).should == 9223372036854817285 end + it "converts positive Bignums if the values is less than 64bits" do + @s.rb_num2ulong(0xffff_ffff_ffff_ffff).should == 0xffff_ffff_ffff_ffff + @s.rb_num2ulong(2**62).should == 2**62 + @s.rb_num2ulong(fixnum_max+1).should == fixnum_max+1 + @s.rb_num2ulong(fixnum_max).should == fixnum_max + end + it "raises a RangeError if the value is more than 64bits" do lambda do @s.rb_num2ulong(0xffff_ffff_ffff_ffff+1) @@ -247,6 +261,20 @@ describe "CApiNumericSpecs" do end end + describe "rb_uint2inum" do + it "creates a new Fixnum from a long" do + i = @s.rb_uint2inum_14() + i.should be_kind_of(Fixnum) + i.should eql(14) + end + + it "creates a new Bignum from a negative long" do + i = @s.rb_uint2inum_n14() + i.should be_kind_of(Bignum) + i.should eql(2 ** (@s.size_of_VALUE * 8) - 14) + end + end + describe "rb_num2dbl" do it "raises a TypeError if passed nil" do lambda { @s.rb_num2dbl(nil) }.should raise_error(TypeError) diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb index 97bff38ec0..55faa27af5 100644 --- a/spec/ruby/optional/capi/object_spec.rb +++ b/spec/ruby/optional/capi/object_spec.rb @@ -313,8 +313,8 @@ describe "CApiObject" do it "does not rescue exceptions raised by #to_ary" do obj = mock("to_ary") - obj.should_receive(:to_ary).and_raise(RuntimeError) - lambda { @o.rb_check_array_type obj }.should raise_error(RuntimeError) + obj.should_receive(:to_ary).and_raise(frozen_error_class) + lambda { @o.rb_check_array_type obj }.should raise_error(frozen_error_class) end end @@ -666,14 +666,14 @@ describe "CApiObject" do obj.tainted?.should == true end - it "raises a RuntimeError if the object passed is frozen" do - lambda { @o.rb_obj_taint("".freeze) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if the object passed is frozen" do + lambda { @o.rb_obj_taint("".freeze) }.should raise_error(frozen_error_class) end end describe "rb_check_frozen" do - it "raises a RuntimeError if the obj is frozen" do - lambda { @o.rb_check_frozen("".freeze) }.should raise_error(RuntimeError) + it "raises a #{frozen_error_class} if the obj is frozen" do + lambda { @o.rb_check_frozen("".freeze) }.should raise_error(frozen_error_class) end it "does nothing when object isn't frozen" do diff --git a/spec/ruby/optional/capi/struct_spec.rb b/spec/ruby/optional/capi/struct_spec.rb index 9a0eafeb7b..e779312bef 100644 --- a/spec/ruby/optional/capi/struct_spec.rb +++ b/spec/ruby/optional/capi/struct_spec.rb @@ -184,9 +184,9 @@ describe "C-API Struct function" do lambda { @s.rb_struct_aset(@struct, 3, 1) }.should raise_error(IndexError) end - it "raises a RuntimeError if the struct is frozen" do + it "raises a #{frozen_error_class} if the struct is frozen" do @struct.freeze - lambda { @s.rb_struct_aset(@struct, :a, 1) }.should raise_error(RuntimeError) + lambda { @s.rb_struct_aset(@struct, :a, 1) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/shared/complex/Complex.rb b/spec/ruby/shared/complex/Complex.rb index 5a9715b161..15feb65754 100644 --- a/spec/ruby/shared/complex/Complex.rb +++ b/spec/ruby/shared/complex/Complex.rb @@ -72,7 +72,7 @@ describe :kernel_Complex, shared: true do describe "when passed a Numeric which responds to #real? with false" do it "returns the passed argument" do n = mock_numeric("unreal") - n.should_receive(:real?).and_return(false) + n.should_receive(:real?).any_number_of_times.and_return(false) Complex(n).should equal(n) end end diff --git a/spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb b/spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb new file mode 100644 index 0000000000..0b09ec5265 --- /dev/null +++ b/spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb @@ -0,0 +1,33 @@ +require File.expand_path('../../../fixtures/rational', __FILE__) + +describe :rational_arithmetic_exception_in_coerce, shared: true do + ruby_version_is ""..."2.5" do + it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError) + + # e.g. Rational(3, 4) + b + -> { Rational(3, 4).send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into Rational/) + end + + it "does not rescue Exception and StandardError siblings raised in other#coerce" do + [Exception, NoMemoryError].each do |exception| + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(exception) + + # e.g. Rational(3, 4) + b + -> { Rational(3, 4).send(@method, b) }.should raise_error(exception) + end + end + end + + ruby_version_is "2.5" do + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError) + + # e.g. Rational(3, 4) + b + -> { Rational(3, 4).send(@method, b) }.should raise_error(RationalSpecs::CoerceError) + end + end +end diff --git a/spec/ruby/shared/rational/comparison.rb b/spec/ruby/shared/rational/comparison.rb index c52363781f..ba2d0e9f20 100644 --- a/spec/ruby/shared/rational/comparison.rb +++ b/spec/ruby/shared/rational/comparison.rb @@ -1,4 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../../../fixtures/rational', __FILE__) describe :rational_cmp_rat, shared: true do it "returns 1 when self is greater than the passed argument" do @@ -78,6 +79,37 @@ describe :rational_cmp_coerce, shared: true do end end +describe :rational_cmp_coerce_exception, shared: true do + ruby_version_is ""..."2.5" do + it "rescues exception (StandardError and subclasses) raised in other#coerce and returns nil" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError) + + -> { + (Rational(3, 4) <=> b).should == nil + }.should complain(/Numerical comparison operators will no more rescue exceptions of #coerce/) + end + + it "does not rescue Exception and StandardError siblings raised in other#coerce" do + [Exception, NoMemoryError].each do |exception| + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(exception) + + -> { Rational(3, 4) <=> b }.should raise_error(exception) + end + end + end + + ruby_version_is "2.5" do + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError) + + -> { Rational(3, 4) <=> b }.should raise_error(RationalSpecs::CoerceError) + end + end +end + describe :rational_cmp_other, shared: true do it "returns nil" do (Rational <=> mock("Object")).should be_nil