diff options
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 8 | ||||
-rw-r--r-- | spec/unit/cookbook/metadata_spec.rb | 19 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index ab83da9e55..212c596272 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.warn "ignoring method #{method} on cookbook with name #{name}, possible typo or future metdata?" + 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..a6c85bd397 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(:warn).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 |