summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-09-22 13:03:38 -0700
committerGitHub <noreply@github.com>2016-09-22 13:03:38 -0700
commit70dc0d4b57d2766206700f17c991c0996a4c4e4a (patch)
tree52171d9e0421f8bb1b59394f7ef97095439ca1ed
parentb5070bb28b6a543fc95b312e0a568cf21c60e69e (diff)
parent8e3449879785b7572c0a9910cb4b2565413b713c (diff)
downloadchef-70dc0d4b57d2766206700f17c991c0996a4c4e4a.tar.gz
Merge pull request #5299 from chef/lcg/ignore-unknown-metdata-rb-fields
ignore unknown metadata fields in metadata.rb
-rw-r--r--lib/chef/cookbook/metadata.rb8
-rw-r--r--spec/unit/cookbook/metadata_spec.rb19
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index ab83da9e55..02f9831d70 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -722,6 +722,14 @@ class Chef
end
end
+ def method_missing(method, *args, &block)
+ if block_given?
+ super
+ else
+ Chef::Log.debug "ignoring method #{method} on cookbook with name #{name}, possible typo or future metadata?"
+ end
+ end
+
private
# Helper to match a gem style version (ohai_version/chef_version) against a set of
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index 27666eb338..389f02501a 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -948,5 +948,24 @@ describe Chef::Cookbook::Metadata do
end
end
+ describe "from_file" do
+ it "ignores unknown metadata fields in metadata.rb files" do
+ expect(Chef::Log).to receive(:debug).with(/ignoring method some_spiffy_new_metadata_field/)
+ Tempfile.open("metadata.rb") do |f|
+ f.write <<-EOF
+ some_spiffy_new_metadata_field "stuff its set to"
+ EOF
+ f.close
+ metadata.from_file(f.path)
+ end
+ end
+ end
+
+ describe "from_json" do
+ it "ignores unknown metadata fields in metdata.json files" do
+ json = %q{{ "some_spiffy_new_metadata_field": "stuff its set to" }}
+ metadata.from_json(json)
+ end
+ end
end
end