1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Thread::Queue.new should accept an Enumerable [Feature #17327]

Enumerable implements #to_a but not #to_array.
This commit is contained in:
Nobuyoshi Nakada 2021-02-12 12:21:49 +09:00
parent e8b210542b
commit 1f0e0dfb22
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
3 changed files with 27 additions and 11 deletions

View file

@ -18,9 +18,9 @@ describe "Queue#initialize" do
q.should.empty?
end
it "uses #to_ary on the provided Enumerable" do
it "uses #to_a on the provided Enumerable" do
enumerable = MockObject.new('mock-enumerable')
enumerable.should_receive(:to_ary).and_return([1, 2, 3])
enumerable.should_receive(:to_a).and_return([1, 2, 3])
q = Queue.new(enumerable)
q.size.should == 3
q.should_not.empty?
@ -30,15 +30,9 @@ describe "Queue#initialize" do
q.should.empty?
end
it "raises if the provided Enumerable does not respond to #to_ary" do
it "raises if the provided Enumerable does not respond to #to_a" do
enumerable = MockObject.new('mock-enumerable')
-> { Queue.new(enumerable) }.should raise_error(TypeError, "no implicit conversion of MockObject into Array")
end
it "raises if the provided Enumerable #to_ary does not return an Array" do
enumerable = MockObject.new('mock-enumerable')
enumerable.should_receive(:to_ary).and_return(14)
-> { Queue.new(enumerable) }.should raise_error(TypeError, "can't convert MockObject to Array (MockObject#to_ary gives Integer)")
-> { Queue.new(enumerable) }.should raise_error(TypeError, "can't convert MockObject into Array")
end
end
end