Sha256: b60e0d1ae3cd7ed34ddba75ca7682f33ccfd036c784db0a0eebe7247435b83ec

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "Advices on singleton method (also known as class method)" do
  it "class method" do
    class AdvicesOnClassMethod
      class << self
        include Aspect4r
        
        def value
          @value ||= []
        end
        
        around :test do |proxy|
          value << "around(before)"
          a4r_invoke proxy
          value << "around(after)"
        end
        
        before :test do
          value << "before"
        end
        
        after :test do
          value << "after"
        end
        
        def test
          value << "test"
        end
      end
    end
    
    AdvicesOnClassMethod.test
    AdvicesOnClassMethod.value.should == %w(before around(before) test around(after) after)
  end

  it "module singleton method" do
    module AdvicesOnModuleSingletonMethod
      class << self
        include Aspect4r
        
        def value
          @value ||= []
        end
        
        around :test do |proxy|
          value << "around(before)"
          a4r_invoke proxy
          value << "around(after)"
        end
        
        before :test do
          value << "before"
        end
        
        after :test do
          value << "after"
        end
        
        def test
          value << "test"
        end
      end
    end
    
    AdvicesOnModuleSingletonMethod.test
    AdvicesOnModuleSingletonMethod.value.should == %w(before around(before) test around(after) after)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aspect4r-0.8.2 spec/aspect4r/advice_on_class_method_spec.rb
aspect4r-0.8.1 spec/aspect4r/advice_on_class_method_spec.rb
aspect4r-0.8.0 spec/aspect4r/advice_on_class_method_spec.rb