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 full diagram" do
76 erd
.read(File
.new("spec/fixtures/complex_erd.xml"))
77 erd
.mark
.should
== 4.0
78 erd
.should
have(5).vertices
79 erd
.should
have(6).edges
81 b0
= erd
.vertices
.find
{|b
| b
.id
== 0}
82 b0
.name
.original
.should
== "Unit"
83 b0
.should
have(2).neighbours
85 b1
= erd
.vertices
.find
{|b
| b
.id
== 1}
86 b1
.name
.original
.should
== "Employee"
87 b1
.should
have(2).neighbours
89 b2
= erd
.vertices
.find
{|b
| b
.id
== 2}
90 b2
.name
.original
.should
== "Course"
91 b2
.should
have(3).neighbours
93 b3
= erd
.vertices
.find
{|b
| b
.id
== 3}
94 b3
.name
.original
.should
== "Presentation"
95 b3
.should
have(3).neighbours
97 b4
= erd
.vertices
.find
{|b
| b
.id
== 4}
98 b4
.name
.original
.should
== "Client"
99 b4
.should
have(1).neighbours
101 l0
= erd
.edges
.find
{|e
| e
.id
== 0}
102 l0
.name
.original
.should
== "ConsistsOf"
103 l0
.connections
.find
{|c
| c
.end == b0
}.blob
.should be
:closed
104 l0
.connections
.find
{|c
| c
.end == b0
}.crowsfoot
.should be
:yes
105 l0
.connections
.find
{|c
| c
.end == b2
}.blob
.should be
:closed
106 l0
.connections
.find
{|c
| c
.end == b2
}.crowsfoot
.should be
:no
108 l1
= erd
.edges
.find
{|e
| e
.id
== 1}
109 l1
.name
.original
.should
== "Prepares"
110 l1
.connections
.find
{|c
| c
.end == b0
}.blob
.should be
:open
111 l1
.connections
.find
{|c
| c
.end == b0
}.crowsfoot
.should be
:yes
112 l1
.connections
.find
{|c
| c
.end == b1
}.blob
.should be
:closed
113 l1
.connections
.find
{|c
| c
.end == b1
}.crowsfoot
.should be
:no
115 l2
= erd
.edges
.find
{|e
| e
.id
== 2}
116 l2
.name
.original
.should
== "Presents"
117 l2
.connections
.find
{|c
| c
.end == b1
}.blob
.should be
:closed
118 l2
.connections
.find
{|c
| c
.end == b1
}.crowsfoot
.should be
:no
119 l2
.connections
.find
{|c
| c
.end == b3
}.blob
.should be
:closed
120 l2
.connections
.find
{|c
| c
.end == b3
}.crowsfoot
.should be
:yes
122 l3
= erd
.edges
.find
{|e
| e
.id
== 3}
123 l3
.name
.original
.should
== "Presented"
124 l3
.connections
.find
{|c
| c
.end == b2
}.blob
.should be
:open
125 l3
.connections
.find
{|c
| c
.end == b2
}.crowsfoot
.should be
:no
126 l3
.connections
.find
{|c
| c
.end == b3
}.blob
.should be
:closed
127 l3
.connections
.find
{|c
| c
.end == b3
}.crowsfoot
.should be
:yes
129 l4
= erd
.edges
.find
{|e
| e
.id
== 4}
130 l4
.name
.original
.should
== "Recieves"
131 l4
.connections
.find
{|c
| c
.end == b3
}.blob
.should be
:closed
132 l4
.connections
.find
{|c
| c
.end == b3
}.crowsfoot
.should be
:yes
133 l4
.connections
.find
{|c
| c
.end == b4
}.blob
.should be
:closed
134 l4
.connections
.find
{|c
| c
.end == b4
}.crowsfoot
.should be
:no
136 l5
= erd
.edges
.find
{|e
| e
.id
== 5}
137 l5
.name
.original
.should
== "IsPrerequisiteOf"
138 l5
.connections
.find
{|c
| c
.crowsfoot
== :yes}.blob
.should be
:open
139 l5
.connections
.find
{|c
| c
.crowsfoot
== :no}.blob
.should be
:open
140 l5
.connections
.find
{|c
| c
.crowsfoot
== :yes}.end.should be b2
141 l5
.connections
.find
{|c
| c
.crowsfoot
== :no}.end.should be b2
146 it
"finds three MMUs in a simple ERD" do
148 erd
.read(File
.new("spec/fixtures/two_boxes_one_link_erd.xml"))
151 mmus
.should
have(3).items
152 single_box_mmus
= mmus
.select
{|m
| m
.vertices
.length
== 1}
153 single_link_mmus
= mmus
.select
{|m
| m
.edges
.length
== 1}
155 single_box_mmus
.should
have(2).items
156 single_box_mmus
.each
do |m
|
157 m
.should
have(1).vertices
158 m
.should
have(0).edges
161 single_link_mmus
.should
have(1).items
162 single_link_mmus
.each
do |m
|
163 m
.should
have(2).vertices
164 m
.should
have(1).edges
165 m
.edges
.first
.should
have(2).connections
166 m
.vertices
.each
do |v
|
167 m
.vertices
.should
include(v
)
172 it
"finds many MMUs in a complex ERD" do
174 erd
.read(File
.new("spec/fixtures/complex_erd.xml"))
177 mmus
.should
have(11).items
178 single_box_mmus
= mmus
.select
{|m
| m
.vertices
.length
== 1}
179 single_link_mmus
= mmus
.select
{|m
| m
.edges
.length
== 1}
181 single_box_mmus
.should
have(5).items
182 single_box_mmus
.each
do |m
|
183 m
.should
have(1).vertices
184 m
.should
have(0).edges
186 single_box_mmus
.map
{|m
| m
.vertices
.first
.name
.original
}.uniq
.should
have(5).items
188 single_link_mmus
.should
have(6).items
189 single_link_mmus
.each
do |m
|
190 m
.should
have(2).vertices
191 m
.should
have(1).edges
192 m
.edges
.first
.should
have(2).connections
193 m
.vertices
.each
do |v
|
194 m
.vertices
.should
include(v
)
197 single_link_mmus
.map
{|m
| m
.edges
.first
.name
.original
}.uniq
.should
have(6).items