Abstracting Services In Ruby C0 Coverage Information - RCov

spec/xml_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/xml_spec.rb 144 128
100.00%
100.00%

Key

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.

Coverage Details

1 require File.expand_path('../spec_helper', __FILE__)
2 require 'asir/coder/xml'
3 
4 describe "ASIR::Coder::XML" do
5   before(:each) do 
6     @enc = ASIR::Coder::XML.new
7     @dec = @enc.dup
8   end
9 
10   basic_objs = [ ]
11 
12   [
13    nil,
14    true,
15    false,
16   ].each do | x |
17     basic_objs << x
18     it "should handle #{x.inspect}" do
19       xml = @enc.encode(x)
20       xml.should == "<#{x.class.name} />"
21       @dec.decode(xml).should == x
22     end
23   end
24 
25   [
26    1234,
27    1.234,
28   ].each do | x |
29     basic_objs << x
30     it "should handle #{x.inspect}" do
31       xml = @enc.encode(x)
32       xml.should == "<#{x.class.name} v=\"#{x.to_s}\" />"
33       @dec.decode(xml).should == x
34     end
35   end
36 
37   [
38    :symbol,
39   ].each do | x |
40     basic_objs << x
41     it "should handle #{x.inspect}" do
42       xml = @enc.encode(x)
43       xml.should == "<#{x.class.name} >#{x.to_s}</#{x.class.name}>"
44       @dec.decode(xml).should == x
45     end
46   end
47 
48   [
49    'String',
50   ].each do | x |
51     basic_objs << x
52     it "should handle #{x.inspect}" do
53       xml = @enc.encode(x)
54       xml.should == "<#{x.class.name} id=\"1\" >#{x.to_s}</#{x.class.name}>"
55       @dec.decode(xml).should == x
56     end
57   end
58 
59   it "should handle empty Array" do
60     x = [ ]
61     xml = @enc.encode(x)
62     xml.should == "<#{x.class.name} id=\"1\" ></#{x.class.name}>"
63     @dec.decode(xml).should == x
64   end
65 
66   it "should handle Array" do
67     x = [ *basic_objs ]
68     xml = @enc.encode(x)
69     xml.should =~ %r{\A<#{x.class.name} id=\"1\" ><NilClass /><TrueClass /><FalseClass /><Fixnum v="1234" /><Float v="1.234" /><Symbol >symbol</Symbol><String id=\"[^"]+\" >String</String></#{x.class.name}>\Z} # " emacs
70     @dec.decode(xml).should == x
71   end
72 
73   it "should handle empty Hash" do
74     x = { }
75     xml = @enc.encode(x)
76     xml.should == "<#{x.class.name} id=\"1\" ></#{x.class.name}>"
77     @dec.decode(xml).should == x
78   end
79 
80   it "should handle Hash" do
81     x = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
82     xml = @enc.encode(x)
83     xml.should =~ %r{\A<#{x.class.name} id=\"1\" >}
84     xml.should =~ %r{</#{x.class.name}>\Z}
85     basic_objs.each do | v |
86       vx = @enc.dup.encode(v)
87       vx = vx.gsub(/id="[^"]+"/, 'id="\d+"')
88       xml.should =~ Regexp.new(vx)
89       xml.should =~ %r{ >#{v.inspect}</String>}
90     end
91     @dec.decode(xml).should == x
92   end
93 
94   class ASIR::Coder::XML::Test
95     attr_accessor :a, :h, :o
96   end
97 
98   it "should handle deep objects" do
99     x = ASIR::Coder::XML::Test.new
100     x.a = [ *basic_objs ]
101     x.h = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
102     x.o = ASIR::Coder::XML::Test.new
103     x.o.a = 123
104     xml = @enc.encode(x)
105     xml.should =~ %r{<#{x.class.name.gsub('::', '.')} id=\"1\" >}
106     xml.should =~ %r{</#{x.class.name.gsub('::', '.')}>}
107     y = @dec.decode(xml)
108     y.a.should == x.a
109     y.h.should == x.h
110     y.o.class.should == ASIR::Coder::XML::Test
111     y.o.a.should == x.o.a
112     x.instance_variables.sort { |a, b| a.to_s <=> b.to_s}.should == 
113       y.instance_variables.sort { | a, b | a.to_s <=> b.to_s }
114   end
115 
116   it "should handle multiple references to same objects." do
117     x = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
118     y = [ 1, 2 ]
119     x = [ x, x, y, y ]
120     xml = @enc.encode(x)
121     y = @dec.decode(xml)
122     y[0].object_id.should == y[1].object_id
123     y[2].object_id.should == y[3].object_id
124   end
125 
126   it "should handle self-referencing Array." do
127     x = [ 1 ]
128     x << x
129     xml = @enc.encode(x)
130     y = @dec.decode(xml)
131     y[0].should == x[0]
132     y[1].object_id.should == y.object_id
133   end
134 
135   it "should handle self-referencing Hash." do
136     x = { :a => 1 }
137     x[:self] = x
138     xml = @enc.encode(x)
139     y = @dec.decode(xml)
140     y[:a].should == x[:a]
141     y[:self].object_id.should == y.object_id
142   end
143 
144 end

Generated on Fri Jan 27 17:37:46 -0600 2012 with rcov 0.9.8