From: Daniel Berger Date: 2005-11-09T12:07:12+09:00 Subject: Re: Testing array.push(array) Eric Hodel wrote: > On Nov 8, 2005, at 6:42 PM, Daniel Berger wrote: > > > Hi all, > > > > I recently tried to write an assertion like so: > > > > def test_array_infinity > > array = [1,2,3] > > assert_equal([1,2,3,"[...]"], array.push(array)) > > end > > > > But, it appears that "[...]" is not a literal string. However, I > > can't > > just remove the quotes, because then I get a syntax error. > > > > How do I test this case? > > I don't think you can do it so easily: > > irb(main):001:0> expected = [1, 2, 3] > => [1, 2, 3] > irb(main):002:0> expected << expected > => [1, 2, 3, [...]] > irb(main):003:0> array = [1,2,3] > => [1, 2, 3] > irb(main):004:0> array.push array > => [1, 2, 3, [...]] > irb(main):005:0> array == expected > SystemStackError: stack level too deep > from (irb):5:in `==' > from (irb):5 > from :0 > > Try: > > irb(main):007:0> array[0] == expected[0] > => true > irb(main):008:0> array[1] == expected[1] > => true > irb(main):009:0> array[2] == expected[2] > => true > irb(main):011:0> array[3] == array > => true Ah, that will work fine, thanks. Dan