summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-08 12:18:42 -0600
committerLuke Kanies <luke@madstop.com>2007-11-08 12:18:42 -0600
commitdfe774f55e98db085d8f5729a4b1229513c6c2b0 (patch)
tree39915f08eff31c0d6f690e05b7ebb3f594338536 /spec/unit
parentf465e7e96d62f9b18bdebd51319582d5b2ffa332 (diff)
downloadpuppet-dfe774f55e98db085d8f5729a4b1229513c6c2b0.tar.gz
puppet-dfe774f55e98db085d8f5729a4b1229513c6c2b0.tar.xz
puppet-dfe774f55e98db085d8f5729a4b1229513c6c2b0.zip
Switching the base class for the Relationship class.
It was previously using the GRATR::Edge class, which had wonky overrides that dramatically slowed down sorting (its hash mechanism hashed the source and target so that edges with the same source/target got the same hash, which we actually don't want any more). This shouldn't change any functionality, just performance. I didn't retain all functionality from the Edge class, but a lot of that functionality was, um, horrible, like Edge[] being equivalent to Edge.new.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/other/pgraph.rb8
-rwxr-xr-xspec/unit/relationship.rb149
2 files changed, 154 insertions, 3 deletions
diff --git a/spec/unit/other/pgraph.rb b/spec/unit/other/pgraph.rb
index 9446a8371..41835ebc7 100755
--- a/spec/unit/other/pgraph.rb
+++ b/spec/unit/other/pgraph.rb
@@ -50,8 +50,8 @@ describe Puppet::PGraph, " when matching edges" do
@none = Puppet::Event.new(:source => "a", :event => :NONE)
@edges = {}
- @edges["a/b"] = Puppet::Relationship["a", "b", {:event => :yay, :callback => :refresh}]
- @edges["a/c"] = Puppet::Relationship["a", "c", {:event => :yay, :callback => :refresh}]
+ @edges["a/b"] = Puppet::Relationship.new("a", "b", {:event => :yay, :callback => :refresh})
+ @edges["a/c"] = Puppet::Relationship.new("a", "c", {:event => :yay, :callback => :refresh})
@graph.add_edge!(@edges["a/b"])
end
@@ -65,7 +65,9 @@ describe Puppet::PGraph, " when matching edges" do
it "should match multiple edges" do
@graph.add_edge!(@edges["a/c"])
- @graph.matching_edges([@event]).sort.should == [@edges["a/b"], @edges["a/c"]].sort
+ edges = @graph.matching_edges([@event])
+ edges.should be_include(@edges["a/b"])
+ edges.should be_include(@edges["a/c"])
end
end
diff --git a/spec/unit/relationship.rb b/spec/unit/relationship.rb
new file mode 100755
index 000000000..5d90a9349
--- /dev/null
+++ b/spec/unit/relationship.rb
@@ -0,0 +1,149 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-11-1.
+# Copyright (c) 2006. All rights reserved.
+
+require File.dirname(__FILE__) + '/../spec_helper'
+require 'puppet/relationship'
+
+describe Puppet::Relationship do
+ before do
+ @edge = Puppet::Relationship.new(:a, :b)
+ end
+
+ it "should have a :source attribute" do
+ @edge.should respond_to(:source)
+ end
+
+ it "should have a :target attribute" do
+ @edge.should respond_to(:target)
+ end
+
+ it "should have a :label attribute" do
+ @edge.should respond_to(:label)
+ end
+
+ it "should provide a :ref method that describes the edge" do
+ @edge = Puppet::Relationship.new(stub("a", :ref => "a"), stub("b", :ref => "b"))
+ @edge.ref.should == "a => b"
+ end
+end
+
+describe Puppet::Relationship, " when initializing" do
+ before do
+ @edge = Puppet::Relationship.new(:a, :b, :testing => :foo)
+ end
+
+ it "should use the first argument as the source" do
+ @edge.source.should == :a
+ end
+
+ it "should use the second argument as the target" do
+ @edge.target.should == :b
+ end
+
+ it "should use the third argument as the label" do
+ @edge.label.should == {:testing => :foo}
+ end
+
+ it "should require a callback if a non-NONE event is specified" do
+ proc { Puppet::Relationship.new(:a, :b, :event => :something) }.should raise_error(ArgumentError)
+ end
+
+ it "should require the label to be a hash" do
+ proc { Puppet::Relationship.new(:a, :b, :event) }.should raise_error(ArgumentError)
+ end
+end
+
+describe Puppet::Relationship, " when interpreting the label" do
+ it "should default to an event of nil" do
+ @edge = Puppet::Relationship.new(:a, :b)
+ @edge.event.should be_nil
+ end
+
+ it "should expose a provided event via the :event method" do
+ @edge = Puppet::Relationship.new(:a, :b, :event => :something, :callback => :whatever)
+ @edge.event.should == :something
+ end
+
+ it "should default to a nil callback" do
+ @edge = Puppet::Relationship.new(:a, :b)
+ @edge.callback.should be_nil
+ end
+
+ it "should expose a provided callback via the :callback method" do
+ @edge = Puppet::Relationship.new(:a, :b, :callback => :testing)
+ @edge.callback.should == :testing
+ end
+end
+
+describe Puppet::Relationship, " when matching edges with no specified event" do
+ before do
+ @edge = Puppet::Relationship.new(:a, :b)
+ end
+
+ it "should not match :NONE" do
+ @edge.should_not be_match(:NONE)
+ end
+
+ it "should not match :ALL_EVENTS" do
+ @edge.should_not be_match(:NONE)
+ end
+
+ it "should not match any other events" do
+ @edge.should_not be_match(:whatever)
+ end
+end
+
+describe Puppet::Relationship, " when matching edges with :NONE as the event" do
+ before do
+ @edge = Puppet::Relationship.new(:a, :b, :event => :NONE)
+ end
+ it "should not match :NONE" do
+ @edge.should_not be_match(:NONE)
+ end
+
+ it "should not match :ALL_EVENTS" do
+ @edge.should_not be_match(:ALL_EVENTS)
+ end
+
+ it "should not match other events" do
+ @edge.should_not be_match(:yayness)
+ end
+end
+
+describe Puppet::Relationship, " when matching edges with :ALL as the event" do
+ before do
+ @edge = Puppet::Relationship.new(:a, :b, :event => :ALL_EVENTS, :callback => :whatever)
+ end
+
+ it "should not match :NONE" do
+ @edge.should_not be_match(:NONE)
+ end
+
+ it "should match :ALL_EVENTS" do
+ @edge.should be_match(:ALLEVENTS)
+ end
+
+ it "should match all other events" do
+ @edge.should be_match(:foo)
+ end
+end
+
+describe Puppet::Relationship, " when matching edges with a non-standard event" do
+ before do
+ @edge = Puppet::Relationship.new(:a, :b, :event => :random, :callback => :whatever)
+ end
+
+ it "should not match :NONE" do
+ @edge.should_not be_match(:NONE)
+ end
+
+ it "should not match :ALL_EVENTS" do
+ @edge.should_not be_match(:ALL_EVENTS)
+ end
+
+ it "should match events with the same name" do
+ @edge.should be_match(:random)
+ end
+end