Sha256: 4483cc26e09346739c515e5072097186e2ddc64df99e23db39544492867ad9ad

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 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
      include Aspect4r

      class << self

        def value
          @value ||= []
        end
        
        around :test do |&block|
          value << "around(before)"
          block.call
          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
      include Aspect4r

      class << self
 
        def value
          @value ||= []
        end
        
        around :test do |&block|
          value << "around(before)"
          block.call
          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

1 entries across 1 versions & 1 rubygems

Version Path
aspect4r-0.9.1 spec/aspect4r/advice_on_class_method_spec.rb