Permalink
Browse files

Correct tests and use raise as opposed to throw

  • Loading branch information...
1 parent ff05413 commit 9e634da368aa78cad3f23fdfb4e1264c9d549922 @D4L committed Aug 15, 2012
View
1 lib/abstract_graph/composition/vertex.rb
@@ -10,6 +10,7 @@ class Vertex
def name=(name)
raise ArgumentError if name.class != String
+ raise Exception if @@names.include? name
@@names.delete @name
@name = name
@@names.push name
View
2 lib/abstract_graph/composition/vertex/initialize.rb
@@ -7,7 +7,7 @@ class Vertex
def initialize (name="", value="")
@name = name
if @@names.include? name
- throw Exception
+ raise Exception
end
@@names.push name
end
View
6 spec/abstract_graph/composition/vertex/initialize_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe AbstractGraph::Composition::Vertex do
-
+
before :each do
AbstractGraph::Composition::Vertex.class_variable_set :@@names, []
end
@@ -28,6 +28,10 @@
@vertex.should_not be_nil
end
+ it "doesn't allow two vertices to be named the same" do
+ expect { AbstractGraph::Composition::Vertex.new("v1") }.to raise_error
+ end
+
end
describe "#new(String, Object)" do
View
7 spec/abstract_graph/composition/vertex/name_spec.rb
@@ -40,7 +40,8 @@
it "doesn't allow two objects to have the same name" do
@vertex.name = "v1"
- expect { AbstractGraph::Composition::Vertex.new("v1") }.to raise_error
+ vertex2 = AbstractGraph::Composition::Vertex.new("v2")
+ expect { vertex2.name = "v1" }.to raise_error
end
it "can change a name of a vertex to free up the name" do
@@ -52,5 +53,9 @@
end
end
+ it "can assign a name after delete removes it" do
+ pending "delete method"
+ end
+
end
end
View
1 spec/abstract_graph/composition/vertex/value_spec.rb
@@ -2,7 +2,6 @@
describe AbstractGraph::Composition::Vertex do
describe "#value" do
-
end
describe "#value=" do

0 comments on commit 9e634da

Please sign in to comment.