77d7ad2b42dbf19531a3684ea4a41cb23fbbcb31
5 let(:input) { double('input').as_null_object
}
6 let(:output) { double('output').as_null_object
}
7 let(:erd) { Erd
.new(input
, output
) }
9 describe
"#initialize" do
10 it
"creates an empty ERD" do
12 erd
.mark
.should be_nil
13 erd
.should
have(0).vertices
14 erd
.should
have(0).edges
17 it
"reads and creates a single box" do
18 erd
= Erd
.new(File
.new("spec/fixtures/single_box_erd.xml"))
19 erd
.mark
.should
== 6.5
20 erd
.should
have(1).vertices
21 erd
.should
have(0).edges
26 it
"reads and creates a single box" do
28 erd
.read(File
.new("spec/fixtures/single_box_erd.xml"))
29 erd
.mark
.should
== 6.5
30 erd
.should
have(1).vertices
31 erd
.should
have(0).edges
34 it
"reads and creates two boxes with an edge joining them" do
36 erd
.read(File
.new("spec/fixtures/two_boxes_one_link_erd.xml"))
37 erd
.mark
.should
== 4.5
38 erd
.should
have(2).vertices
39 erd
.should
have(1).edges
41 erd
.vertices
[0].should
have(1).neighbours
42 erd
.vertices
[1].should
have(1).neighbours
43 erd
.vertices
[0].neighbours
.should
include(erd
.vertices
[1])
44 erd
.vertices
[1].neighbours
.should
include(erd
.vertices
[0])
47 b0
= erd
.vertices
.find
{|v
| v
.id
== 0}
48 b1
= erd
.vertices
.find
{|v
| v
.id
== 1}
49 link
.connection_at(b0
).blob
.should
be(:closed)
50 link
.connection_at(b0
).crowsfoot
.should
be(:yes)
51 link
.connection_at(b1
).blob
.should
be(:open)
52 link
.connection_at(b1
).crowsfoot
.should
be(:no)
55 it
"reads and creates a box with a self-loop" do
57 erd
.read(File
.new("spec/fixtures/single_box_self_loop_erd.xml"))
58 erd
.mark
.should
== 4.5
59 erd
.should
have(1).vertices
60 erd
.should
have(1).edges
62 erd
.vertices
[0].should
have(1).neighbours
63 erd
.vertices
[0].neighbours
.should
include(erd
.vertices
[0])
67 c1
= link
.connections
.find
{|c
| c
.blob
== :closed}
68 c1
.crowsfoot
.should
be(:yes)
69 c2
= link
.connections
.find
{|c
| c
.blob
== :open}
70 c2
.crowsfoot
.should
be(:no)
74 it
"reads and creates an ERD with subclassing" do
76 erd
.read(File
.new("spec/fixtures/two_boxes_one_contained_erd.xml"))
77 erd
.mark
.should
== 4.5
78 erd
.should
have(2).vertices
79 erd
.should
have(0).edges
81 erd
.vertices
[0].should
have(0).neighbours
82 erd
.vertices
[1].should
have(0).neighbours
84 erd
.vertices
[0].within
?(erd
.vertices
[1]).should
be(true)
85 erd
.vertices
[1].should
be_contains(erd
.vertices
[0])
88 it
"reads and creates full diagram" do
90 erd
.read(File
.new("spec/fixtures/complex_erd.xml"))
91 erd
.mark
.should
== 4.0
92 erd
.should
have(5).vertices
93 erd
.should
have(6).edges
95 b0
= erd
.vertices
.find
{|b
| b
.id
== 0}
96 b0
.name
.original
.should
== "Unit"
97 b0
.should
have(2).neighbours
99 b1
= erd
.vertices
.find
{|b
| b
.id
== 1}
100 b1
.name
.original
.should
== "Employee"
101 b1
.should
have(2).neighbours
103 b2
= erd
.vertices
.find
{|b
| b
.id
== 2}
104 b2
.name
.original
.should
== "Course"
105 b2
.should
have(3).neighbours
107 b3
= erd
.vertices
.find
{|b
| b
.id
== 3}
108 b3
.name
.original
.should
== "Presentation"
109 b3
.should
have(3).neighbours
111 b4
= erd
.vertices
.find
{|b
| b
.id
== 4}
112 b4
.name
.original
.should
== "Client"
113 b4
.should
have(1).neighbours
115 l0
= erd
.edges
.find
{|e
| e
.id
== 0}
116 l0
.name
.original
.should
== "ConsistsOf"
117 l0
.connections
.find
{|c
| c
.end == b0
}.blob
.should be
:closed
118 l0
.connections
.find
{|c
| c
.end == b0
}.crowsfoot
.should be
:yes
119 l0
.connections
.find
{|c
| c
.end == b2
}.blob
.should be
:closed
120 l0
.connections
.find
{|c
| c
.end == b2
}.crowsfoot
.should be
:no
122 l1
= erd
.edges
.find
{|e
| e
.id
== 1}
123 l1
.name
.original
.should
== "Prepares"
124 l1
.connections
.find
{|c
| c
.end == b0
}.blob
.should be
:open
125 l1
.connections
.find
{|c
| c
.end == b0
}.crowsfoot
.should be
:yes
126 l1
.connections
.find
{|c
| c
.end == b1
}.blob
.should be
:closed
127 l1
.connections
.find
{|c
| c
.end == b1
}.crowsfoot
.should be
:no
129 l2
= erd
.edges
.find
{|e
| e
.id
== 2}
130 l2
.name
.original
.should
== "Presents"
131 l2
.connections
.find
{|c
| c
.end == b1
}.blob
.should be
:closed
132 l2
.connections
.find
{|c
| c
.end == b1
}.crowsfoot
.should be
:no
133 l2
.connections
.find
{|c
| c
.end == b3
}.blob
.should be
:closed
134 l2
.connections
.find
{|c
| c
.end == b3
}.crowsfoot
.should be
:yes
136 l3
= erd
.edges
.find
{|e
| e
.id
== 3}
137 l3
.name
.original
.should
== "Presented"
138 l3
.connections
.find
{|c
| c
.end == b2
}.blob
.should be
:open
139 l3
.connections
.find
{|c
| c
.end == b2
}.crowsfoot
.should be
:no
140 l3
.connections
.find
{|c
| c
.end == b3
}.blob
.should be
:closed
141 l3
.connections
.find
{|c
| c
.end == b3
}.crowsfoot
.should be
:yes
143 l4
= erd
.edges
.find
{|e
| e
.id
== 4}
144 l4
.name
.original
.should
== "Recieves"
145 l4
.connections
.find
{|c
| c
.end == b3
}.blob
.should be
:closed
146 l4
.connections
.find
{|c
| c
.end == b3
}.crowsfoot
.should be
:yes
147 l4
.connections
.find
{|c
| c
.end == b4
}.blob
.should be
:closed
148 l4
.connections
.find
{|c
| c
.end == b4
}.crowsfoot
.should be
:no
150 l5
= erd
.edges
.find
{|e
| e
.id
== 5}
151 l5
.name
.original
.should
== "IsPrerequisiteOf"
152 l5
.connections
.find
{|c
| c
.crowsfoot
== :yes}.blob
.should be
:open
153 l5
.connections
.find
{|c
| c
.crowsfoot
== :no}.blob
.should be
:open
154 l5
.connections
.find
{|c
| c
.crowsfoot
== :yes}.end.should be b2
155 l5
.connections
.find
{|c
| c
.crowsfoot
== :no}.end.should be b2
160 it
"finds three MMUs in a simple ERD" do
162 erd
.read(File
.new("spec/fixtures/two_boxes_one_link_erd.xml"))
165 mmus
.should
have(3).items
166 single_box_mmus
= mmus
.select
{|m
| m
.vertices
.length
== 1}
167 single_link_mmus
= mmus
.select
{|m
| m
.edges
.length
== 1}
169 single_box_mmus
.should
have(2).items
170 single_box_mmus
.each
do |m
|
171 m
.should
have(1).vertices
172 m
.should
have(0).edges
175 single_link_mmus
.should
have(1).items
176 single_link_mmus
.each
do |m
|
177 m
.should
have(2).vertices
178 m
.should
have(1).edges
179 m
.edges
.first
.should
have(2).connections
180 m
.vertices
.each
do |v
|
181 m
.vertices
.should
include(v
)
186 it
"finds many MMUs in a complex ERD" do
188 erd
.read(File
.new("spec/fixtures/complex_erd.xml"))
191 mmus
.should
have(11).items
192 single_box_mmus
= mmus
.select
{|m
| m
.vertices
.length
== 1}
193 single_link_mmus
= mmus
.select
{|m
| m
.edges
.length
== 1}
195 single_box_mmus
.should
have(5).items
196 single_box_mmus
.each
do |m
|
197 m
.should
have(1).vertices
198 m
.should
have(0).edges
200 single_box_mmus
.map
{|m
| m
.vertices
.first
.name
.original
}.uniq
.should
have(5).items
202 single_link_mmus
.should
have(6).items
203 single_link_mmus
.each
do |m
|
204 m
.should
have(2).vertices
205 m
.should
have(1).edges
206 m
.edges
.first
.should
have(2).connections
207 m
.vertices
.each
do |v
|
208 m
.vertices
.should
include(v
)
211 single_link_mmus
.map
{|m
| m
.edges
.first
.name
.original
}.uniq
.should
have(6).items