summaryrefslogtreecommitdiff
path: root/spec/unit/recipe_spec.rb
diff options
context:
space:
mode:
authorAdam Jacob <adam@hjksolutions.com>2008-03-06 22:13:01 -0800
committerAdam Jacob <adam@hjksolutions.com>2008-03-06 22:13:01 -0800
commitaca232ba638afdc45f6d5b3e9b3f68d4a149d0a5 (patch)
tree63dd4c3b55ebd5ca95c5ec16a751d48c36c84a04 /spec/unit/recipe_spec.rb
parentb5117775e86cff40399187b6292c98fba9dc5034 (diff)
downloadchef-aca232ba638afdc45f6d5b3e9b3f68d4a149d0a5.tar.gz
Marionette does graphs, and can eval on the fly to resources
Diffstat (limited to 'spec/unit/recipe_spec.rb')
-rw-r--r--spec/unit/recipe_spec.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
new file mode 100644
index 0000000000..66c6095ffc
--- /dev/null
+++ b/spec/unit/recipe_spec.rb
@@ -0,0 +1,95 @@
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: GNU General Public License version 2 or later
+#
+# This program and entire repository is free software; you can
+# redistribute it and/or modify it under the terms of the GNU
+# General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+require File.join(File.dirname(__FILE__), "..", "spec_helper")
+
+class Marionette
+ class Resource
+ class ZenMaster < Marionette::Resource
+ attr_reader :peace
+
+ def initialize(name, dg)
+ @resource_name = :zen_master
+ super(name, dg)
+ end
+
+ def peace=(tf)
+ @peace = tf
+ end
+ end
+ end
+end
+
+
+describe Marionette::Recipe do
+ before(:each) do
+ @recipe = Marionette::Recipe.new("hjk", "test", "node")
+ end
+
+ it "should load our zen_master resource" do
+ lambda do
+ @recipe.zen_master "monkey" do
+ peace = true
+ end
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "should add our zen_master as a vertex" do
+ @recipe.zen_master "monkey" do
+ peace = true
+ end
+ @recipe.dg.each_vertex do |v|
+ next if v == :top
+ v.should be_kind_of(Marionette::Resource::ZenMaster)
+ end
+ end
+
+ it "should graph our zen masters in the order they appear" do
+ %w{monkey dog cat}.each do |name|
+ @recipe.zen_master name do
+ peace = true
+ end
+ end
+ index = 0
+ @recipe.dg.topsort_iterator do |v|
+ case v
+ when :top
+ index.should eql(0)
+ when v.name == "monkey"
+ index.should eql(1)
+ when v.name == "dog"
+ index.should eql(2)
+ when v.name == "cat"
+ index.should eql(3)
+ end
+ index += 1
+ end
+ end
+
+ it "should handle an instance_eval properly" do
+ code = <<-CODE
+zen_master "gnome" do
+ peace = true
+end
+CODE
+ lambda { @recipe.instance_eval(code) }.should_not raise_error
+ @recipe.resource(:zen_master => "gnome").name.should eql("gnome")
+ end
+
+end \ No newline at end of file