1 require File.dirname(__FILE__) + '/../../spec_helper'
3 describe "Enumerable#count" do
4 # Assuming array doesn't override count. If this changes, use
5 # EachDefiner from core/enumerable/fixtures/classes.rb
7 it "requires an argument or a block" do
8 lambda { [1, 2, 3, 4].count }.should raise_error
11 it "counts nils if given nil as an argument" do
12 [nil, nil, nil, false].count(nil).should == 3
15 it "accepts an argument for comparison using ==" do
17 ary.count(2).should == 2
20 it "uses a block for comparison" do
22 ary.count{|x|x%2==0}.should == 3