aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/library/set/sortedset/each_spec.rb
blob: c715c403b2391ca0c18abf0be3eaabd42dd28b12 (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__)
require 'set'

describe "SortedSet#each" do
  before :each do
    @set = SortedSet[1, 2, 3]
  end

  it "yields each Object in self in sorted order" do
    ret = []
    SortedSet["one", "two", "three"].each { |x| ret << x }
    ret.should == ["one", "two", "three"].sort
  end

  it "returns self" do
    @set.each { |x| x }.should equal(@set)
  end

  it "returns an Enumerator when not passed a block" do
    enum = @set.each

    ret = []
    enum.each { |x| ret << x }
    ret.sort.should == [1, 2, 3]
  end
end