C0 code coverage information
Generated on Sun Oct 26 11:18:05 -0500 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1
2 require File.dirname(__FILE__) + '/../spec_helper'
3 require 'aquarium/spec_example_types'
4 require 'aquarium/aspects'
5
6 include Aquarium::Aspects
7
8 # Explicitly check that nested types are handled correctly.
9
10 module Nested1
11 module Nested2
12 class MyClass
13 def do1 *args
14 yield
15 end
16 end
17
18 module MyModule
19 def do2 *args
20 yield
21 end
22 end
23 end
24 end
25
26 describe Aspect, ".new when advising methods in a nested class" do
27 after(:each) do
28 @aspect.unadvise if @aspect
29 end
30
31 it "should correctly advise methods in a nested class." do
32 myclass = Nested1::Nested2::MyClass.new
33 advice_called = false
34 @aspect = Aspect.new :before, :pointcut => {:type => Nested1::Nested2::MyClass, :methods => :do1} do |jp, obj, *args|
35 advice_called = true
36 args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
37 jp.context.advice_kind.should == :before
38 jp.context.advised_object.should == myclass
39 jp.context.returned_value.should == nil
40 jp.context.raised_exception.should == nil
41 end
42 block_called = 0
43 myclass.do1(:a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2') { |*args| block_called += 1 }
44 block_called.should == 1
45 advice_called.should be_true
46 end
47
48 it "should correctly advise methods in an instance of the nested class." do
49 myclass = Nested1::Nested2::MyClass.new
50 advice_called = false
51 @aspect = Aspect.new :before, :pointcut => {:object => myclass, :methods => :do1} do |jp, obj, *args|
52 advice_called = true
53 args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
54 jp.context.advice_kind.should == :before
55 jp.context.advised_object.should == myclass
56 jp.context.returned_value.should == nil
57 jp.context.raised_exception.should == nil
58 end
59 block_called = 0
60 myclass.do1(:a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2') { |*args| block_called += 1 }
61 block_called.should == 1
62 advice_called.should be_true
63 end
64 end
65
66 describe Aspect, ".new when advising methods in a nested module included by a class" do
67 after(:each) do
68 @aspect.unadvise if @aspect
69 end
70
71 it "should correctly advise the module's methods when the nested module is specified." do
72 class MyClassWithModule1
73 include Nested1::Nested2::MyModule
74 end
75
76 myclass = MyClassWithModule1.new
77 advice_called = false
78 @aspect = Aspect.new :before, :pointcut => {:type => Nested1::Nested2::MyModule, :methods => :do2} do |jp, obj, *args|
79 advice_called = true
80 args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
81 jp.context.advice_kind.should == :before
82 jp.context.advised_object.should == myclass
83 jp.context.returned_value.should == nil
84 jp.context.raised_exception.should == nil
85 end
86 block_called = 0
87 myclass.do2(:a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2') { |*args| block_called += 1 }
88 block_called.should == 1
89 advice_called.should be_true
90 end
91
92 it "should correctly advise the module's methods when the class is specified." do
93 class MyClassWithModule2
94 include Nested1::Nested2::MyModule
95 end
96
97 myclass = MyClassWithModule2.new
98 advice_called = false
99 @aspect = Aspect.new :before, :pointcut => {:type => MyClassWithModule2, :methods => :do2} do |jp, obj, *args|
100 advice_called = true
101 args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
102 jp.context.advice_kind.should == :before
103 jp.context.advised_object.should == myclass
104 jp.context.returned_value.should == nil
105 jp.context.raised_exception.should == nil
106 end
107 block_called = 0
108 myclass.do2(:a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2') { |*args| block_called += 1 }
109 block_called.should == 1
110 advice_called.should be_true
111 end
112
113 it "should correctly advise the module's methods when an instance of the class is specified." do
114 class MyClassWithModule3
115 include Nested1::Nested2::MyModule
116 end
117
118 myclass = MyClassWithModule3.new
119 context = nil
120 advice_called = false
121 @aspect = Aspect.new :before, :pointcut => {:object => myclass, :methods => :do2} do |jp, obj, *args|
122 advice_called = true
123 args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
124 jp.context.advice_kind.should == :before
125 jp.context.advised_object.should == myclass
126 jp.context.returned_value.should == nil
127 jp.context.raised_exception.should == nil
128 end
129 block_called = 0
130 myclass.do2(:a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2') { |*args| block_called += 1 }
131 block_called.should == 1
132 advice_called.should be_true
133 end
134 end
135
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.