C0 code coverage information
Generated on Sun Oct 26 11:18:06 -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 # Specifically tests behavior when two or more advices apply to the same join points,
2 # where one advice is for the type and the other is for an object of the type.
3
4 require File.dirname(__FILE__) + '/../spec_helper'
5 require 'aquarium/spec_example_types'
6 require 'aquarium/aspects/concurrently_accessed'
7 require 'aquarium/aspects'
8
9 include Aquarium::Aspects
10
11 def make_aspect method, advice_kind, type_or_object_key, type_or_object
12 Aspect.new advice_kind, :pointcut => {type_or_object_key => type_or_object, :method => method} do |jp, obj, *args|
13 @invoked << type_or_object_key
14 jp.proceed if advice_kind == :around
15 end
16 end
17
18 describe "Advising an object join point and then the corresponding type join point" do
19 before :each do
20 @aspects = []
21 @invoked = []
22 @accessed = ConcurrentlyAccessed.new
23 @accessed2 = ConcurrentlyAccessed.new
24 end
25 after :each do
26 @aspects.each {|a| a.unadvise}
27 end
28
29 Aquarium::Aspects::Advice.kinds.each do |advice_kind|
30 it "should invoke both the :#{advice_kind} advices when the object join point is invoked" do
31 method = advice_kind == :after_raising ? :invoke_raises : :invoke
32 @aspects << make_aspect(method, advice_kind, :object, @accessed)
33 @aspects << make_aspect(method, advice_kind, :type, ConcurrentlyAccessed)
34 begin
35 @accessed.method(method).call :a1, :a2
36 fail if advice_kind == :after_raising
37 rescue ConcurrentlyAccessed::Error
38 fail unless advice_kind == :after_raising
39 end
40 @invoked.sort.should == [:object, :type]
41 end
42 end
43
44 Aquarium::Aspects::Advice.kinds.each do |advice_kind|
45 it "should invoke only the :#{advice_kind} type advice when a different object is invoked" do
46 method = advice_kind == :after_raising ? :invoke_raises : :invoke
47 @aspects << make_aspect(method, advice_kind, :object, @accessed2)
48 @aspects << make_aspect(method, advice_kind, :type, ConcurrentlyAccessed)
49 begin
50 @accessed.method(method).call :a1, :a2
51 fail if advice_kind == :after_raising
52 rescue ConcurrentlyAccessed::Error
53 fail unless advice_kind == :after_raising
54 end
55 @invoked.should == [:type]
56 end
57 end
58 end
59
60 describe "Advising a type join point and then the corresponding join point on an object of the type" do
61 before :each do
62 @aspects = []
63 @invoked = []
64 @accessed = ConcurrentlyAccessed.new
65 end
66 after :each do
67 @aspects.each {|a| a.unadvise}
68 end
69
70 [:around, :before].each do |advice_kind|
71 it "should invoke first the advice on the object join point and then invoke the advice on the type join point for :#{advice_kind} advice" do
72 method = advice_kind == :after_raising ? :invoke_raises : :invoke
73 @aspects << make_aspect(:invoke, advice_kind, :type, ConcurrentlyAccessed)
74 @aspects << make_aspect(:invoke, advice_kind, :object, @accessed)
75 @accessed.invoke :a1, :a2
76 @invoked.should == [:object, :type]
77 end
78 end
79
80 [:after, :after_returning, :after_raising].each do |advice_kind|
81 it "should invoke first the advice on the type join point and then invoke the advice on the object join point for :#{advice_kind} advice" do
82 method = advice_kind == :after_raising ? :invoke_raises : :invoke
83 @aspects << make_aspect(method, advice_kind, :type, ConcurrentlyAccessed)
84 @aspects << make_aspect(method, advice_kind, :object, @accessed)
85 begin
86 @accessed.method(method).call :a1, :a2
87 fail if advice_kind == :after_raising
88 rescue ConcurrentlyAccessed::Error
89 fail unless advice_kind == :after_raising
90 end
91 @invoked.should == [:type, :object]
92 end
93 end
94 end
95
96 describe "Removing two advices, one from an object join point and one from the corresponding type join point" do
97 before :each do
98 @aspects = []
99 @invoked = []
100 @accessed = ConcurrentlyAccessed.new
101 end
102
103 Aquarium::Aspects::Advice.kinds.each do |advice_kind|
104 it "should be removable for :#{advice_kind} advice only when the object join point was advised first" do
105 method = advice_kind == :after_raising ? :invoke_raises : :invoke
106 @aspects << make_aspect(method, advice_kind, :object, @accessed)
107 @aspects << make_aspect(method, advice_kind, :type, ConcurrentlyAccessed)
108 @aspects.each {|a| a.unadvise}
109 begin
110 @accessed.method(method).call :a1, :a2
111 fail if advice_kind == :after_raising
112 rescue ConcurrentlyAccessed::Error
113 fail unless advice_kind == :after_raising
114 end
115 @invoked.should == []
116 end
117 end
118 end
119
120
121
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.