Sha256: 350860f9c6032bd5c3e3a87635a2b661748c0466209a83e94ff656ee7a14eb8e

Contents?: true

Size: 973 Bytes

Versions: 10

Compression:

Stored size: 973 Bytes

Contents

# 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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.6.0 test/more/test_advisable.rb
facets-2.4.0 test/test_advisable.rb
facets-2.4.1 test/test_advisable.rb
facets-2.4.3 test/more/test_advisable.rb
facets-2.4.2 test/more/test_advisable.rb
facets-2.4.4 test/more/test_advisable.rb
facets-2.5.0 test/more/test_advisable.rb
facets-2.5.1 test/more/test_advisable.rb
facets-2.4.5 test/more/test_advisable.rb
facets-2.5.2 test/more/test_advisable.rb