mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@a6b8805
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6530b14cee
commit
8c5b60eb22
218 changed files with 4069 additions and 328 deletions
|
@ -15,7 +15,7 @@ describe "Array#at" do
|
|||
a.at(7).should == nil
|
||||
end
|
||||
|
||||
it "returns the (-n)'th elemet from the last, for the given negative index n" do
|
||||
it "returns the (-n)'th element from the last, for the given negative index n" do
|
||||
a = [1, 2, 3, 4, 5, 6]
|
||||
a.at(-1).should == 6
|
||||
a.at(-2).should == 5
|
||||
|
@ -50,7 +50,7 @@ describe "Array#at" do
|
|||
lambda { [].at("cat") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when 2 or more arguments is passed" do
|
||||
it "raises an ArgumentError when 2 or more arguments are passed" do
|
||||
lambda { [:a, :b].at(0,1) }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ describe "Array#&" do
|
|||
|
||||
it "does not modify the original Array" do
|
||||
a = [1, 1, 3, 5]
|
||||
a & [1, 2, 3]
|
||||
(a & [1, 2, 3]).should == [1, 3]
|
||||
a.should == [1, 1, 3, 5]
|
||||
end
|
||||
|
||||
|
@ -52,7 +52,7 @@ describe "Array#&" do
|
|||
obj1.stub!(:hash).and_return(0)
|
||||
obj2.stub!(:hash).and_return(0)
|
||||
obj1.should_receive(:eql?).at_least(1).and_return(true)
|
||||
obj2.should_receive(:eql?).at_least(1).and_return(true)
|
||||
obj2.stub!(:eql?).and_return(true)
|
||||
|
||||
([obj1] & [obj2]).should == [obj1]
|
||||
([obj1, obj1, obj2, obj2] & [obj2]).should == [obj1]
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
|
||||
describe "Array#max" do
|
||||
ruby_version_is "2.4" do
|
||||
it "is defined on Array" do
|
||||
[1].method(:max).owner.should equal Array
|
||||
end
|
||||
end
|
||||
|
||||
it "returns nil with no values" do
|
||||
[].max.should == nil
|
||||
end
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
|
||||
describe "Array#min" do
|
||||
ruby_version_is "2.4" do
|
||||
it "is defined on Array" do
|
||||
[1].method(:max).owner.should equal Array
|
||||
end
|
||||
end
|
||||
|
||||
it "returns nil with no values" do
|
||||
[].min.should == nil
|
||||
end
|
||||
|
|
52
spec/ruby/core/array/pack/buffer_spec.rb
Normal file
52
spec/ruby/core/array/pack/buffer_spec.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
# encoding: ascii-8bit
|
||||
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
ruby_version_is '2.4' do
|
||||
describe "Aray#pack with `buffer` option" do
|
||||
it "returns specified buffer" do
|
||||
n = [ 65, 66, 67 ]
|
||||
buffer = " "*3
|
||||
result = n.pack("ccc", buffer: buffer) #=> "ABC"
|
||||
result.should equal(buffer)
|
||||
end
|
||||
|
||||
it "adds result at the end of buffer content" do
|
||||
n = [ 65, 66, 67 ] # result without buffer is "ABC"
|
||||
|
||||
buffer = ""
|
||||
n.pack("ccc", buffer: buffer).should == "ABC"
|
||||
|
||||
buffer = "123"
|
||||
n.pack("ccc", buffer: buffer).should == "123ABC"
|
||||
|
||||
buffer = "12345"
|
||||
n.pack("ccc", buffer: buffer).should == "12345ABC"
|
||||
end
|
||||
|
||||
it "raises TypeError exception if buffer is not String" do
|
||||
lambda { [65].pack("ccc", buffer: []) }.should raise_error(
|
||||
TypeError, "buffer must be String, not Array")
|
||||
end
|
||||
|
||||
context "offset (@) is specified" do
|
||||
it 'keeps buffer content if it is longer than offset' do
|
||||
n = [ 65, 66, 67 ]
|
||||
buffer = "123456"
|
||||
n.pack("@3ccc", buffer: buffer).should == "123ABC"
|
||||
end
|
||||
|
||||
it "fills the gap with \0 if buffer content is shorter than offset" do
|
||||
n = [ 65, 66, 67 ]
|
||||
buffer = "123"
|
||||
n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
|
||||
end
|
||||
|
||||
it 'does not keep buffer content if it is longer than offset + result' do
|
||||
n = [ 65, 66, 67 ]
|
||||
buffer = "1234567890"
|
||||
n.pack("@3ccc", buffer: buffer).should == "123ABC"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -52,7 +52,7 @@ describe "Array#permutation" do
|
|||
end
|
||||
|
||||
it "returns no permutations when the given length has no permutations" do
|
||||
@numbers.permutation(9).entries.size == 0
|
||||
@numbers.permutation(9).entries.size.should == 0
|
||||
@numbers.permutation(9) { |n| @yielded << n }
|
||||
@yielded.should == []
|
||||
end
|
||||
|
|
|
@ -119,7 +119,7 @@ describe "Array#pop" do
|
|||
a.should == []
|
||||
end
|
||||
|
||||
it "raises a TypeError when the passed n can be coerced to Integer" do
|
||||
it "raises a TypeError when the passed n cannot be coerced to Integer" do
|
||||
lambda{ [1, 2].pop("cat") }.should raise_error(TypeError)
|
||||
lambda{ [1, 2].pop(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
|
|
@ -104,7 +104,7 @@ describe "Array#shift" do
|
|||
a.should == []
|
||||
end
|
||||
|
||||
it "raises a TypeError when the passed n can be coerced to Integer" do
|
||||
it "raises a TypeError when the passed n cannot be coerced to Integer" do
|
||||
lambda{ [1, 2].shift("cat") }.should raise_error(TypeError)
|
||||
lambda{ [1, 2].shift(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
|
44
spec/ruby/core/array/sum_spec.rb
Normal file
44
spec/ruby/core/array/sum_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
|
||||
ruby_version_is '2.4' do
|
||||
describe "Array#sum" do
|
||||
it "returns the sum of elements" do
|
||||
[1, 2, 3].sum.should == 6
|
||||
end
|
||||
|
||||
it "applies a block to each element before adding if it's given" do
|
||||
[1, 2, 3].sum { |i| i * 10 }.should == 60
|
||||
end
|
||||
|
||||
it "returns init value if array is empty" do
|
||||
[].sum(-1).should == -1
|
||||
end
|
||||
|
||||
it "returns 0 if array is empty and init is omitted" do
|
||||
[].sum.should == 0
|
||||
end
|
||||
|
||||
it "adds init value to the sum of elemens" do
|
||||
[1, 2, 3].sum(10).should == 16
|
||||
end
|
||||
|
||||
it "can be used for non-numeric objects by providing init value" do
|
||||
["a", "b", "c"].sum("").should == "abc"
|
||||
end
|
||||
|
||||
it 'raises TypeError if any element are not numeric' do
|
||||
lambda { ["a"].sum }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it 'raises TypeError if any element cannot be added to init value' do
|
||||
lambda { [1].sum([]) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "calls + to sum the elements" do
|
||||
a = mock("a")
|
||||
b = mock("b")
|
||||
a.should_receive(:+).with(b).and_return(42)
|
||||
[b].sum(a).should == 42
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue