diff options
Diffstat (limited to 'spec/ruby/core')
134 files changed, 876 insertions, 431 deletions
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 |