summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Young <elyscape@gmail.com>2018-05-21 14:55:19 -0700
committerThom May <thom@chef.io>2018-06-13 12:41:40 +0100
commitf9e5d769a374fcec8262ee1e080560d3bad794f0 (patch)
tree28555ac2d643f35eb7bc5874b28dc54ebe9a7d06
parent8795d1cb409607f396fefba732d800e2fefeeef1 (diff)
downloadmixlib-config-f9e5d769a374fcec8262ee1e080560d3bad794f0.tar.gz
Fix config_context_list/hash in strict mode
Signed-off-by: Eli Young <elyscape@gmail.com>
-rw-r--r--lib/mixlib/config.rb4
-rw-r--r--spec/mixlib/config_spec.rb20
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb
index 8c0c834..03486a8 100644
--- a/lib/mixlib/config.rb
+++ b/lib/mixlib/config.rb
@@ -436,7 +436,7 @@ module Mixlib
# block<Block>: a block that will be run in the context of this new config
# class.
def config_context_list(plural_symbol, singular_symbol, &block)
- if configurables.has_key?(symbol)
+ if configurables.has_key?(plural_symbol)
raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context"
end
@@ -468,7 +468,7 @@ module Mixlib
# block<Block>: a block that will be run in the context of this new config
# class.
def config_context_hash(plural_symbol, singular_symbol, &block)
- if configurables.has_key?(symbol)
+ if configurables.has_key?(plural_symbol)
raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context"
end
diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb
index cf2841b..e171712 100644
--- a/spec/mixlib/config_spec.rb
+++ b/spec/mixlib/config_spec.rb
@@ -115,6 +115,26 @@ describe Mixlib::Config do
it "raises an error when you set an arbitrary config option with [:y] = 10" do
expect(lambda { StrictClass[:y] = 10 }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported config value y.")
end
+
+ it "does not break config_context_list" do
+ expect(lambda do
+ StrictClass.class_eval do
+ config_context_list(:lists, :list) do
+ default :y, 20
+ end
+ end
+ end).not_to raise_error
+ end
+
+ it "does not break config_context_hash" do
+ expect(lambda do
+ StrictClass.class_eval do
+ config_context_hash(:hashes, :hash) do
+ default :z, 20
+ end
+ end
+ end).not_to raise_error
+ end
end
describe "when a block has been used to set config values" do