C0 code coverage information

Generated on Sun Jul 06 22:30:58 +0900 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/plugins_spec.rb 164 131
100.0%  
100.0%  
  1 #!/usr/bin/env ruby
  2 require File.dirname(__FILE__) + '/spec_helper.rb'
  3 
  4 include Citrus
  5 
  6 describe Plugins, "load plugins" do
  7 	before :all do
  8 		@plugins_dir = Pathname.tempname
  9 		@plugins_dir.mkpath
 10 
 11 		@foobarrb = @plugins_dir + "foobar.rb"
 12 		@foobarrb.open("w") do |f|
 13 			f << <<-EOF
 14 				class Foobar
 15 					def initialize(a, b)
 16 						@a, @b = a, b
 17 					end
 18 				end
 19 			EOF
 20 		end
 21 
 22 		@barbazrb = @plugins_dir + "barbaz.rb"
 23 		@barbazrb.open("w") do |f|
 24 			f << <<-EOF
 25 				class Barbaz
 26 					def initialize(a, b)
 27 						@a, @b = a, b
 28 					end
 29 				end
 30 			EOF
 31 		end
 32 
 33 		@plugins = Plugins.new(@plugins_dir)
 34 	end
 35 
 36 	it "should search all plugins" do
 37 		@plugins.plugin_names.should == ["Foobar", "Barbaz"]
 38 		info = @plugins.instance_variable_get(:@plugins)
 39 		info["Foobar"][:file].should == @foobarrb
 40 		info["Barbaz"][:file].should == @barbazrb
 41 	end
 42 
 43 	it "should load plugin correctly" do
 44 		instance = @plugins.load("Foobar", "a", "b")
 45 		instance.class.name.should match(/Foobar$/)
 46 
 47 		@plugins.loaded_plugin_names.should == ["Foobar"]
 48 		instance.instance_variable_get(:@a).should == "a"
 49 		instance.instance_variable_get(:@b).should == "b"
 50 
 51 		instance = @plugins["Foobar"]
 52 		instance.instance_variable_get(:@a).should == "a"
 53 		instance.instance_variable_get(:@b).should == "b"
 54 	end
 55 
 56 	it "should be able to reload plugins" do
 57 		@foobarrb.open("w") do |f|
 58 			f << <<-EOF
 59 				class Foobar
 60 					def initialize(a, b)
 61 						@c, @d = a, b
 62 					end
 63 				end
 64 			EOF
 65 		end
 66 		instance = @plugins.reload("Foobar", "a", "b")
 67 		instance.instance_variable_get(:@c).should == "a"
 68 		instance.instance_variable_get(:@d).should == "b"
 69 
 70 		instance = @plugins["Foobar"]
 71 		instance.instance_variable_get(:@c).should == "a"
 72 		instance.instance_variable_get(:@d).should == "b"
 73 	end
 74 
 75 	it "should be able to reload all modified plugins" do
 76 		@plugins.load("Foobar", "a", "b")
 77 		@plugins.load("Barbaz", "a", "b")
 78 
 79 		info = @plugins.instance_variable_get(:@plugins)
 80 		prev_Foobar_time = info["Foobar"][:time]
 81 		prev_Barbaz_time = info["Barbaz"][:time]
 82 
 83 		@foobarrb.utime(Time.now + 1, Time.now + 1)
 84 		@barbazrb.utime(Time.now + 1, Time.now + 1)
 85 
 86 		instances = @plugins.reload(:all, "a", "b")
 87 		instances["Foobar"].should be_a_kind_of(info["Foobar"][:class])
 88 		instances["Barbaz"].should be_a_kind_of(info["Barbaz"][:class])
 89 		instances["Barbaz"].instance_variable_get(:@a).should == "a"
 90 		instances["Barbaz"].instance_variable_get(:@b).should == "b"
 91 
 92 		info["Foobar"][:time].should_not == prev_Foobar_time
 93 		info["Barbaz"][:time].should_not == prev_Barbaz_time
 94 
 95 		@foobarrb.utime(Time.now + 2, Time.now + 2)
 96 		instances = @plugins.reload(:all, "a", "b")
 97 		instances["Foobar"].should be_a_kind_of(info["Foobar"][:class])
 98 	end
 99 
100 	it "should have loaded_plugins method" do
101 		@plugins.load("Foobar", "a", "b")
102 		@plugins.load("Barbaz", "a", "b")
103 		info = @plugins.instance_variable_get(:@plugins)
104 
105 		res = @plugins.loaded_plugins
106 		res.should have_key("Foobar")
107 		res.should have_key("Barbaz")
108 		res["Foobar"].should be_a_kind_of(info["Foobar"][:class])
109 		res["Barbaz"].should be_a_kind_of(info["Barbaz"][:class])
110 	end
111 
112 	it "can iterate" do
113 		@plugins.load("Foobar", "a", "b")
114 		@plugins.load("Barbaz", "a", "b")
115 		info = @plugins.instance_variable_get(:@plugins)
116 
117 		@plugins.each do |name, instance|
118 			instance.should be_a_kind_of(info[name][:class])
119 		end
120 	end
121 
122 	it "should be call on_load/on_unload event correctly" do
123 		@foobarrb.open("w") do |f|
124 			f << <<-EOF
125 				class Foobar
126 					def initialize(a, b)
127 						@a, @b = a, b
128 					end
129 
130 					def on_load
131 						@on_load = true
132 					end
133 
134 					def on_unload
135 						@on_unload = true
136 					end
137 				end
138 			EOF
139 		end
140 		instance1 = @plugins.reload("Foobar", "a", "b")
141 		instance1.instance_variable_get(:@a).should  == "a"
142 		instance1.instance_variable_get(:@on_load).should be_true
143 
144 		@plugins.unload("Foobar")
145 
146 		instance1.instance_variable_get(:@on_unload).should be_true
147 
148 		instance2 = @plugins.load("Foobar", "b", "b")
149 		instance2.instance_variable_get(:@a).should  == "b"
150 		instance2.instance_variable_get(:@on_load).should be_true
151 
152 		instance3 = @plugins.reload("Foobar", "c", "b")
153 		instance3.instance_variable_get(:@on_load).should be_true
154 		instance3.instance_variable_get(:@a).should  == "c"
155 
156 		instance2.instance_variable_get(:@on_unload).should be_true
157 	end
158 
159 	after :all do
160 		@plugins_dir.rmtree
161 	end
162 end
163 
164 

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

Valid XHTML 1.0! Valid CSS!