spec/configuration_spec.rb in loquacious-1.8.1 vs spec/configuration_spec.rb in loquacious-1.9.0
- old
+ new
@@ -9,31 +9,31 @@
it 'should initialize from a block' do
obj = Loquacious::Configuration.new {
first 'foo'
second 'bar'
}
- obj.first.should == 'foo'
- obj.second.should == 'bar'
+ obj.first.should be == 'foo'
+ obj.second.should be == 'bar'
obj.third.should be_nil
end
it 'should respond to any method' do
@obj.first.should be_nil
@obj.first = 'foo'
- @obj.first.should == 'foo'
+ @obj.first.should be == 'foo'
@obj.second = 'bar'
- @obj.second.should == 'bar'
+ @obj.second.should be == 'bar'
end
it 'should deine attribute accessors when first used' do
- @obj.respond_to?(:foo).should == false
- @obj.respond_to?(:foo=).should == false
+ @obj.respond_to?(:foo).should be == false
+ @obj.respond_to?(:foo=).should be == false
@obj.foo
- @obj.respond_to?(:foo).should == true
- @obj.respond_to?(:foo=).should == true
+ @obj.respond_to?(:foo).should be == true
+ @obj.respond_to?(:foo=).should be == true
end
it 'should provide a hash object for storing method descriptions' do
h = @obj.__desc
@obj.__desc.should equal(h)
@@ -41,105 +41,105 @@
it 'should allow attributes to be assigned hash values' do
cfg = Loquacious::Configuration.new {
hash({:one => 1})
}
- cfg.hash.should == {:one => 1}
+ cfg.hash.should be == {:one => 1}
end
it 'should provide hash accessor notation for attributes' do
cfg = Loquacious::Configuration.new {
one 1
two 2
three 3
}
- cfg['one'].should == 1
- cfg[:two].should == 2
- cfg['three'].should == 3
+ cfg['one'].should be == 1
+ cfg[:two].should be == 2
+ cfg['three'].should be == 3
cfg[:four].should be_nil
cfg.four = 4
- cfg[:four].should == 4
+ cfg[:four].should be == 4
cfg[:five] = 5
- cfg.five.should == 5
- cfg[:five].should == 5
+ cfg.five.should be == 5
+ cfg[:five].should be == 5
end
it 'should allow Kernel methods to be treated as configuration attributes' do
cfg = Loquacious::Configuration.new {
fork 'spoon knife spork'
split 'join'
raise 'double down'
puts 'not what you think'
}
- cfg['fork'].should == 'spoon knife spork'
- cfg['split'].should == 'join'
- cfg['raise'].should == 'double down'
- cfg['puts'].should == 'not what you think'
+ cfg['fork'].should be == 'spoon knife spork'
+ cfg['split'].should be == 'join'
+ cfg['raise'].should be == 'double down'
+ cfg['puts'].should be == 'not what you think'
- cfg[:fork].should == 'spoon knife spork'
- cfg[:split].should == 'join'
- cfg[:raise].should == 'double down'
- cfg[:puts].should == 'not what you think'
+ cfg[:fork].should be == 'spoon knife spork'
+ cfg[:split].should be == 'join'
+ cfg[:raise].should be == 'double down'
+ cfg[:puts].should be == 'not what you think'
- cfg.fork.should == 'spoon knife spork'
- cfg.split.should == 'join'
- cfg.raise.should == 'double down'
- cfg.puts.should == 'not what you think'
+ cfg.fork.should be == 'spoon knife spork'
+ cfg.split.should be == 'join'
+ cfg.raise.should be == 'double down'
+ cfg.puts.should be == 'not what you think'
end
it 'should not be affected by loading other modules like timeout' do
require 'timeout'
Loquacious.remove :timeout
cfg = Loquacious::Configuration.new {
timeout 10
foo 'bar'
baz 'buz'
}
- cfg.timeout.should == 10
- cfg.foo.should == 'bar'
- cfg.baz.should == 'buz'
+ cfg.timeout.should be == 10
+ cfg.foo.should be == 'bar'
+ cfg.baz.should be == 'buz'
end
it 'should evaluate Proc objects when fetching values' do
obj = Loquacious::Configuration.new {
first 'foo'
second 'bar'
}
obj.third = Proc.new { obj.first + obj.second }
- obj.third.should == 'foobar'
+ obj.third.should be == 'foobar'
obj.second = 'baz'
- obj.third.should == 'foobaz'
+ obj.third.should be == 'foobaz'
obj.first = 'Hello '
obj.second = 'World!'
- obj.third.should == 'Hello World!'
+ obj.third.should be == 'Hello World!'
end
it 'should return a value when evaluating inside the DSL' do
obj = Loquacious::Configuration.new {
first 'foo'
second {
bar nil
}
}
- obj.first.should == 'foo'
+ obj.first.should be == 'foo'
obj.second.bar.should be_nil
Loquacious::Configuration::DSL.evaluate(:config => obj) {
first 'bar'
second.bar 'no longer nil'
}
- obj.first.should == 'bar'
- obj.second.bar.should == 'no longer nil'
+ obj.first.should be == 'bar'
+ obj.second.bar.should be == 'no longer nil'
end
it 'should not delete descriptions' do
obj = Loquacious::Configuration.new {
first 'foo', :desc => 'the first value'
@@ -148,28 +148,28 @@
second {
bar nil, :desc => 'time to go drinking'
}
}
- obj.first.should == 'foo'
+ obj.first.should be == 'foo'
obj.second.bar.should be_nil
- obj.__desc[:first].should == 'the first value'
- obj.__desc[:second].should == 'the second value'
- obj.second.__desc[:bar].should == 'time to go drinking'
+ obj.__desc[:first].should be == 'the first value'
+ obj.__desc[:second].should be == 'the second value'
+ obj.second.__desc[:bar].should be == 'time to go drinking'
Loquacious::Configuration::DSL.evaluate(:config => obj) {
first 'bar'
second.bar 'no longer nil'
}
- obj.first.should == 'bar'
- obj.second.bar.should == 'no longer nil'
+ obj.first.should be == 'bar'
+ obj.second.bar.should be == 'no longer nil'
- obj.__desc[:first].should == 'the first value'
- obj.__desc[:second].should == 'the second value'
- obj.second.__desc[:bar].should == 'time to go drinking'
+ obj.__desc[:first].should be == 'the first value'
+ obj.__desc[:second].should be == 'the second value'
+ obj.second.__desc[:bar].should be == 'time to go drinking'
end
# -----------------------------------------------------------------------
describe 'when merging' do
@@ -179,16 +179,16 @@
second 'bar', :desc => 'bar method'
}
@obj.first.should be_nil
@obj.second.should be_nil
- @obj.__desc.should == {:first => nil, :second => nil}
+ @obj.__desc.should be == {:first => nil, :second => nil}
@obj.merge! other
- @obj.first.should == 'foo'
- @obj.second.should == 'bar'
- @obj.__desc.should == {
+ @obj.first.should be == 'foo'
+ @obj.second.should be == 'bar'
+ @obj.__desc.should be == {
:first => 'foo method',
:second => 'bar method'
}
end
@@ -209,21 +209,21 @@
}
}
@obj.merge! other
- @obj.first.should == 'foo'
- @obj.second.should == 'bar'
- @obj.third.question.should == '?'
- @obj.third.answer.should == 42
+ @obj.first.should be == 'foo'
+ @obj.second.should be == 'bar'
+ @obj.third.question.should be == '?'
+ @obj.third.answer.should be == 42
- @obj.__desc.should == {
+ @obj.__desc.should be == {
:first => 'foo method',
:second => 'bar method',
:third => 'the third group'
}
- @obj.third.__desc.should == {
+ @obj.third.__desc.should be == {
:question => 'perhaps you do not understand',
:answer => 'life the universe and everything'
}
end
@@ -244,12 +244,12 @@
STR
first 'foo'
second 'bar', :desc => "bar method\n also a multiline comment"
}
- other.__desc[:first].should == "This is the first thing we are defining in this config.\nIt has a multiline comment."
- other.__desc[:second].should == "bar method\nalso a multiline comment"
+ other.__desc[:first].should be == "This is the first thing we are defining in this config.\nIt has a multiline comment."
+ other.__desc[:second].should be == "bar method\nalso a multiline comment"
end
it 'should leave whitespace after a gutter marker' do
other = Loquacious::Configuration.new {
desc <<-STR
@@ -266,12 +266,12 @@
| followed by this line
DESC
second 'bar'
}
- other.__desc[:first].should == " This is the first thing we are defining in this config.\n It has a multiline comment."
- other.__desc[:second].should == "This is a short explanation\n\nExample:\n do this then that\n followed by this line"
+ other.__desc[:first].should be == " This is the first thing we are defining in this config.\n It has a multiline comment."
+ other.__desc[:second].should be == "This is a short explanation\n\nExample:\n do this then that\n followed by this line"
end
end
# -----------------------------------------------------------------------
describe 'when working with defaults' do
@@ -287,11 +287,11 @@
bar nil, :desc => 'time to go drinking'
}
}
c = Loquacious::Configuration.for 'test'
- c.first.should == 'foo'
+ c.first.should be == 'foo'
c.second.bar.should be_nil
end
it 'does not overwrite existing configuration values' do
c = Loquacious::Configuration.for('test') {
@@ -305,17 +305,17 @@
second {
bar nil, :desc => 'time to go drinking'
}
}
- c.first.should == 1
- c.third.should == 3
+ c.first.should be == 1
+ c.third.should be == 3
c.second.bar.should be_nil
- c.__desc[:first].should == 'the first value'
- c.__desc[:second].should == 'the second value'
- c.second.__desc[:bar].should == 'time to go drinking'
+ c.__desc[:first].should be == 'the first value'
+ c.__desc[:second].should be == 'the second value'
+ c.second.__desc[:bar].should be == 'time to go drinking'
c.__desc[:thrid].should be_nil
end
it 'does not overwrite nested configuration values' do
c = Loquacious::Configuration.for('test') {
@@ -341,25 +341,25 @@
boo nil, :desc => 'no need to cry about it'
}
}
}
- c.first.should == 1
- c.third.should == 3
- c.second.bar.should == 'pub'
- c.second.baz.buz.should == 'random text'
- c.second.baz.boo.should == 'who'
+ c.first.should be == 1
+ c.third.should be == 3
+ c.second.bar.should be == 'pub'
+ c.second.baz.buz.should be == 'random text'
+ c.second.baz.boo.should be == 'who'
c.second.bar = Loquacious::Undefined.new('second.bar')
- c.second.bar.should == 'h-bar'
+ c.second.bar.should be == 'h-bar'
- c.__desc[:first].should == 'the first value'
- c.__desc[:second].should == 'the second value'
- c.second.__desc[:bar].should == 'time to go drinking'
- c.second.__desc[:baz].should == 'getting weird'
- c.second.baz.__desc[:buz].should == 'post drinking feeling'
- c.second.baz.__desc[:boo].should == 'no need to cry about it'
+ c.__desc[:first].should be == 'the first value'
+ c.__desc[:second].should be == 'the second value'
+ c.second.__desc[:bar].should be == 'time to go drinking'
+ c.second.__desc[:baz].should be == 'getting weird'
+ c.second.baz.__desc[:buz].should be == 'post drinking feeling'
+ c.second.baz.__desc[:boo].should be == 'no need to cry about it'
c.__desc[:thrid].should be_nil
end
it 'supports differing default type' do
c = Loquacious::Configuration.for('test') {
@@ -382,16 +382,16 @@
bar 'h-bar', :desc => 'time to go drinking'
baz nil, :desc => 'deprecated'
}
}
- c.second.baz.buz.should == 'random text'
- c.second.baz.boo.should == 'who'
+ c.second.baz.buz.should be == 'random text'
+ c.second.baz.boo.should be == 'who'
c.second.baz = Loquacious::Undefined.new('second.bar')
c.second.baz.should be_nil
- c.second.__desc[:baz].should == 'deprecated'
+ c.second.__desc[:baz].should be == 'deprecated'
end
it 'properly handles Proc default values' do
c = Loquacious::Configuration.for('test') {
first 1
@@ -408,11 +408,45 @@
bar 'h-bar', :desc => 'time to go drinking'
baz(Proc.new { c.third * 12 }, :desc => 'proc will be evaluated')
}
}
- c.second.baz.should == 36
- c.second.__desc[:baz].should == 'proc will be evaluated'
+ c.second.baz.should be == 36
+ c.second.__desc[:baz].should be == 'proc will be evaluated'
+ end
+ end
+
+ # -----------------------------------------------------------------------
+ describe 'when converting to a hash' do
+ it "should do so recursively" do
+ c = Loquacious::Configuration.new {
+ first 1, :desc => 'one is the loneliest number'
+ second {
+ bar 'pub', :desc => 'where the magic happens'
+ desc 'overwrite me'
+ baz {
+ buz 'random text'
+ boo 'who'
+ }
+ }
+ third 3
+ }
+ c.to_hash.should == {
+ :first => 1,
+ :second => {
+ :bar => 'pub',
+ :baz => {
+ :buz => 'random text',
+ :boo => 'who'
+ }
+ },
+ :third => 3
+ }
+ end
+
+ it "just returns an empty hash for an empty configuration" do
+ c = Loquacious::Configuration.new { }
+ c.to_hash.should == {}
end
end
end