File: inspect_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 (47 lines) | stat: -rw-r--r-- 1,296 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'spec_helper'

describe Immutable::Set do
  describe '#inspect' do
    [
      [[], 'Immutable::Set[]'],
      [['A'], 'Immutable::Set["A"]'],
    ].each do |values, expected|
      describe "on #{values.inspect}" do
        let(:set) { S[*values] }

        it "returns #{expected.inspect}" do
          set.inspect.should == expected
        end

        it "returns a string which can be eval'd to get an equivalent set" do
          eval(set.inspect).should eql(set)
        end
      end
    end

    describe 'on ["A", "B", "C"]' do
      let(:set) { S['A', 'B', 'C'] }

      it 'returns a programmer-readable representation of the set contents' do
        set.inspect.should match(/^Immutable::Set\["[A-C]", "[A-C]", "[A-C]"\]$/)
      end

      it "returns a string which can be eval'd to get an equivalent set" do
        eval(set.inspect).should eql(set)
      end
    end

    context 'from a subclass' do
      MySet = Class.new(Immutable::Set)
      let(:set) { MySet[1, 2] }

      it 'returns a programmer-readable representation of the set contents' do
        set.inspect.should match(/^MySet\[[1-2], [1-2]\]$/)
      end

      it "returns a string which can be eval'd to get an equivalent set" do
        eval(set.inspect).should eql(set)
      end
    end
  end
end