From 2dc31c62db3a4d0a5accfcc592d5accafc1d42db Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Wed, 25 Mar 2015 19:42:13 -0700 Subject: [PATCH] Allow cookbooks to be defined with no source option in DSL --- .../cookbook_location_specification.rb | 6 +++++- spec/unit/policyfile_evaluation_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/chef-dk/policyfile/cookbook_location_specification.rb b/lib/chef-dk/policyfile/cookbook_location_specification.rb index b3a2886d5..3faea5c6a 100644 --- a/lib/chef-dk/policyfile/cookbook_location_specification.rb +++ b/lib/chef-dk/policyfile/cookbook_location_specification.rb @@ -80,7 +80,7 @@ def valid? def errors error_messages = [] - if installer.nil? + if source_options_invalid? error_messages << "Cookbook `#{name}' has invalid source options `#{source_options.inspect}'" end error_messages @@ -124,6 +124,10 @@ def source_options_for_lock installer.lock_data end + def source_options_invalid? + !source_options.empty? && installer.nil? + end + end end end diff --git a/spec/unit/policyfile_evaluation_spec.rb b/spec/unit/policyfile_evaluation_spec.rb index fcc2f50d6..329a2b902 100644 --- a/spec/unit/policyfile_evaluation_spec.rb +++ b/spec/unit/policyfile_evaluation_spec.rb @@ -206,6 +206,22 @@ end + context "with an added cookbook with no options" do + + let(:policyfile_rb) do + <<-EOH + run_list "foo", "bar" + cookbook "baz" + EOH + end + + it "adds the cookbook to the list of location specs" do + expect(policyfile.errors).to eq([]) + expected_cb_spec = ChefDK::Policyfile::CookbookLocationSpecification.new("baz", ">= 0.0.0", {}, storage_config) + expect(policyfile.cookbook_location_specs).to eq("baz" => expected_cb_spec) + end + end + end context "with the default source set to a chef server" do