Skip to content
This repository
branch: readruby
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 46 lines (39 sloc) 1.147 kb
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
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'

describe "Array#to_s" do
  ruby_version_is "" .. "1.9" do
    it "is equivalent to #join without a separator string" do
      old = $,
      begin
        a = [1, 2, 3, 4]
        a.to_s.should == a.join
        $, = '-'
        a.to_s.should == a.join
      ensure
        $, = old
      end
    end

    it "returns '[...]' for an empty array embedded in itself" do
      ArraySpecs.empty_recursive_array.to_s.should == "[...]"
    end

    ruby_bug "[ruby-dev:37019]", "1.8.6.319" do
      it "returns '[...]' for the embedded array in a recursive array" do
        a = [1, 2, 3]; a << a
        a.to_s.should == "123[...]"
      end
    end
  end

  ruby_version_is "1.9" do
    it "is equivalent to Array#inspect" do
      a = [1, 2, 3, 4]
      a.to_s.should == a.inspect
    end

    it "is equivalent to Array#inspect in a recursive array" do
      a = [1, 2, 3, 4]; a << a
      a.to_s.should == a.inspect

      a = ArraySpecs.empty_recursive_array
      a.to_s.should == "[[...]]"
      a.inspect == "[[...]]"
    end
  end
end
Something went wrong with that request. Please try again.