summaryrefslogtreecommitdiff
path: root/spec/ruby/core/enumerable/shared/enumeratorized.rb
blob: 05d27b578326f2b89398d32e3d7387293a59c768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
describe :enumeratorized_with_unknown_size, shared: true do
  describe "when no block is given" do
    describe "returned Enumerator" do
      it "size returns nil" do
        @object.send(*@method).size.should == nil
      end
    end
  end
end

describe :enumeratorized_with_origin_size, shared: true do
  describe "when no block is given" do
    describe "returned Enumerator" do
      it "size returns the enumerable size" do
        @object.send(*@method).size.should == @object.size
      end
    end
  end
end

describe :enumeratorized_with_cycle_size, shared: true do
  describe "when no block is given" do
    describe "returned Enumerator" do
      describe "size" do
        it "should be the result of multiplying the enumerable size by the argument passed" do
          @object.cycle(2).size.should == @object.size * 2
          @object.cycle(7).size.should == @object.size * 7
          @object.cycle(0).size.should == 0
          @empty_object.cycle(2).size.should == 0
        end

        it "should be zero when the argument passed is 0 or less" do
          @object.cycle(-1).size.should == 0
        end

        it "should be Float::INFINITY when no argument is passed" do
          @object.cycle.size.should == Float::INFINITY
        end
      end
    end
  end
end