module ErdHandler
describe Erd do
- let(:input) { double('input').as_null_object }
- let(:output) { double('output').as_null_object }
- let(:erd) { Erd.new(input) }
- describe "#initialize" do
- it "creates an empty ERD" do
+ describe '#initialize' do
+ it 'creates an empty ERD' do
erd = Erd.new
erd.mark.should be_nil
erd.should have(0).vertices
erd.should have(0).edges
end
- it "reads and creates a single box" do
- erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml"))
+ it 'reads and creates a single box' do
+ erd = Erd.new(File.new('spec/fixtures/single_box_erd.xml'))
erd.mark.should == 6.5
erd.should have(1).vertices
erd.should have(0).edges
end
end # #initialize
- describe "#read" do
- it "reads and creates a single box" do
+ describe '#read' do
+ it 'reads and creates a single box' do
erd = Erd.new
- erd.read(File.new("spec/fixtures/single_box_erd.xml"))
+ erd.read(File.new('spec/fixtures/single_box_erd.xml'))
erd.mark.should == 6.5
erd.should have(1).vertices
erd.should have(0).edges
end
- it "reads and creates two boxes with an edge joining them" do
+ it 'reads and creates two boxes with an edge joining them' do
erd = Erd.new
- erd.read(File.new("spec/fixtures/two_boxes_one_link_erd.xml"))
+ erd.read(File.new('spec/fixtures/two_boxes_one_link_erd.xml'))
erd.mark.should == 4.5
erd.should have(2).vertices
erd.should have(1).edges
link.connection_at(b1).crowsfoot.should be(:no)
end
- it "reads and creates a box with a self-loop" do
+ it 'reads and creates a box with a self-loop' do
erd = Erd.new
- erd.read(File.new("spec/fixtures/single_box_self_loop_erd.xml"))
+ erd.read(File.new('spec/fixtures/single_box_self_loop_erd.xml'))
erd.mark.should == 4.5
erd.should have(1).vertices
erd.should have(1).edges
c1.should_not == c2
end
- it "reads and creates an ERD with subclassing" do
+ it 'reads and creates an ERD with subclassing' do
erd = Erd.new
- erd.read(File.new("spec/fixtures/two_boxes_one_contained_erd.xml"))
+ erd.read(File.new('spec/fixtures/two_boxes_one_contained_erd.xml'))
erd.mark.should == 4.5
erd.should have(2).vertices
erd.should have(0).edges
erd.vertices[1].should be_contains(erd.vertices[0])
end
- it "reads and creates full diagram" do
+ it 'reads and creates full diagram' do
erd = Erd.new
- erd.read(File.new("spec/fixtures/complex_erd.xml"))
+ erd.read(File.new('spec/fixtures/complex_erd.xml'))
erd.mark.should == 4.0
erd.should have(5).vertices
erd.should have(6).edges
b0 = erd.vertices.find {|b| b.id == 0}
- b0.name.original.should == "Unit"
+ b0.name.original.should == 'Unit'
b0.should have(2).neighbours
b1 = erd.vertices.find {|b| b.id == 1}
- b1.name.original.should == "Employee"
+ b1.name.original.should == 'Employee'
b1.should have(2).neighbours
b2 = erd.vertices.find {|b| b.id == 2}
- b2.name.original.should == "Course"
+ b2.name.original.should == 'Course'
b2.should have(3).neighbours
b3 = erd.vertices.find {|b| b.id == 3}
- b3.name.original.should == "Presentation"
+ b3.name.original.should == 'Presentation'
b3.should have(3).neighbours
b4 = erd.vertices.find {|b| b.id == 4}
- b4.name.original.should == "Client"
+ b4.name.original.should == 'Client'
b4.should have(1).neighbours
l0 = erd.edges.find {|e| e.id == 0}
- l0.name.original.should == "ConsistsOf"
+ l0.name.original.should == 'ConsistsOf'
l0.connections.find {|c| c.end == b0}.blob.should be :closed
l0.connections.find {|c| c.end == b0}.crowsfoot.should be :yes
l0.connections.find {|c| c.end == b2}.blob.should be :closed
l0.connections.find {|c| c.end == b2}.crowsfoot.should be :no
l1 = erd.edges.find {|e| e.id == 1}
- l1.name.original.should == "Prepares"
+ l1.name.original.should == 'Prepares'
l1.connections.find {|c| c.end == b0}.blob.should be :open
l1.connections.find {|c| c.end == b0}.crowsfoot.should be :yes
l1.connections.find {|c| c.end == b1}.blob.should be :closed
l1.connections.find {|c| c.end == b1}.crowsfoot.should be :no
l2 = erd.edges.find {|e| e.id == 2}
- l2.name.original.should == "Presents"
+ l2.name.original.should == 'Presents'
l2.connections.find {|c| c.end == b1}.blob.should be :closed
l2.connections.find {|c| c.end == b1}.crowsfoot.should be :no
l2.connections.find {|c| c.end == b3}.blob.should be :closed
l2.connections.find {|c| c.end == b3}.crowsfoot.should be :yes
l3 = erd.edges.find {|e| e.id == 3}
- l3.name.original.should == "Presented"
+ l3.name.original.should == 'Presented'
l3.connections.find {|c| c.end == b2}.blob.should be :open
l3.connections.find {|c| c.end == b2}.crowsfoot.should be :no
l3.connections.find {|c| c.end == b3}.blob.should be :closed
l3.connections.find {|c| c.end == b3}.crowsfoot.should be :yes
l4 = erd.edges.find {|e| e.id == 4}
- l4.name.original.should == "Recieves"
+ l4.name.original.should == 'Recieves'
l4.connections.find {|c| c.end == b3}.blob.should be :closed
l4.connections.find {|c| c.end == b3}.crowsfoot.should be :yes
l4.connections.find {|c| c.end == b4}.blob.should be :closed
l4.connections.find {|c| c.end == b4}.crowsfoot.should be :no
l5 = erd.edges.find {|e| e.id == 5}
- l5.name.original.should == "IsPrerequisiteOf"
+ l5.name.original.should == 'IsPrerequisiteOf'
l5.connections.find {|c| c.crowsfoot == :yes}.blob.should be :open
l5.connections.find {|c| c.crowsfoot == :no}.blob.should be :open
l5.connections.find {|c| c.crowsfoot == :yes}.end.should be b2
end
end # #read
- describe "#mmus" do
- it "finds three MMUs in a simple ERD" do
+ describe '#mmus' do
+ it 'finds three MMUs in a simple ERD' do
erd = Erd.new
- erd.read(File.new("spec/fixtures/two_boxes_one_link_erd.xml"))
+ erd.read(File.new('spec/fixtures/two_boxes_one_link_erd.xml'))
mmus = erd.mmus
mmus.should have(3).items
end
end
- it "finds many MMUs in a complex ERD" do
+ it 'finds many MMUs in a complex ERD' do
erd = Erd.new
- erd.read(File.new("spec/fixtures/complex_erd.xml"))
+ erd.read(File.new('spec/fixtures/complex_erd.xml'))
mmus = erd.mmus
mmus.should have(11).items
module ErdHandler
describe Label do
describe '#initialize' do
- it "should give an error if not given an original string" do
+ it 'should give an error if not given an original string' do
# Label.new.should raise_error(ArgumentError)
expect {Label.new}.to raise_error(ArgumentError)
end
- it "should create a copy of the original as the processed string" do
- test_label = "Test label"
+ it 'should create a copy of the original as the processed string' do
+ test_label = 'Test label'
l1 = Label.new test_label
l1.original.should == test_label
end
- it "should tidy the processed string if asked" do
- test_label = "testingLabeller string, he_pontificated"
+ it 'should tidy the processed string if asked' do
+ test_label = 'testingLabeller string, he_pontificated'
l1 = Label.new test_label.dup, true
l2 = Label.new test_label.dup
l2.split.downcase.stem
end # initialze
describe '#original' do
- it "reports the string it was initialised with" do
- test_label = "Test label"
+ it 'reports the string it was initialised with' do
+ test_label = 'Test label'
l1 = Label.new test_label
l1.original.should == test_label
#l1 = Label.new
- #l1.original.should == ""
+ #l1.original.should == ''
end
end # original
describe '#processed' do
- it "reports the original if no processing has been done" do
- test_label = "Test label"
+ it 'reports the original if no processing has been done' do
+ test_label = 'Test label'
l1 = Label.new test_label
l1.processed.should == [test_label]
l1.original.should == test_label
end # processed
describe '#split' do
- it "splits the original on the specified regexp" do
- l1 = Label.new "Test label"
+ it 'splits the original on the specified regexp' do
+ l1 = Label.new 'Test label'
l1.split(/ /)
- l1.processed.should == ["Test", "label"]
- l1.original.should == "Test label"
+ l1.processed.should == ['Test', 'label']
+ l1.original.should == 'Test label'
- l1 = Label.new "Test_label"
+ l1 = Label.new 'Test_label'
l1.split(/_/)
- l1.processed.should == ["Test", "label"]
+ l1.processed.should == ['Test', 'label']
- l1 = Label.new "Test label_string"
+ l1 = Label.new 'Test label_string'
l1.split(/[ _]/)
- l1.processed.should == ["Test", "label", "string"]
+ l1.processed.should == ['Test', 'label', 'string']
end
- it "splits the original on camel case" do
- l1 = Label.new "TestLabel"
+ it 'splits the original on camel case' do
+ l1 = Label.new 'TestLabel'
l1.split :camel_case => true
- l1.processed.should == ["Test", "Label"]
- l1.original.should == "TestLabel"
+ l1.processed.should == ['Test', 'Label']
+ l1.original.should == 'TestLabel'
- l2 = Label.new "testLabel"
+ l2 = Label.new 'testLabel'
l2.split :camel_case => true
- l2.processed.should == ["test", "Label"]
- l2.original.should == "testLabel"
+ l2.processed.should == ['test', 'Label']
+ l2.original.should == 'testLabel'
end
- it "doesn't split the original on camel case if asked not to" do
- l1 = Label.new "TestLabel"
+ it 'does not split the original on camel case if asked not to' do
+ l1 = Label.new 'TestLabel'
l1.split :camel_case => false
- l1.processed.should == ["TestLabel"]
- l1.original.should == "TestLabel"
+ l1.processed.should == ['TestLabel']
+ l1.original.should == 'TestLabel'
- l2 = Label.new "TestLabel"
+ l2 = Label.new 'TestLabel'
l2.split :camel_case => nil
- l2.processed.should == ["TestLabel"]
- l2.original.should == "TestLabel"
+ l2.processed.should == ['TestLabel']
+ l2.original.should == 'TestLabel'
end
- it "splits the original on numbers" do
- l1 = Label.new "Test123Label"
+ it 'splits the original on numbers' do
+ l1 = Label.new 'Test123Label'
l1.split :numbers => true
- l1.processed.should == ["Test", "123", "Label"]
- l1.original.should == "Test123Label"
+ l1.processed.should == ['Test', '123', 'Label']
+ l1.original.should == 'Test123Label'
- l2 = Label.new "test1label"
+ l2 = Label.new 'test1label'
l2.split :numbers => true
- l2.processed.should == ["test", "1", "label"]
- l2.original.should == "test1label"
+ l2.processed.should == ['test', '1', 'label']
+ l2.original.should == 'test1label'
end
- it "doesn't split the original on numbers if asked not to" do
- l1 = Label.new "Test123Label"
+ it 'does not split the original on numbers if asked not to' do
+ l1 = Label.new 'Test123Label'
l1.split :numbers => false
- l1.processed.should == ["Test123Label"]
- l1.original.should == "Test123Label"
+ l1.processed.should == ['Test123Label']
+ l1.original.should == 'Test123Label'
- l2 = Label.new "Test123Label"
+ l2 = Label.new 'Test123Label'
l2.split :numbers => nil
- l2.processed.should == ["Test123Label"]
- l2.original.should == "Test123Label"
+ l2.processed.should == ['Test123Label']
+ l2.original.should == 'Test123Label'
end
- it "splits the original using a default regexp" do
+ it 'splits the original using a default regexp' do
l1 = Label.new "Test label_string\tfred"
l1.split
- l1.processed.should == ["Test", "label", "string", "fred"]
+ l1.processed.should == ['Test', 'label', 'string', 'fred']
end
- it "splits the original on camel case by default" do
- l1 = Label.new "TestLabel"
+ it 'splits the original on camel case by default' do
+ l1 = Label.new 'TestLabel'
l1.split
- l1.processed.should == ["Test", "Label"]
- l1.original.should == "TestLabel"
+ l1.processed.should == ['Test', 'Label']
+ l1.original.should == 'TestLabel'
end
- it "splits the original on numbers by default" do
- l1 = Label.new "Test123Label"
+ it 'splits the original on numbers by default' do
+ l1 = Label.new 'Test123Label'
l1.split
- l1.processed.should == ["Test", "123", "Label"]
- l1.original.should == "Test123Label"
+ l1.processed.should == ['Test', '123', 'Label']
+ l1.original.should == 'Test123Label'
end
- it "splits the original on punctuation, whitespace, camel case, and numbers by default" do
- l1 = Label.new "TestLabel is_split, 123 he,said456Fred"
+ it 'splits the original on punctuation, whitespace, camel case, and numbers by default' do
+ l1 = Label.new 'TestLabel is_split, 123 he,said456Fred'
l1.split
- l1.processed.should == ["Test", "Label", "is", "split","123", "he", "said", "456", "Fred"]
- l1.original.should == "TestLabel is_split, 123 he,said456Fred"
+ l1.processed.should == ['Test', 'Label', 'is', 'split','123', 'he', 'said', '456', 'Fred']
+ l1.original.should == 'TestLabel is_split, 123 he,said456Fred'
end
- it "is idempotent" do
- l1 = Label.new "TestLabel is_split, 123 he,said456Fred"
+ it 'is idempotent' do
+ l1 = Label.new 'TestLabel is_split, 123 he,said456Fred'
res1 = l1.split.dup
res2 = l1.split
res1.processed.should == res2.processed
- l1.original.should == "TestLabel is_split, 123 he,said456Fred"
+ l1.original.should == 'TestLabel is_split, 123 he,said456Fred'
end
end # split
- describe "#downcase" do
- it "downcases all parts of the processed label" do
- l1 = Label.new "Test label_string"
+ describe '#downcase' do
+ it 'downcases all parts of the processed label' do
+ l1 = Label.new 'Test label_string'
l1.split.downcase
- l1.processed.should == ["test", "label", "string"]
+ l1.processed.should == ['test', 'label', 'string']
end
end # downcase
- describe "#stem" do
- it "stems all parts of the processed label" do
- l1 = Label.new "testing labeller string pontificated"
+ describe '#stem' do
+ it 'stems all parts of the processed label' do
+ l1 = Label.new 'testing labeller string pontificated'
l1.split.stem
- l1.processed.should == ["test", "label", "string", "pontif"]
+ l1.processed.should == ['test', 'label', 'string', 'pontif']
end
end # stem
- describe "#tidy" do
- it "tidies a label" do
- l1 = Label.new "testingLabeller string, he_pontificated"
+ describe '#tidy' do
+ it 'tidies a label' do
+ l1 = Label.new 'testingLabeller string, he_pontificated'
l2 = Label.new l1.original
l1.tidy
l2.split.downcase.stem
end
end # tidy
- describe "#length" do
- it "returns the length of the processed label" do
- l1 = Label.new "testingLabeller string, he_pontificated"
+ describe '#length' do
+ it 'returns the length of the processed label' do
+ l1 = Label.new 'testingLabeller string, he_pontificated'
l1.tidy
l1.length.should == l1.processed.join('').length
end
end # length
- describe "#levenshtein" do
- it "calculates the Levenshtein distance of the processed string" do
- l1 = Label.new "Fred"
- l1.levenshtein("Fred").should == 0
- l1.levenshtein("Free").should == 1
- l1.levenshtein("").should == 4
- l2 = Label.new ""
- l2.levenshtein("Free").should == 4
- l2.levenshtein("").should == 0
- l3 = Label.new "meilenstein"
- l3.levenshtein("levenshtein").should == 4
- l4 = Label.new "testingLabeller string, he_pontificated"
- l4.tidy.levenshtein("testlabelstringhepontif").should == 0
- l4.tidy.levenshtein("testlabelXstringhepontif").should == 1
+ describe '#levenshtein' do
+ it 'calculates the Levenshtein distance of the processed string' do
+ l1 = Label.new 'Fred'
+ l1.levenshtein('Fred').should == 0
+ l1.levenshtein('Free').should == 1
+ l1.levenshtein('').should == 4
+ l2 = Label.new ''
+ l2.levenshtein('Free').should == 4
+ l2.levenshtein('').should == 0
+ l3 = Label.new 'meilenstein'
+ l3.levenshtein('levenshtein').should == 4
+ l4 = Label.new 'testingLabeller string, he_pontificated'
+ l4.tidy.levenshtein('testlabelstringhepontif').should == 0
+ l4.tidy.levenshtein('testlabelXstringhepontif').should == 1
end
- it "calculates the Levenshtein distance between Labels" do
- l1 = Label.new "meilenstein"
- l2 = Label.new "levenshtein"
+ it 'calculates the Levenshtein distance between Labels' do
+ l1 = Label.new 'meilenstein'
+ l2 = Label.new 'levenshtein'
l1.levenshtein(l2).should == 4
end
end