aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/core/enumerator/size_spec.rb
blob: ef7940dc167c5bc0e911d098bea3e2bec8c8dd11 (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
require File.expand_path('../../../spec_helper', __FILE__)

describe "Enumerator#size" do
  it "returns same value if set size is an Integer" do
    Enumerator.new(100) {}.size.should == 100
  end

  it "returns nil if set size is nil" do
    Enumerator.new(nil) {}.size.should be_nil
  end

  it "returns returning value from size.call if set size is a Proc" do
    base_size = 100
    enum = Enumerator.new(lambda { base_size + 1 }) {}
    base_size = 200
    enum.size.should == 201
    base_size = 300
    enum.size.should == 301
  end

  it "returns the result from size.call if the size respond to call" do
    obj = mock('call')
    obj.should_receive(:call).and_return(42)
    Enumerator.new(obj) {}.size.should == 42
  end
end