mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@0fe33ac
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0f989b87a0
commit
a34db218ad
162 changed files with 1267 additions and 621 deletions
|
@ -55,6 +55,11 @@ Lint/EmptyExpression:
|
|||
Exclude:
|
||||
- 'language/**/*.rb'
|
||||
|
||||
Lint/EmptyWhen:
|
||||
Exclude:
|
||||
- language/case_spec.rb
|
||||
- optional/capi/spec_helper.rb
|
||||
|
||||
Lint/UriRegexp:
|
||||
Exclude:
|
||||
- 'library/uri/regexp_spec.rb'
|
||||
|
|
|
@ -3,29 +3,24 @@ language: ruby
|
|||
install:
|
||||
- git clone https://github.com/ruby/mspec.git ../mspec
|
||||
script:
|
||||
- if [ -n "$RUBOCOP" ]; then gem install rubocop -v 0.52.0 && rubocop; fi
|
||||
- ../mspec/bin/mspec $MSPEC_OPTS
|
||||
matrix:
|
||||
include:
|
||||
- os: osx
|
||||
osx_image: xcode9
|
||||
rvm: 2.4.2
|
||||
env: CHECK_LEAKS=true
|
||||
- os: linux
|
||||
rvm: 2.4.2
|
||||
- rvm: 2.5.0
|
||||
env: MSPEC_OPTS="-R2 -ff"
|
||||
- os: linux
|
||||
rvm: 2.2.8
|
||||
- os: linux
|
||||
rvm: 2.3.5
|
||||
- os: linux
|
||||
rvm: 2.4.2
|
||||
env: CHECK_LEAKS=true RUBOCOP=true
|
||||
- os: linux
|
||||
rvm: ruby-head
|
||||
- rvm: 2.2.9
|
||||
- rvm: 2.3.6
|
||||
- rvm: 2.4.3
|
||||
- rvm: 2.5.0
|
||||
env: CHECK_LEAKS=true
|
||||
- rvm: ruby-head
|
||||
- env: RUBOCOP=true
|
||||
rvm: 2.4.3
|
||||
script:
|
||||
- gem install rubocop -v 0.52.0
|
||||
- rubocop
|
||||
allow_failures:
|
||||
- os: linux
|
||||
rvm: ruby-head
|
||||
- rvm: ruby-head
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
4
spec/ruby/core/float/fixtures/classes.rb
Normal file
4
spec/ruby/core/float/fixtures/classes.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
module FloatSpecs
|
||||
class CoerceError < StandardError
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!)
|
||||
|
|
|
@ -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!)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
7
spec/ruby/core/integer/divide_spec.rb
Normal file
7
spec/ruby/core/integer/divide_spec.rb
Normal file
|
@ -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
|
||||
|
4
spec/ruby/core/integer/fixtures/classes.rb
Normal file
4
spec/ruby/core/integer/fixtures/classes.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
module IntegerSpecs
|
||||
class CoerceError < StandardError
|
||||
end
|
||||
end
|
7
spec/ruby/core/integer/gt_spec.rb
Normal file
7
spec/ruby/core/integer/gt_spec.rb
Normal file
|
@ -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
|
||||
|
7
spec/ruby/core/integer/gte_spec.rb
Normal file
7
spec/ruby/core/integer/gte_spec.rb
Normal file
|
@ -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
|
||||
|
6
spec/ruby/core/integer/lt_spec.rb
Normal file
6
spec/ruby/core/integer/lt_spec.rb
Normal file
|
@ -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
|
6
spec/ruby/core/integer/lte_spec.rb
Normal file
6
spec/ruby/core/integer/lte_spec.rb
Normal file
|
@ -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
|
7
spec/ruby/core/integer/minus_spec.rb
Normal file
7
spec/ruby/core/integer/minus_spec.rb
Normal file
|
@ -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
|
||||
|
6
spec/ruby/core/integer/multiply_spec.rb
Normal file
6
spec/ruby/core/integer/multiply_spec.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
6
spec/ruby/core/integer/plus_spec.rb
Normal file
6
spec/ruby/core/integer/plus_spec.rb
Normal file
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
9
spec/ruby/core/method/case_compare_spec.rb
Normal file
9
spec/ruby/core/method/case_compare_spec.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -62,4 +62,7 @@ module RangeSpecs
|
|||
|
||||
class MyRange < Range
|
||||
end
|
||||
|
||||
class ComparisonError < RuntimeError
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue