Sha256: b4e9fa59b8bf992a6371a1d1c3bcaf8d91743c7de7dc8fe8b310e828d0c03c54

Contents?: true

Size: 1.88 KB

Versions: 83

Compression:

Stored size: 1.88 KB

Contents

describe :enumerable_take, :shared => true do
  before :each do
    @values = [4,3,2,1]
    @enum = EnumerableSpecs::Numerous.new(*@values)
  end

  it "returns the first count elements if given a count" do
    @enum.send(@method, 2).should == [4, 3]
  end

  it "returns an empty array when passed count on an empty array" do
    empty = EnumerableSpecs::Empty.new
    empty.send(@method, 0).should == []
    empty.send(@method, 1).should == []
    empty.send(@method, 2).should == []
  end

  it "returns an empty array when passed count == 0" do
    @enum.send(@method, 0).should == []
  end

  it "returns an array containing the first element when passed count == 1" do
    @enum.send(@method, 1).should == [4]
  end

  it "raises an ArgumentError when count is negative" do
    lambda { @enum.send(@method, -1) }.should raise_error(ArgumentError)
  end

  it "returns the entire array when count > length" do
    @enum.send(@method, 10).should == @values
  end

  it "tries to convert the passed argument to an Integer using #to_int" do
    obj = mock('to_int')
    obj.should_receive(:to_int).and_return(3).at_most(:twice) # called twice, no apparent reason. See redmine #1554
    @enum.send(@method, obj).should == [4, 3, 2]
  end

  it "raises a TypeError if the passed argument is not numeric" do
    lambda { @enum.send(@method, nil) }.should raise_error(TypeError)
    lambda { @enum.send(@method, "a") }.should raise_error(TypeError)

    obj = mock("nonnumeric")
    lambda { @enum.send(@method, obj) }.should raise_error(TypeError)
  end

  ruby_bug "#1554", "1.9.1" do
    it "consumes only what is needed" do
      thrower = EnumerableSpecs::ThrowingEach.new
      thrower.send(@method, 0).should == []
      counter = EnumerableSpecs::EachCounter.new(1,2,3,4)
      counter.send(@method, 2).should == [1,2]
      counter.times_called.should == 1
      counter.times_yielded.should == 2
    end
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/enumerable/shared/take.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/enumerable/shared/take.rb