Sha256: 86fa7ebf4416ff51489c1ef638bc32be3a19d378b39b39547daec7b70c41d793

Contents?: true

Size: 941 Bytes

Versions: 9

Compression:

Stored size: 941 Bytes

Contents

require 'test/unit'
require 'facets/advice'

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
facets-2.0.0 test/unit/test_advice.rb
facets-2.0.1 test/unit/test_advice.rb
facets-2.0.2 test/unit/test_advice.rb
facets-2.1.0 test/unit/test_advice.rb
facets-2.1.1 test/unit/test_advice.rb
facets-2.0.4 test/unit/test_advice.rb
facets-2.1.2 test/unit/test_advice.rb
facets-2.0.5 test/unit/test_advice.rb
facets-2.0.3 test/unit/test_advice.rb