/vendor/gems/facets-2.4.5/test/more/test_advisable.rb
Ruby | 71 lines | 52 code | 17 blank | 2 comment | 0 complexity | b3ae69114aceea23abd557b9c134b919 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
- # Test for facets/advice.rb
- require 'test/unit'
- require 'facets/advisable'
- class TestAdvice < Test::Unit::TestCase
- class X
- extend Advisable
- attr_reader :out
- def initialize
- @out = []
- end
- before :x do
- @out << "BEFORE X#x"
- end
- after :x do
- @out << "AFTER X#x"
- end
- def x
- @out << "X#x"
- "x"
- end
- end
- class Y < X
- before :x do
- @out << "BEFORE Y#x"
- end
- after :x do
- @out << "AFTER Y#x"
- end
- around :x do |target|
- "{" + target.call + "}"
- end
- def x
- @out << "Y#x"
- super
- end
- end
- # tests
- def setup
- @x = X.new
- @y = Y.new
- end
- def test_x
- r = @x.x
- o = @x.out
- assert_equal("x", r)
- assert_equal(["BEFORE X#x", "X#x", "AFTER X#x"], o)
- end
- def test_y
- r = @y.x
- o = @y.out
- assert_equal("{x}", r)
- assert_equal(["BEFORE Y#x", "BEFORE X#x", "Y#x", "X#x", "AFTER X#x", "AFTER Y#x"], o)
- end
- end