Skip to content

Commit

Permalink
Fix config_context_list/hash in strict mode
Browse files Browse the repository at this point in the history
Signed-off-by: Eli Young <[email protected]>
  • Loading branch information
elyscape committed May 21, 2018
1 parent 9a6bd80 commit 5063ed2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mixlib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def config_context(symbol, &block)
# 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

Expand Down Expand Up @@ -468,7 +468,7 @@ def config_context_list(plural_symbol, singular_symbol, &block)
# 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

Expand Down
20 changes: 20 additions & 0 deletions spec/mixlib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ class StrictClass
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
Expand Down

0 comments on commit 5063ed2

Please sign in to comment.