require 'test/unit' require 'elusion' class PassiveTest < Test::Unit::TestCase def test_01_simple elusion = Elusion.new { |b| b.one 1 b.two 2 b.three 3 } assert_equal [1, 2, 3], [elusion.one, elusion.two, elusion.three] end def test_02_nested elusion = Elusion.new { |a| a.first { |b| b.one 1 b.two 2 b.three 3 } a.second { |b| b.one 1 b.two 2 b.three 3 } a.third { |b| b.one 1 b.two 2 b.three 3 } } assert_equal [1, 2, 3], [elusion.first.one, elusion.second.two, elusion.third.three] end def test_03_multiple elusion = Elusion.new { |a| a.foo 1 a.foo 2 a.foo 3 } assert_equal [1, 2, 3], elusion.foo end def test_04_combined elusion = Elusion.new { |a| a.foo { |b| b.first "first" } a.foo { |b| b.last "last" } } assert_equal ["first", "last"], [elusion.foo.first.first, elusion.foo.last.last] end def test_05_nomethod elusion = Elusion.new assert_raise(NameError) { elusion.foo } elusion.__define__ { |b| b.foo 1 } assert_equal 1, elusion.foo end def test_06_specialnames e = Elusion.new([:send, :id, :to_s]) { |e| e.send 1 e.id 2 e.to_s :a e.to_s :b e.to_s :c } assert [1, 2, [:a, :b, :c]], [e.send, e.id, e.to_s] end def test_07_blockcall elusion = Elusion.new { |a| a.first 1 a.first 2 a.first 3 a.second false a.third { |b| b.one 1 b.two 2 b.three 3 } } n = [] elusion.first { |i| n << i } assert_equal [1, 2, 3], n n = false elusion.second { n = true } assert_equal false, n elusion.third { |v| assert_equal [1, 2, 3], [v.one, v.two, v.three] } end end