C0 code coverage information
Generated on Sun Oct 26 11:18:16 -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 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'aquarium/utils/type_utils'
3 require 'aquarium/utils/type_utils_sample_classes'
4 require 'aquarium/utils/type_utils_sample_nested_types'
5
6 include Aquarium::Utils
7
8 describe TypeUtils, ".is_type?" do
9 it "should be true for a class" do
10 TypeUtils.is_type?(String).should be_true
11 end
12
13 it "should be true for a Module" do
14 TypeUtils.is_type?(Kernel).should be_true
15 end
16
17 it "should be false for an Object" do
18 TypeUtils.is_type?("Object").should be_false
19 end
20 end
21
22 # We don't compare the sizes, because RSpec will add some classes that we don't care about...
23 def check_descendent_array clazz, expected
24 actual = TypeUtils.descendents(clazz)
25 expected.each {|c| actual.should include(c)}
26 end
27
28 describe TypeUtils, ".descendents called with a class" do
29 it "should return the class itself in the result" do
30 TypeUtils.descendents(BaseForDescendents).should include(BaseForDescendents)
31 end
32
33 it "should return just the class if it has no descendents" do
34 TypeUtils.descendents(D11ForDescendents).should eql([D11ForDescendents])
35 TypeUtils.descendents(D2ForDescendents).should eql([D2ForDescendents])
36 TypeUtils.descendents(Aquarium::ForDescendents::NestedD11ForDescendents).should eql([Aquarium::ForDescendents::NestedD11ForDescendents])
37 TypeUtils.descendents(Aquarium::ForDescendents::NestedD2ForDescendents).should eql([Aquarium::ForDescendents::NestedD2ForDescendents])
38 TypeUtils.descendents(Aquarium::ForDescendents::NestedD3ForDescendents).should eql([Aquarium::ForDescendents::NestedD3ForDescendents])
39 TypeUtils.descendents(Aquarium::ForDescendents::NestedD4ForDescendents).should eql([Aquarium::ForDescendents::NestedD4ForDescendents])
40 TypeUtils.descendents(Aquarium::ForDescendents::NestedD31ForDescendents).should eql([Aquarium::ForDescendents::NestedD31ForDescendents])
41 end
42
43 TypeUtils.sample_classes.each do |t|
44 it "should return all classes and their descendents that derive from #{t}" do
45 check_descendent_array t, TypeUtils.sample_classes_descendents[t]
46 end
47 end
48 end
49
50 describe TypeUtils, ".descendents called with a module" do
51 it "should return the module itself in the result" do
52 TypeUtils.descendents(ModuleForDescendents).should include(ModuleForDescendents)
53 TypeUtils.descendents(Aquarium::ForDescendents::NestedModuleForDescendents).should include(Aquarium::ForDescendents::NestedModuleForDescendents)
54 end
55
56 it "should return all classes and their descendents that include a module" do
57 TypeUtils.sample_modules.each do |t|
58 check_descendent_array t, TypeUtils.sample_modules_descendents[t]
59 end
60 end
61
62 it "should return all modules that include a module" do
63 TypeUtils.descendents(ModuleForDescendents).should include(ModuleForDescendents)
64 TypeUtils.descendents(ModuleForDescendents).should include(Aquarium::ForDescendents::Nested2ModuleForDescendents)
65 end
66 end
67
68 module FakeJRubyWrapperModule
69 %w[ancestors constants const_get].each do |method_name|
70 module_eval(<<-EOF, __FILE__, __LINE__)
71 def self.__#{method_name}__(*args)
72 self.#{method_name}(*args)
73 end
74 EOF
75 end
76 end
77 class FakeJRubyWrapperClass
78 include FakeJRubyWrapperModule
79 end
80
81 # See the separate JRuby spec suite for exhaustive tests of JRuby support. This example really exists solely to ensure 100% coverage.
82 describe TypeUtils, ".descendents applied to JRuby-wrapped Java classes" do
83 it "should properly determine descendents" do
84 TypeUtils.descendents(FakeJRubyWrapperModule).should include(FakeJRubyWrapperClass)
85 end
86 end
87
88 describe TypeUtils, ".nested called with a type" do
89 it "should return the type itself in the result" do
90 Aquarium::NestedTestTypes.nested_in_NestedTestTypes.keys.each do |t|
91 TypeUtils.nested(t).should include(t)
92 end
93 end
94
95 it "should return all the modules and classes nested under the type, inclusive" do
96 Aquarium::NestedTestTypes.nested_in_NestedTestTypes.keys.each do |t|
97 actual_types = TypeUtils.nested(t)
98 actual_types.sort{|x,y| x.name <=> y.name}.should == Aquarium::NestedTestTypes.nested_in_NestedTestTypes[t].sort{|x,y| x.name <=> y.name}
99 end
100 end
101 end
102
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.