diff options
author | John Keiser <jkeiser@opscode.com> | 2013-09-09 21:58:53 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-09-09 21:58:53 -0700 |
commit | dbe3521f75e6fe37a7e58bc79fbe89ec7ac2c071 (patch) | |
tree | b7a45d48694bf7b1e5b6296e070a802ec35b1d14 /spec | |
parent | 6a329b4abea7c624a88d05d3122679a5273d65a9 (diff) | |
download | mixlib-config-dbe3521f75e6fe37a7e58bc79fbe89ec7ac2c071.tar.gz |
Add context() DSL for config classes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/config_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb index 420e36f..4e141c8 100644 --- a/spec/mixlib/config_spec.rb +++ b/spec/mixlib/config_spec.rb @@ -311,4 +311,74 @@ describe Mixlib::Config do @klass.attr.should == 4 end end + + describe "When a configurable exists with a context" do + before :each do + @klass = Class.new + @klass.extend(::Mixlib::Config) + @klass.class_eval do + context(:blah) do + default :x, 5 + end + end + end + + it "configurable defaults in that context work" do + @klass.blah.x.should == 5 + end + + it "after setting values in the context, the values remain set" do + @klass.blah.x = 10 + @klass.blah.x.should == 10 + end + + it "setting values with the same name in the parent context do not affect the child context" do + @klass.x = 10 + @klass.x.should == 10 + @klass.blah.x.should == 5 + end + + it "after reset of the parent class, children are reset" do + @klass.blah.x = 10 + @klass.blah.x.should == 10 + @klass.reset + @klass.blah.x.should == 5 + end + end + + describe "When a configurable exists with a nested context" do + before :each do + @klass = Class.new + @klass.extend(::Mixlib::Config) + @klass.class_eval do + context(:blah) do + context(:yarr) do + default :x, 5 + end + end + end + end + + it "configurable defaults in that context work" do + @klass.blah.yarr.x.should == 5 + end + + it "after setting values in the context, the values remain set" do + @klass.blah.yarr.x = 10 + @klass.blah.yarr.x.should == 10 + end + + it "setting values with the same name in the parent context do not affect the child context" do + @klass.x = 10 + @klass.x.should == 10 + @klass.blah.yarr.x.should == 5 + end + + it "after reset of the parent class, children are reset" do + @klass.blah.yarr.x = 10 + @klass.blah.yarr.x.should == 10 + @klass.reset + @klass.blah.yarr.x.should == 5 + end + end end |