From: Eric Hodel Date: 2005-11-09T11:48:57+09:00 Subject: Re: Testing array.push(array) 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 -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04