Sha256: f2223bf06f1acb77ac69f032174b9e8954dca4edb517ac2da9c634223de23e82

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

require 'rext/enumerable'

describe Enumerable do
  
  describe "#every" do
    it "should map a method call" do
      list = %w( cookies icecream sugar )
      list.every.length.should == [7, 8 ,5]
    end
    
    it "should allow mapping shortcuts using a block" do
      people = []
      people << mock('Person', :name => 'TJ')
      people << mock('Person', :name => 'Scott')
      people.every { name.length }.should == [2, 5]
    end
  end
  
  describe "helpers" do
    describe "#group_by" do
      before :each do
        @enum = 'foo', :bar, 1, 2, 3
        @results = {
          String => ['foo'],
          Symbol => [:bar],
          Fixnum => [1, 2, 3]
        }
      end
      
      it "should group an enum" do
        @enum.group_by { |v| v.class }.should == @results
      end
      
      it "should group using instance evaluated block" do
        @enum.group_by { self.class }.should == @results
      end
      
      it "should group by method call" do
        @enum.group_by.class.should == @results
      end
    end
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
visionmedia-rext-0.0.2 spec/enumerable_spec.rb
visionmedia-rext-0.0.3 spec/enumerable_spec.rb
visionmedia-rext-0.0.4 spec/enumerable_spec.rb
visionmedia-rext-0.0.5 spec/enumerable_spec.rb
visionmedia-rext-0.0.6 spec/enumerable_spec.rb
visionmedia-rext-0.0.7 spec/enumerable_spec.rb
visionmedia-rext-0.0.8 spec/enumerable_spec.rb
visionmedia-rext-0.1.0 spec/enumerable_spec.rb