spec/as_hash_spec.rb in mostash-0.0.5 vs spec/as_hash_spec.rb in mostash-0.1.0
- old
+ new
@@ -15,10 +15,22 @@
mo.to_hash.should == { :foo => 'bar', :nested => { :hello => 'world' } }
end
end
context 'initialization' do
+ it "should support initializtion from default value" do
+ mo = Mostash.new 123
+
+ mo.doesnt_exist.should == 123
+ end
+
+ it "should support initialzation from default proc" do
+ mo = Mostash.new { |hash, key| hash[key] = "Go Fish: #{key}" }
+
+ mo.doesnt_exist.should == "Go Fish: doesnt_exist"
+ end
+
it "should support initialzation from hash with default value" do
mo = Mostash.new(Hash.new(123))
mo.doesnt_exist.should == 123
end
@@ -82,9 +94,18 @@
vals[0].should == :a
vals[1].should == :b
end
context 'merge' do
+ it "should not change without bang" do
+ mo = MoStash.new :foo => 'bar', :hello => 'world'
+
+ new_mo = mo.merge( :hello => 'tester' )
+
+ new_mo.hello.should == 'tester'
+ mo.hello.should == 'world'
+ end
+
it "should support merge when single level" do
mo = MoStash.new :foo => 'bar', :hello => 'world'
new_mo = mo.merge( :hello => 'tester' )