spec/mixlib/config_spec.rb in mixlib-config-2.2.1 vs spec/mixlib/config_spec.rb in mixlib-config-2.2.2
- old
+ new
@@ -16,29 +16,24 @@
# limitations under the License.
#
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
-class ConfigIt
- extend ::Mixlib::Config
-end
-
-
describe Mixlib::Config do
before(:each) do
ConfigIt.configure do |c|
- c[:alpha] = 'omega'
+ c[:alpha] = "omega"
c[:foo] = nil
end
end
it "should load a config file" do
File.stub(:exists?).and_return(true)
File.stub(:readable?).and_return(true)
- IO.stub(:read).with('config.rb').and_return("alpha = 'omega'\nfoo = 'bar'")
+ IO.stub(:read).with("config.rb").and_return("alpha = 'omega'\nfoo = 'bar'")
lambda {
- ConfigIt.from_file('config.rb')
+ ConfigIt.from_file("config.rb")
}.should_not raise_error
end
it "should not raise an ArgumentError with an explanation if you try and set a non-existent variable" do
lambda {
@@ -51,31 +46,31 @@
ConfigIt.from_file("/tmp/timmytimmytimmy")
}.should raise_error(Errno::ENOENT)
end
it "should allow the error to bubble up when it's anything other than IOError" do
- IO.stub(:read).with('config.rb').and_return("@#asdf")
+ IO.stub(:read).with("config.rb").and_return("@#asdf")
lambda {
- ConfigIt.from_file('config.rb')
+ ConfigIt.from_file("config.rb")
}.should raise_error(SyntaxError)
end
it "should allow you to reference a value by index" do
- ConfigIt[:alpha].should == 'omega'
+ ConfigIt[:alpha].should == "omega"
end
it "should allow you to reference a value by string index" do
- ConfigIt['alpha'].should == 'omega'
+ ConfigIt["alpha"].should == "omega"
end
it "should allow you to set a value by index" do
ConfigIt[:alpha] = "one"
ConfigIt[:alpha].should == "one"
end
it "should allow you to set a value by string index" do
- ConfigIt['alpha'] = "one"
+ ConfigIt["alpha"] = "one"
ConfigIt[:alpha].should == "one"
end
it "should allow setting a value with attribute form" do
ConfigIt.arbitrary_value = 50
@@ -125,11 +120,11 @@
describe "when a block has been used to set config values" do
before do
ConfigIt.configure { |c| c[:cookbook_path] = "monkey_rabbit"; c[:otherthing] = "boo" }
end
- {:cookbook_path => "monkey_rabbit", :otherthing => "boo"}.each do |k,v|
+ { :cookbook_path => "monkey_rabbit", :otherthing => "boo" }.each do |k, v|
it "should allow you to retrieve the config value for #{k} via []" do
ConfigIt[k].should == v
end
it "should allow you to retrieve the config value for #{k} via method_missing" do
ConfigIt.send(k).should == v
@@ -172,12 +167,12 @@
@klass.instance_eval("test_method 73")
@klass.test_method.should == 73000
end
it "should multiply an integer by 1000 via from-file, too" do
- IO.stub(:read).with('config.rb').and_return("test_method 99")
- @klass.from_file('config.rb')
+ IO.stub(:read).with("config.rb").and_return("test_method 99")
+ @klass.from_file("config.rb")
@klass.test_method.should == 99000
end
it "should receive internal_set with the method name and config value" do
@klass.should_receive(:internal_set).with(:test_method, 53).and_return(true)
@@ -224,22 +219,27 @@
Object.send :define_method, "daemonizeme=".to_sym do
raise NopeError, "NOPE"
end
end
- it 'Normal classes call the extra method' do
+ after do
+ Object.send :remove_method, :daemonizeme
+ Object.send :remove_method, :'daemonizeme='
+ end
+
+ it "Normal classes call the extra method" do
normal_class = Class.new
normal_class.extend(::Mixlib::Config)
lambda { normal_class.daemonizeme }.should raise_error(NopeError)
end
- it 'Configurables with the same name as the extra method can be set' do
+ it "Configurables with the same name as the extra method can be set" do
@klass.daemonizeme = 10
@klass[:daemonizeme].should == 10
end
- it 'Configurables with the same name as the extra method can be retrieved' do
+ it "Configurables with the same name as the extra method can be retrieved" do
@klass[:daemonizeme] = 10
@klass.daemonizeme.should == 10
end
end
end
@@ -307,11 +307,11 @@
before :each do
@klass = Class.new
@klass.extend(::Mixlib::Config)
@klass.class_eval do
default :x, 4
- default(:attr) { x*2 }
+ default(:attr) { x * 2 }
end
end
it "should default to that value" do
@klass.attr.should == 8
@@ -377,12 +377,12 @@
@klass.extend(::Mixlib::Config)
@klass.class_eval { default :attr, [] }
end
it "reset clears it to its default" do
- @klass.attr << 'x'
- @klass.attr.should == [ 'x' ]
+ @klass.attr << "x"
+ @klass.attr.should == [ "x" ]
@klass.reset
@klass.attr.should == []
end
it "save should not save anything for it" do
@@ -392,16 +392,16 @@
it "save with include_defaults should save all defaults" do
@klass.save(true).should == { :attr => [] }
end
it "save should save the new value if it gets set" do
- @klass.attr << 'x'
- (saved = @klass.save).should == { :attr => [ 'x' ] }
+ @klass.attr << "x"
+ (saved = @klass.save).should == { :attr => [ "x" ] }
@klass.reset
@klass.attr.should == []
@klass.restore(saved)
- @klass.attr.should == [ 'x' ]
+ @klass.attr.should == [ "x" ]
end
it "save should save the new value even if it is set to its default value" do
@klass.attr = []
(saved = @klass.save).should == { :attr => [] }
@@ -433,16 +433,16 @@
it "save with include_defaults should save all defaults" do
@klass.save(true).should == { :attr => {} }
end
it "save should save the new value if it gets set" do
- @klass.attr[:hi] = 'lo'
- (saved = @klass.save).should == { :attr => { :hi => 'lo' } }
+ @klass.attr[:hi] = "lo"
+ (saved = @klass.save).should == { :attr => { :hi => "lo" } }
@klass.reset
@klass.attr.should == {}
@klass.restore(saved)
- @klass.save.should == { :attr => { :hi => 'lo' } }
+ @klass.save.should == { :attr => { :hi => "lo" } }
end
it "save should save the new value even if it is set to its default value" do
@klass.attr = {}
(saved = @klass.save).should == { :attr => {} }
@@ -455,44 +455,44 @@
describe "When config has a string default value" do
before :each do
@klass = Class.new
@klass.extend(::Mixlib::Config)
- @klass.class_eval { default :attr, 'hello' }
+ @klass.class_eval { default :attr, "hello" }
end
it "reset clears it to its default" do
- @klass.attr << ' world'
- @klass.attr.should == 'hello world'
+ @klass.attr << " world"
+ @klass.attr.should == "hello world"
@klass.reset
- @klass.attr.should == 'hello'
+ @klass.attr.should == "hello"
end
it "save should not save anything for it" do
@klass.save.should == {}
end
it "save with include_defaults should save all defaults" do
- @klass.save(true).should == { :attr => 'hello' }
+ @klass.save(true).should == { :attr => "hello" }
end
it "save should save the new value if it gets set" do
- @klass.attr << ' world'
- (saved = @klass.save).should == { :attr => 'hello world' }
+ @klass.attr << " world"
+ (saved = @klass.save).should == { :attr => "hello world" }
@klass.reset
- @klass.attr.should == 'hello'
+ @klass.attr.should == "hello"
@klass.restore(saved)
- @klass.attr.should == 'hello world'
+ @klass.attr.should == "hello world"
end
it "save should save the new value even if it is set to its default value" do
- @klass.attr 'hello world'
- (saved = @klass.save).should == { :attr => 'hello world' }
+ @klass.attr "hello world"
+ (saved = @klass.save).should == { :attr => "hello world" }
@klass.reset
@klass.save.should == {}
@klass.restore(saved)
- @klass.save.should == { :attr => 'hello world' }
+ @klass.save.should == { :attr => "hello world" }
end
end
describe "When config has a a default value block" do
before :each do
@@ -561,11 +561,11 @@
@klass = Class.new
@klass.extend(::Mixlib::Config)
@klass.class_eval do
configurable(:attr) do |c|
c.defaults_to(4)
- c.writes_value { |value| value*2 }
+ c.writes_value { |value| value * 2 }
end
end
end
it "should default to that value" do
@@ -636,10 +636,10 @@
describe "When a configurable exists with writer and default value set in chained form" do
before :each do
@klass = Class.new
@klass.extend(::Mixlib::Config)
@klass.class_eval do
- configurable(:attr).defaults_to(4).writes_value { |value| value*2 }
+ configurable(:attr).defaults_to(4).writes_value { |value| value * 2 }
end
end
it "should default to that value" do
@klass.attr.should == 4