File: values_at_spec.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 968 bytes parent folder | download
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
27
28
29
30
31
32
33
require 'spec_helper'

describe Immutable::SortedSet do
  describe '#values_at' do
    let(:sorted_set) { SS['a', 'b', 'c'] }

    it 'accepts any number of indices, and returns a sorted_set of items at those indices' do
      sorted_set.values_at(0).should   eql(SS['a'])
      sorted_set.values_at(1,2).should eql(SS['b', 'c'])
    end

    context 'when passed invalid indices' do
      it 'filters them out' do
        sorted_set.values_at(1,2,3).should  eql(SS['b', 'c'])
        sorted_set.values_at(-10,10).should eql(SS.empty)
      end
    end

    context 'when passed no arguments' do
      it 'returns an empty sorted_set' do
        sorted_set.values_at.should eql(SS.empty)
      end
    end

    context 'from a subclass' do
      it 'returns an instance of the subclass' do
        subclass = Class.new(Immutable::SortedSet)
        instance = subclass.new([1,2,3])
        instance.values_at(1,2).class.should be(subclass)
      end
    end
  end
end