summaryrefslogtreecommitdiff
path: root/chef/spec
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-10-19 15:58:41 -0700
committerdanielsdeleo <dan@opscode.com>2012-10-19 15:58:41 -0700
commitd90433ae23ec93dc9e9804c721911462c7a1b331 (patch)
treebc594753736164e616ec0c1c587bde42b6893627 /chef/spec
parentd489549de16f15660c600dc100f22084194feeca (diff)
parent3fe49d7751a0194790b887708b28ca31d7046053 (diff)
downloadchef-d90433ae23ec93dc9e9804c721911462c7a1b331.tar.gz
Merge branch 'CHEF-2992'
Diffstat (limited to 'chef/spec')
-rw-r--r--chef/spec/spec_helper.rb1
-rw-r--r--chef/spec/unit/cookbook_spec.rb19
-rw-r--r--chef/spec/unit/dsl/data_query_spec.rb66
-rw-r--r--chef/spec/unit/dsl/platfrom_introspection_spec.rb (renamed from chef/spec/unit/mixin/language_spec.rb)143
-rw-r--r--chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb2
-rw-r--r--chef/spec/unit/node_spec.rb112
-rw-r--r--chef/spec/unit/provider/package/apt_spec.rb1
-rw-r--r--chef/spec/unit/provider/package/ips_spec.rb1
-rw-r--r--chef/spec/unit/recipe_spec.rb4
-rw-r--r--chef/spec/unit/run_context_spec.rb18
10 files changed, 173 insertions, 194 deletions
diff --git a/chef/spec/spec_helper.rb b/chef/spec/spec_helper.rb
index 2e0bca0b0c..1d101022ac 100644
--- a/chef/spec/spec_helper.rb
+++ b/chef/spec/spec_helper.rb
@@ -38,6 +38,7 @@ require 'chef'
require 'chef/knife'
Chef::Knife.load_commands
require 'chef/mixins'
+require 'chef/dsl'
require 'chef/application'
require 'chef/applications'
diff --git a/chef/spec/unit/cookbook_spec.rb b/chef/spec/unit/cookbook_spec.rb
index e494e81124..c28a5c7a2a 100644
--- a/chef/spec/unit/cookbook_spec.rb
+++ b/chef/spec/unit/cookbook_spec.rb
@@ -68,20 +68,6 @@ describe Chef::CookbookVersion do
@cookbook.preferred_filename(@node, :files, 'a-filename', 'the-checksum').should be_nil
end
-# TODO: timh, cw: 5/20/2010: removed CookbookVersion.recipe? as it's not used; see cookbook.rb
-# it "should allow you to test for a recipe with recipe?" do
-# @cookbook.recipe_filenames = [ "one", "two" ]
-# @cookbook.recipe?("one").should eql(true)
-# @cookbook.recipe?("shanghai").should eql(false)
-# end
-
-# TODO: timh, cw: 5/20/2010: removed CookbookVersion.recipe? as it's not used; see cookbook.rb
-# it "should allow you to test for a recipe? with a fq recipe name" do
-# @cookbook.recipe_filenames = [ "one", "two" ]
-# @cookbook.recipe?("openldap::one").should eql(true)
-# @cookbook.recipe?("shanghai::city").should eql(false)
-# end
-
it "should allow you to include a fully-qualified recipe using the DSL" do
# DSL method include_recipe allows multiple arguments, so extract the first
recipe = @run_context.include_recipe("openldap::gigantor").first
@@ -95,9 +81,4 @@ describe Chef::CookbookVersion do
lambda { @cookbook.load_recipe("doesnt_exist", @node) }.should raise_error(ArgumentError)
end
- it "should allow you to load an attribute file by name via load_attribute" do
- @node.include_attribute("openldap::smokey")
- @node.smokey.should == "robinson"
- end
-
end
diff --git a/chef/spec/unit/dsl/data_query_spec.rb b/chef/spec/unit/dsl/data_query_spec.rb
new file mode 100644
index 0000000000..8960ad9957
--- /dev/null
+++ b/chef/spec/unit/dsl/data_query_spec.rb
@@ -0,0 +1,66 @@
+#
+# Author:: Seth Falcon (<seth@opscode.com>)
+# Copyright:: Copyright (c) 2010 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+require 'chef/dsl/data_query'
+
+class DataQueryDSLTester
+ include Chef::DSL::DataQuery
+end
+
+describe Chef::DSL::DataQuery do
+ before(:each) do
+ @language = DataQueryDSLTester.new
+ @node = Hash.new
+ @language.stub!(:node).and_return(@node)
+ end
+
+ describe "when loading data bags and items" do
+ it "lists the items in a data bag" do
+ Chef::DataBag.should_receive(:load).with("bag_name").and_return("item_1" => "http://url_for/item_1", "item_2" => "http://url_for/item_2")
+ @language.data_bag("bag_name").sort.should == %w[item_1 item_2]
+ end
+
+ it "validates the name of the data bag you're trying to load" do
+ lambda {@language.data_bag("!# %^&& ")}.should raise_error(Chef::Exceptions::InvalidDataBagName)
+ end
+
+ it "fetches a data bag item" do
+ @item = Chef::DataBagItem.new
+ @item.data_bag("bag_name")
+ @item.raw_data = {"id" => "item_name", "FUU" => "FUU"}
+ Chef::DataBagItem.should_receive(:load).with("bag_name", "item_name").and_return(@item)
+ @language.data_bag_item("bag_name", "item_name").should == @item
+ end
+
+ it "validates the name of the data bag you're trying to load an item from" do
+ lambda {@language.data_bag_item(" %%^& ", "item_name")}.should raise_error(Chef::Exceptions::InvalidDataBagName)
+ end
+
+ it "validates the id of the data bag item you're trying to load" do
+ lambda {@language.data_bag_item("bag_name", " 987 (*&()")}.should raise_error(Chef::Exceptions::InvalidDataBagItemID)
+ end
+
+ it "validates that the id of the data bag item is not nil" do
+ lambda {@language.data_bag_item("bag_name", nil)}.should raise_error(Chef::Exceptions::InvalidDataBagItemID)
+ end
+
+ end
+
+end
+
diff --git a/chef/spec/unit/mixin/language_spec.rb b/chef/spec/unit/dsl/platfrom_introspection_spec.rb
index 42f6b6bbe3..e6cc7ad9ff 100644
--- a/chef/spec/unit/mixin/language_spec.rb
+++ b/chef/spec/unit/dsl/platfrom_introspection_spec.rb
@@ -17,13 +17,13 @@
#
require 'spec_helper'
-require 'chef/mixin/language'
+require 'chef/dsl/platform_introspection'
class LanguageTester
- include Chef::Mixin::Language
+ include Chef::DSL::PlatformIntrospection
end
-describe Chef::Mixin::Language do
+describe Chef::DSL::PlatformIntrospection do
before(:each) do
@language = LanguageTester.new
@node = Hash.new
@@ -35,13 +35,13 @@ describe Chef::Mixin::Language do
"1.2.3" => "#{x}-1.2.3"
}
end
- @platform_hash["debian"] = {["5", "6"] => "debian-5/6", "default" => "debian"}
+ @platform_hash["debian"] = {["5", "6"] => "debian-5/6", "default" => "debian"}
@platform_hash["default"] = "default"
- @platform_family_hash = {
- "debian" => "debian value",
- [:rhel, :fedora] => "redhatty value",
- "suse" => "suse value",
+ @platform_family_hash = {
+ "debian" => "debian value",
+ [:rhel, :fedora] => "redhatty value",
+ "suse" => "suse value",
:default => "default value"
}
end
@@ -51,28 +51,28 @@ describe Chef::Mixin::Language do
@language.value_for_platform(@platform_hash).should == "default"
end
- it "returns a default value when there is no known platform family" do
- @language.value_for_platform_family(@platform_family_hash).should == "default value"
+ it "returns a default value when there is no known platform family" do
+ @language.value_for_platform_family(@platform_family_hash).should == "default value"
end
-
+
it "returns a default value when the current platform doesn't match" do
@node[:platform] = "not-a-known-platform"
@language.value_for_platform(@platform_hash).should == "default"
end
- it "returns a default value when current platform_family doesn't match" do
+ it "returns a default value when current platform_family doesn't match" do
@node[:platform_family] = "ultra-derived-linux"
- @language.value_for_platform_family(@platform_family_hash).should == "default value"
+ @language.value_for_platform_family(@platform_family_hash).should == "default value"
end
-
+
it "returns a value based on the current platform" do
@node[:platform] = "openbsd"
@language.value_for_platform(@platform_hash).should == "openbsd"
end
- it "returns a value based on the current platform family" do
+ it "returns a value based on the current platform family" do
@node[:platform_family] = "debian"
- @language.value_for_platform_family(@platform_family_hash).should == "debian value"
+ @language.value_for_platform_family(@platform_family_hash).should == "debian value"
end
it "returns a version-specific value based on the current platform" do
@@ -101,52 +101,52 @@ describe Chef::Mixin::Language do
end
end
- describe "when checking platform?" do
+ describe "when checking platform?" do
before(:each) do
@language = LanguageTester.new
@node = Hash.new
@language.stub!(:node).and_return(@node)
end
-
- it "returns true if the node is a provided platform and platforms are provided as symbols" do
+
+ it "returns true if the node is a provided platform and platforms are provided as symbols" do
@node[:platform] = 'ubuntu'
@language.platform?([:redhat, :ubuntu]).should == true
end
-
- it "returns true if the node is a provided platform and platforms are provided as strings" do
+
+ it "returns true if the node is a provided platform and platforms are provided as strings" do
@node[:platform] = 'ubuntu'
@language.platform?(["redhat", "ubuntu"]).should == true
end
-
- it "returns false if the node is not of the provided platforms" do
+
+ it "returns false if the node is not of the provided platforms" do
@node[:platform] = 'ubuntu'
@language.platform?(:splatlinux).should == false
end
end
-
- describe "when checking platform_family?" do
+
+ describe "when checking platform_family?" do
before(:each) do
@language = LanguageTester.new
@node = Hash.new
@language.stub!(:node).and_return(@node)
end
-
- it "returns true if the node is in a provided platform family and families are provided as symbols" do
+
+ it "returns true if the node is in a provided platform family and families are provided as symbols" do
@node[:platform_family] = 'debian'
@language.platform_family?([:rhel, :debian]).should == true
end
-
- it "returns true if the node is a provided platform and platforms are provided as strings" do
+
+ it "returns true if the node is a provided platform and platforms are provided as strings" do
@node[:platform_family] = 'rhel'
@language.platform_family?(["rhel", "debian"]).should == true
end
-
- it "returns false if the node is not of the provided platforms" do
+
+ it "returns false if the node is not of the provided platforms" do
@node[:platform_family] = 'suse'
@language.platform_family?(:splatlinux).should == false
end
-
- it "returns false if the node is not of the provided platforms and platform_family is not set" do
+
+ it "returns false if the node is not of the provided platforms and platform_family is not set" do
@language.platform_family?(:splatlinux).should == false
end
@@ -173,44 +173,12 @@ describe Chef::Mixin::Language do
@node[:platform] = "debian"
@node[:platform_version] = '4.0'
@language.value_for_platform(@platform_hash).should == [:restart, :reload]
- end
- end
-
- describe "when loading data bags and items" do
- it "lists the items in a data bag" do
- Chef::DataBag.should_receive(:load).with("bag_name").and_return("item_1" => "http://url_for/item_1", "item_2" => "http://url_for/item_2")
- @language.data_bag("bag_name").sort.should == %w[item_1 item_2]
- end
-
- it "validates the name of the data bag you're trying to load" do
- lambda {@language.data_bag("!# %^&& ")}.should raise_error(Chef::Exceptions::InvalidDataBagName)
end
-
- it "fetches a data bag item" do
- @item = Chef::DataBagItem.new
- @item.data_bag("bag_name")
- @item.raw_data = {"id" => "item_name", "FUU" => "FUU"}
- Chef::DataBagItem.should_receive(:load).with("bag_name", "item_name").and_return(@item)
- @language.data_bag_item("bag_name", "item_name").should == @item
- end
-
- it "validates the name of the data bag you're trying to load an item from" do
- lambda {@language.data_bag_item(" %%^& ", "item_name")}.should raise_error(Chef::Exceptions::InvalidDataBagName)
- end
-
- it "validates the id of the data bag item you're trying to load" do
- lambda {@language.data_bag_item("bag_name", " 987 (*&()")}.should raise_error(Chef::Exceptions::InvalidDataBagItemID)
- end
-
- it "validates that the id of the data bag item is not nil" do
- lambda {@language.data_bag_item("bag_name", nil)}.should raise_error(Chef::Exceptions::InvalidDataBagItemID)
- end
-
end
end
-describe Chef::Mixin::Language::PlatformDependentValue do
+describe Chef::DSL::PlatformIntrospection::PlatformDependentValue do
before do
platform_hash = {
:openbsd => {:default => 'free, functional, secure'},
@@ -218,7 +186,7 @@ describe Chef::Mixin::Language::PlatformDependentValue do
:ubuntu => {'10.04' => 'using upstart more', :default => 'using init more'},
:default => 'bork da bork'
}
- @platform_specific_value = Chef::Mixin::Language::PlatformDependentValue.new(platform_hash)
+ @platform_specific_value = Chef::DSL::PlatformIntrospection::PlatformDependentValue.new(platform_hash)
end
it "returns the default value when the platform doesn't match" do
@@ -246,29 +214,29 @@ describe Chef::Mixin::Language::PlatformDependentValue do
it "returns nil if there is no default and no platforms match" do
# this matches the behavior in the original implementation.
# whether or not it's correct is another matter.
- platform_specific_value = Chef::Mixin::Language::PlatformDependentValue.new({})
+ platform_specific_value = Chef::DSL::PlatformIntrospection::PlatformDependentValue.new({})
platform_specific_value.value_for_node(:platform => 'foo').should be_nil
end
it "raises an argument error if the platform hash is not correctly structured" do
bad_hash = {:ubuntu => :foo} # should be :ubuntu => {:default => 'foo'}
- lambda {Chef::Mixin::Language::PlatformDependentValue.new(bad_hash)}.should raise_error(ArgumentError)
+ lambda {Chef::DSL::PlatformIntrospection::PlatformDependentValue.new(bad_hash)}.should raise_error(ArgumentError)
end
end
-describe Chef::Mixin::Language::PlatformFamilyDependentValue do
+describe Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue do
before do
- @array_values = [:stop, :start, :reload]
+ @array_values = [:stop, :start, :reload]
- @platform_family_hash = {
- "debian" => "debian value",
- [:rhel, "fedora"] => "redhatty value",
- "suse" => @array_values,
+ @platform_family_hash = {
+ "debian" => "debian value",
+ [:rhel, "fedora"] => "redhatty value",
+ "suse" => @array_values,
:gentoo => "gentoo value",
:default => "default value"
}
-
- @platform_family_value = Chef::Mixin::Language::PlatformFamilyDependentValue.new(@platform_family_hash)
+
+ @platform_family_value = Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue.new(@platform_family_hash)
end
it "returns the default value when the platform family doesn't match" do
@@ -277,28 +245,27 @@ describe Chef::Mixin::Language::PlatformFamilyDependentValue do
it "returns a value for the platform family when it was set as a string but fetched as a symbol" do
- @platform_family_value.value_for_node(:platform_family => :debian).should == "debian value"
+ @platform_family_value.value_for_node(:platform_family => :debian).should == "debian value"
end
-
-
+
it "returns a value for the platform family when it was set as a symbol but fetched as a string" do
- @platform_family_value.value_for_node(:platform_family => "gentoo").should == "gentoo value"
+ @platform_family_value.value_for_node(:platform_family => "gentoo").should == "gentoo value"
end
-
- it "returns an array value stored for a platform family" do
+
+ it "returns an array value stored for a platform family" do
@platform_family_value.value_for_node(:platform_family => "suse").should == @array_values
end
it "returns a value for the platform family when it was set within an array hash key as a symbol" do
- @platform_family_value.value_for_node(:platform_family => :rhel).should == "redhatty value"
+ @platform_family_value.value_for_node(:platform_family => :rhel).should == "redhatty value"
end
-
+
it "returns a value for the platform family when it was set within an array hash key as a string" do
- @platform_family_value.value_for_node(:platform_family => "fedora").should == "redhatty value"
+ @platform_family_value.value_for_node(:platform_family => "fedora").should == "redhatty value"
end
-
+
it "returns nil if there is no default and no platforms match" do
- platform_specific_value = Chef::Mixin::Language::PlatformFamilyDependentValue.new({})
+ platform_specific_value = Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue.new({})
platform_specific_value.value_for_node(:platform_family => 'foo').should be_nil
end
diff --git a/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
index 277e710ddf..54a57d8077 100644
--- a/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
+++ b/chef/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
@@ -19,7 +19,7 @@
require 'spec_helper'
describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do
- include Chef::Mixin::RecipeDefinitionDSLCore
+ include Chef::DSL::Recipe
def run_context
node = Chef::Node.new
diff --git a/chef/spec/unit/node_spec.rb b/chef/spec/unit/node_spec.rb
index 2be154c5b3..4577d5098b 100644
--- a/chef/spec/unit/node_spec.rb
+++ b/chef/spec/unit/node_spec.rb
@@ -21,7 +21,6 @@ require 'ostruct'
describe Chef::Node do
before(:each) do
- Chef::Config.node_path(File.expand_path(File.join(CHEF_SPEC_DATA, "nodes")))
@node = Chef::Node.new()
end
@@ -63,12 +62,9 @@ describe Chef::Node do
end
describe "run_state" do
- it "should have a template_cache hash" do
- @node.run_state[:template_cache].should be_a_kind_of(Hash)
- end
-
- it "should have a seen_recipes hash" do
- @node.run_state[:seen_recipes].should be_a_kind_of(Hash)
+ it "is an empty hash" do
+ @node.run_state.should respond_to(:keys)
+ @node.run_state.should be_empty
end
end
@@ -123,18 +119,6 @@ describe Chef::Node do
end
describe "attributes" do
- it "should be loaded from the node's cookbooks" do
- @cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
- cl = Chef::CookbookLoader.new(@cookbook_repo)
- cl.load_cookbooks
- @node.cookbook_collection = Chef::CookbookCollection.new(cl)
- @node.load_attributes
- @node.ldap_server.should eql("ops1prod")
- @node.ldap_basedn.should eql("dc=hjksolutions,dc=com")
- @node.ldap_replication_password.should eql("forsure")
- @node.smokey.should eql("robinson")
- end
-
it "should have attributes" do
@node.attribute.should be_a_kind_of(Hash)
end
@@ -440,33 +424,34 @@ describe Chef::Node do
end
end
- # TODO: timh, cw: 2010-5-19: Node.recipe? deprecated. See node.rb
- # describe "recipes" do
- # it "should have a RunList of recipes that should be applied" do
- # @node.recipes.should be_a_kind_of(Chef::RunList)
- # end
- #
- # it "should allow you to query whether or not it has a recipe applied with recipe?" do
- # @node.recipes << "sunrise"
- # @node.recipe?("sunrise").should eql(true)
- # @node.recipe?("not at home").should eql(false)
- # end
- #
- # it "should allow you to query whether or not a recipe has been applied, even if it was included" do
- # @node.run_state[:seen_recipes]["snakes"] = true
- # @node.recipe?("snakes").should eql(true)
- # end
- #
- # it "should return false if a recipe has not been seen" do
- # @node.recipe?("snakes").should eql(false)
- # end
- #
- # it "should allow you to set recipes with arguments" do
- # @node.recipes "one", "two"
- # @node.recipe?("one").should eql(true)
- # @node.recipe?("two").should eql(true)
- # end
- # end
+ describe "when evaluating attributes files" do
+ before do
+ @node = Chef::Node.new
+
+ @cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks"))
+ @cookbook_loader = Chef::CookbookLoader.new(@cookbook_repo)
+ @cookbook_loader.load_cookbooks
+
+ @cookbook_collection = Chef::CookbookCollection.new(@cookbook_loader.cookbooks_by_name)
+
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
+
+ @node.include_attribute("openldap::default")
+ @node.include_attribute("openldap::smokey")
+ end
+
+ it "sets attributes from the files" do
+ @node.ldap_server.should eql("ops1prod")
+ @node.ldap_basedn.should eql("dc=hjksolutions,dc=com")
+ @node.ldap_replication_password.should eql("forsure")
+ @node.smokey.should eql("robinson")
+ end
+
+ it "gives a sensible error when attempting to load a missing attributes file" do
+ lambda { @node.include_attribute("nope-this::doesnt-exist") }.should raise_error(Chef::Exceptions::CookbookNotFound)
+ end
+ end
describe "roles" do
it "should allow you to query whether or not it has a recipe applied with role?" do
@@ -514,37 +499,6 @@ describe Chef::Node do
end
end
- describe "find_file" do
- it "should load a node from a file by fqdn" do
- @node.find_file("test.example.com")
- @node.name.should == "test.example.com"
- @node.chef_environment.should == "dev"
- end
-
- it "should load a node from a file by hostname" do
- File.stub!(:exists?).and_return(true)
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
- @node.find_file("test.example.com")
- @node.name.should == "test.example.com-short"
- end
-
- it "should load a node from the default file" do
- File.stub!(:exists?).and_return(true)
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false)
- @node.find_file("test.example.com")
- @node.name.should == "test.example.com-default"
- end
-
- it "should raise an ArgumentError if it cannot find any node file at all" do
- File.stub!(:exists?).and_return(true)
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false)
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "default.rb")).and_return(false)
- lambda { @node.find_file("test.example.com") }.should raise_error(ArgumentError)
- end
- end
-
describe "update_from!" do
before(:each) do
@node.name("orig")
@@ -607,7 +561,7 @@ describe Chef::Node do
describe "json" do
it "should serialize itself as json", :json => true do
- @node.find_file("test.example.com")
+ @node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
json = Chef::JSONCompat.to_json(@node)
json.should =~ /json_class/
json.should =~ /name/
@@ -628,7 +582,7 @@ describe Chef::Node do
end
it "should deserialize itself from json", :json => true do
- @node.find_file("test.example.com")
+ @node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
json = Chef::JSONCompat.to_json(@node)
serialized_node = Chef::JSONCompat.from_json(json)
serialized_node.should be_a_kind_of(Chef::Node)
diff --git a/chef/spec/unit/provider/package/apt_spec.rb b/chef/spec/unit/provider/package/apt_spec.rb
index e40a640837..06ada5189e 100644
--- a/chef/spec/unit/provider/package/apt_spec.rb
+++ b/chef/spec/unit/provider/package/apt_spec.rb
@@ -22,7 +22,6 @@ require 'ostruct'
describe Chef::Provider::Package::Apt do
before(:each) do
@node = Chef::Node.new
- @node.cookbook_collection = {}
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
@new_resource = Chef::Resource::Package.new("irssi", @run_context)
diff --git a/chef/spec/unit/provider/package/ips_spec.rb b/chef/spec/unit/provider/package/ips_spec.rb
index dad880a93b..641a527012 100644
--- a/chef/spec/unit/provider/package/ips_spec.rb
+++ b/chef/spec/unit/provider/package/ips_spec.rb
@@ -24,7 +24,6 @@ require 'ostruct'
describe Chef::Provider::Package::Ips do
before(:each) do
@node = Chef::Node.new
- @node.cookbook_collection = {}
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
@new_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context)
diff --git a/chef/spec/unit/recipe_spec.rb b/chef/spec/unit/recipe_spec.rb
index 797e566190..4615bcb4d4 100644
--- a/chef/spec/unit/recipe_spec.rb
+++ b/chef/spec/unit/recipe_spec.rb
@@ -206,9 +206,9 @@ describe Chef::Recipe do
res.pretty_kitty.should eql(true)
end
- it "should store that it has seen a recipe in node.run_state[:seen_recipes]" do
+ it "should store that it has seen a recipe in the run_context" do
@run_context.include_recipe "openldap"
- @node.run_state[:seen_recipes].should have_key("openldap")
+ @run_context.loaded_recipe?("openldap").should be_true
end
it "should not include the same recipe twice" do
diff --git a/chef/spec/unit/run_context_spec.rb b/chef/spec/unit/run_context_spec.rb
index 7bdcc60de0..51fa0e81f9 100644
--- a/chef/spec/unit/run_context_spec.rb
+++ b/chef/spec/unit/run_context_spec.rb
@@ -24,13 +24,12 @@ Chef::Log.level = :debug
describe Chef::RunContext do
before(:each) do
- Chef::Config.node_path(File.expand_path(File.join(CHEF_SPEC_DATA, "run_context", "nodes")))
@chef_repo_path = File.expand_path(File.join(CHEF_SPEC_DATA, "run_context", "cookbooks"))
cl = Chef::CookbookLoader.new(@chef_repo_path)
cl.load_cookbooks
@cookbook_collection = Chef::CookbookCollection.new(cl)
@node = Chef::Node.new
- @node.find_file("run_context")
+ @node.run_list << "test" << "test::one" << "test::two"
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
end
@@ -55,12 +54,25 @@ describe Chef::RunContext do
end
it "should load all the recipes specified for this node" do
- @run_context.resource_collection[0].to_s.should == "cat[einstein]"
+ @run_context.resource_collection[0].to_s.should == "cat[einstein]"
@run_context.resource_collection[1].to_s.should == "cat[loulou]"
@run_context.resource_collection[2].to_s.should == "cat[birthday]"
@run_context.resource_collection[3].to_s.should == "cat[peanut]"
@run_context.resource_collection[4].to_s.should == "cat[fat peanut]"
end
+
+ it "loads all the attribute files in the cookbook collection" do
+ @run_context.loaded_fully_qualified_attribute?("test", "george").should be_true
+ @node[:george].should == "washington"
+ end
+
+ it "registers attributes files as loaded so they won't be reloaded" do
+ # This test unfortunately is pretty tightly intertwined with the
+ # implementation of how nodes load attribute files, but is the only
+ # convenient way to test this behavior.
+ @node.should_not_receive(:from_file)
+ @node.include_attribute("test::george")
+ end
end
end