C0 code coverage information

Generated on Sun Oct 26 11:17:55 -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.
Name Total lines Lines of code Total coverage Code coverage
spec/aquarium/aspects/advice_spec.rb 253 229
100.0% 
100.0% 
  1 require File.dirname(__FILE__) + '/../spec_helper'
  2 require 'aquarium/spec_example_types'
  3 require 'aquarium/aspects/advice'
  4 require 'aquarium/aspects/aspect'
  5 include Aquarium::Aspects
  6 
  7 describe Advice, "#sort_by_priority_order" do
  8   it "should return an empty array for empty input" do
  9     Advice.sort_by_priority_order([]).should == []
 10   end
 11   
 12   it "should return a properly-sorted array for arbitrary input of valid advice kind symbols" do
 13     Advice.sort_by_priority_order([:after_raising, :after_returning, :before, :after, :around]).should == [:around, :before, :after, :after_returning, :after_raising]
 14   end
 15   
 16   it "should accept strings for the advice kinds, but return sorted symbols" do
 17     Advice.sort_by_priority_order(["after_raising", "after_returning", "before", "after", "around"]).should == [:around, :before, :after, :after_returning, :after_raising]
 18   end
 19 end
 20 
 21 describe Advice, "#invoke_original_join_point" do
 22   class InvocationCounter
 23     def initialize; @counter = 0; end
 24     def increment; @counter += 1; end
 25     def counter; @counter; end
 26   end
 27   
 28   it "should invoke the original join_point with multiple advices" do
 29     aspect1 = Aspect.new :before, :type => InvocationCounter, :method => :increment do |jp, o|
 30       jp.invoke_original_join_point
 31     end
 32     aspect2 = Aspect.new :around, :type => InvocationCounter, :method => :increment do |jp, o|
 33       jp.invoke_original_join_point
 34       jp.proceed
 35     end
 36     ic = InvocationCounter.new
 37     ic.increment
 38     ic.counter == 3
 39     aspect1.unadvise
 40     aspect2.unadvise
 41   end
 42   
 43   Advice.kinds.each do |kind|
 44     it "should invoke the original join_point with #{kind} advice" do
 45       aspect = Aspect.new kind, :type => InvocationCounter, :method => :increment do |jp, o|
 46         jp.invoke_original_join_point
 47       end
 48       ic = InvocationCounter.new
 49       ic.increment
 50       ic.counter == 1
 51       aspect.unadvise
 52     end
 53   end
 54 end
 55 
 56 def should_raise_expected_exception_with_message message
 57   begin
 58     yield ; fail
 59   rescue => e
 60     e.message.should include(message)
 61   end
 62 end
 63 
 64 describe Advice, "that raises an exception" do
 65   it "should add the kind of advice to the exception message." do
 66     aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_watchful_method} do |jp, obj, *args| 
 67       raise SpecExceptionForTesting.new("advice called with args: #{args.inspect}")
 68     end
 69     should_raise_expected_exception_with_message("\"before\" advice") {Watchful.new.public_watchful_method(:a1, :a2)}
 70     aspect.unadvise
 71   end
 72 
 73   it "should add the \"Class#method\" of the advised object's type and method to the exception message." do
 74     aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_watchful_method} do |jp, obj, *args| 
 75       raise "advice called with args: #{args.inspect}"
 76     end
 77     should_raise_expected_exception_with_message("Watchful#public_watchful_method") {Watchful.new.public_watchful_method(:a1, :a2)}
 78     aspect.unadvise
 79   end
 80 
 81   it "should add the \"Class.method\" of the advised type's class method to the exception message." do
 82     aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, obj, *args| 
 83       raise "advice called with args: #{args.inspect}"
 84     end
 85     should_raise_expected_exception_with_message("Watchful.public_class_watchful_method") {Watchful.public_class_watchful_method(:a1, :a2)}
 86     aspect.unadvise
 87   end
 88 
 89   it "should rethrow an exception of the same type as the original exception." do
 90     class MyException1 < Exception; end
 91     aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, obj, *args| 
 92       raise MyException1.new("advice called with args: #{args.inspect}")
 93     end
 94     lambda { Watchful.public_class_watchful_method :a1, :a2 }.should raise_error(MyException1)
 95     aspect.unadvise
 96   end
 97 
 98   it "should rethrow an exception with the same backtrace as the original exception." do
 99     class MyException2 < Exception; end
100     @backtrace = nil
101     aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, obj, *args| 
102       begin
103         exception = MyException2.new("advice called with args: #{args.inspect}")
104         raise exception
105       rescue Exception => e
106         @backtrace = e.backtrace
107         raise e
108       end
109     end
110     begin
111       Watchful.public_class_watchful_method(:a1, :a2) ; fail
112     rescue Exception => e
113       e.backtrace.should == @backtrace
114     end
115     aspect.unadvise
116   end
117 end
118 
119 describe Advice, "#invoke_original_join_point that raises an exception" do
120   class InvokeOriginalJoinPointRaisingException
121     class IOJPRException < Exception; end
122     def raise_exception *args
123       raise IOJPRException.new(":raise_exception called with args: #{args.inspect}")
124     end
125     def self.class_raise_exception *args
126       raise IOJPRException.new(":class_raise_exception called with args: #{args.inspect}")
127     end
128   end
129   
130   it "should add the kind of advice to the exception message." do
131     aspect = Aspect.new :before, 
132     :pointcut => {:type => InvokeOriginalJoinPointRaisingException, :methods => :raise_exception} do |jp, obj, *args| 
133       jp.invoke_original_join_point
134     end
135     begin
136       InvokeOriginalJoinPointRaisingException.new.raise_exception(:a1, :a2) ; fail
137     rescue InvokeOriginalJoinPointRaisingException::IOJPRException => e
138       e.message.should include("\"before\" advice")
139     end
140     aspect.unadvise
141   end
142 
143   it "should add the \"Class#method\" of the advised object's type and method to the exception message." do
144     aspect = Aspect.new :before, 
145       :pointcut => {:type => InvokeOriginalJoinPointRaisingException, :methods => :raise_exception} do |jp, obj, *args| 
146         jp.invoke_original_join_point
147     end
148     begin
149       InvokeOriginalJoinPointRaisingException.new.raise_exception(:a1, :a2) ; fail
150     rescue InvokeOriginalJoinPointRaisingException::IOJPRException => e
151       e.message.should include("InvokeOriginalJoinPointRaisingException#raise_exception")
152     end
153     aspect.unadvise
154   end
155 
156   it "should add the \"Class.method\" of the advised type's class method to the exception message." do
157     aspect = Aspect.new :before, 
158       :pointcut => {:type => InvokeOriginalJoinPointRaisingException, :methods => :class_raise_exception, 
159       :method_options => [:class]} do |jp, obj, *args| 
160         jp.invoke_original_join_point
161     end
162     begin
163       InvokeOriginalJoinPointRaisingException.class_raise_exception(:a1, :a2) ; fail
164     rescue InvokeOriginalJoinPointRaisingException::IOJPRException => e
165       e.message.should include("InvokeOriginalJoinPointRaisingException.class_raise_exception")
166     end
167     aspect.unadvise
168   end
169 
170   it "should rethrow an exception of the same type as the original exception." do
171     aspect = Aspect.new :before, 
172       :pointcut => {:type => InvokeOriginalJoinPointRaisingException, :methods => :class_raise_exception, 
173       :method_options => [:class]} do |jp, obj, *args| 
174         jp.invoke_original_join_point
175     end
176     lambda { InvokeOriginalJoinPointRaisingException.class_raise_exception :a1, :a2 }.should raise_error(InvokeOriginalJoinPointRaisingException::IOJPRException)
177     aspect.unadvise
178   end
179 
180   it "should rethrow an exception with the same backtrace as the original exception." do
181     @backtrace = nil
182     aspect = Aspect.new :before, 
183       :pointcut => {:type => InvokeOriginalJoinPointRaisingException, :methods => :class_raise_exception, 
184       :method_options => [:class]} do |jp, obj, *args| 
185       begin
186         jp.invoke_original_join_point
187       rescue Exception => e
188         @backtrace = e.backtrace
189         raise e
190       end
191     end
192     begin
193       InvokeOriginalJoinPointRaisingException.class_raise_exception(:a1, :a2) ; fail
194     rescue Exception => e
195       e.backtrace.should == @backtrace
196     end
197     aspect.unadvise
198   end
199 end
200 
201 describe Advice, ".compare_advice_kinds with nil or UNKNOWN_ADVICE_KIND" do
202   it "should return 0 when comparing nil to nil" do
203     Advice.compare_advice_kinds(nil, nil).should == 0
204   end
205   it "should return 0 when comparing UNKNOWN_ADVICE_KIND to UNKNOWN_ADVICE_KIND" do
206     Advice.compare_advice_kinds(Advice::UNKNOWN_ADVICE_KIND, Advice::UNKNOWN_ADVICE_KIND).should == 0
207   end
208   it "should return 1 when comparing UNKNOWN_ADVICE_KIND to nil" do
209     Advice.compare_advice_kinds(Advice::UNKNOWN_ADVICE_KIND, nil).should == 1
210   end
211   it "should return -1 when comparing nil to UNKNOWN_ADVICE_KIND" do
212     Advice.compare_advice_kinds(nil, Advice::UNKNOWN_ADVICE_KIND).should == -1
213   end
214 
215   Advice::KINDS_IN_PRIORITY_ORDER.each do |kind|
216     it "should return 1 when comparing :#{kind} to UNKNOWN_ADVICE_KIND" do
217       Advice.compare_advice_kinds(kind, Advice::UNKNOWN_ADVICE_KIND).should == 1
218     end
219   end
220   Advice::KINDS_IN_PRIORITY_ORDER.each do |kind|
221     it "should return -1 when comparing UNKNOWN_ADVICE_KIND to :#{kind}" do
222       Advice.compare_advice_kinds(Advice::UNKNOWN_ADVICE_KIND, kind).should == -1
223     end
224   end
225 end
226   
227 describe Advice, ".compare_advice_kinds between 'real' advice kinds" do
228   Advice::KINDS_IN_PRIORITY_ORDER.each do |kind1|
229     Advice::KINDS_IN_PRIORITY_ORDER.each do |kind2|
230       expected = Advice::KINDS_IN_PRIORITY_ORDER.index(kind1) <=> Advice::KINDS_IN_PRIORITY_ORDER.index(kind2)
231       it "should return #{expected} when comparing :#{kind1} to :#{kind2} (using priority order)" do
232         Advice.compare_advice_kinds(kind1, kind2).should == expected
233       end
234     end
235   end
236 end
237 
238 describe AdviceChainNodeFactory, "#make_node" do
239   it "should raise if an unknown advice kind is specified" do
240     lambda {AdviceChainNodeFactory.make_node :advice_kind => :foo}.should raise_error(Aquarium::Utils::InvalidOptions)    
241   end
242 
243   it "should return a node of the type corresponding to the input advice kind" do
244     AdviceChainNodeFactory.make_node(:advice_kind => :no).kind_of?(NoAdviceChainNode).should be_true
245     AdviceChainNodeFactory.make_node(:advice_kind => :none).kind_of?(NoAdviceChainNode).should be_true
246     AdviceChainNodeFactory.make_node(:advice_kind => :before).kind_of?(BeforeAdviceChainNode).should be_true
247     AdviceChainNodeFactory.make_node(:advice_kind => :after).kind_of?(AfterAdviceChainNode).should be_true
248     AdviceChainNodeFactory.make_node(:advice_kind => :after_raising).kind_of?(AfterRaisingAdviceChainNode).should be_true
249     AdviceChainNodeFactory.make_node(:advice_kind => :after_returning).kind_of?(AfterReturningAdviceChainNode).should be_true
250     AdviceChainNodeFactory.make_node(:advice_kind => :around).kind_of?(AroundAdviceChainNode).should be_true
251   end
252 end
253 

Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.

Valid XHTML 1.0! Valid CSS!