Sha256: 4f1491a2b2ee26d710251ed01895a7692d3059de88c73805ff3e5f06f5b21e41

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')

require 'test/unit'
require 'facets/more/aspects'

class TestCaseAspects < Test::Unit::TestCase # :nodoc: all

  class Monitor
    def self.pre(this)
      this.ma = 2
    end

    def self.post(this)
      this.mb = 5
    end
  end

  module Localize
    def localize
      @ll = 5
    end
  end

  module Tester
    include ::Aspects

    attr_accessor :ta
    pre { |this| this.ta = 5 }
  end
  
  class Dummy
    include ::Aspects
    include Tester

    attr_accessor :a, :b, :c
    attr_accessor :oa, :ob
    attr_accessor :ma, :mb
    attr_accessor :ll
    attr_accessor :pa

    pre :pre_advice
    wrap Monitor
    wrap Localize, :pre => :localize
    post { |this| this.pa = 3 }

    def initialize
      @a = 0
    end
    
    def hello(q)
      @a += 1 + q
    end

    def pre_advice
      @b = 1
      @a += 1
    end

    def post_advice
      @c = 1
    end
  end

  # Class aspect.
  
  class Observer < Aspect
    def self.pre(this)
      this.oa = 9
    end
  end
  
  # Instance aspect.

  class Epilogue < Aspect
    def post(this)
      this.ob = 9
    end
  end
  
  def test_all
    Observer.wrap(Dummy, :hello)
    Epilogue.new.wrap(Dummy, :hello)
    ::Aspects.wrap(Dummy, :hello)

    d = Dummy.new
    d.hello(3)
    assert_equal 5, d.a
    assert_equal 1, d.b
    assert_equal 9, d.oa
    assert_equal 9, d.ob
    assert_equal 2, d.ma
    assert_equal 5, d.mb
    assert_equal 5, d.ll
    assert_equal 3, d.pa

    assert_equal 5, d.ta
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
glue-0.41.0 test/glue/tc_aspects.rb
glue-0.31.0 test/glue/tc_aspects.rb
glue-0.30.0 test/glue/tc_aspects.rb
glue-0.40.0 test/glue/tc_aspects.rb