PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/more/test_advisable.rb

https://bitbucket.org/mediashelf/fedora-migrator
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
  1. # Test for facets/advice.rb
  2. require 'test/unit'
  3. require 'facets/advisable'
  4. class TestAdvice < Test::Unit::TestCase
  5. class X
  6. extend Advisable
  7. attr_reader :out
  8. def initialize
  9. @out = []
  10. end
  11. before :x do
  12. @out << "BEFORE X#x"
  13. end
  14. after :x do
  15. @out << "AFTER X#x"
  16. end
  17. def x
  18. @out << "X#x"
  19. "x"
  20. end
  21. end
  22. class Y < X
  23. before :x do
  24. @out << "BEFORE Y#x"
  25. end
  26. after :x do
  27. @out << "AFTER Y#x"
  28. end
  29. around :x do |target|
  30. "{" + target.call + "}"
  31. end
  32. def x
  33. @out << "Y#x"
  34. super
  35. end
  36. end
  37. # tests
  38. def setup
  39. @x = X.new
  40. @y = Y.new
  41. end
  42. def test_x
  43. r = @x.x
  44. o = @x.out
  45. assert_equal("x", r)
  46. assert_equal(["BEFORE X#x", "X#x", "AFTER X#x"], o)
  47. end
  48. def test_y
  49. r = @y.x
  50. o = @y.out
  51. assert_equal("{x}", r)
  52. assert_equal(["BEFORE Y#x", "BEFORE X#x", "Y#x", "X#x", "AFTER X#x", "AFTER Y#x"], o)
  53. end
  54. end