spec/handler_spec.rb in safe_yaml-0.1 vs spec/handler_spec.rb in safe_yaml-0.2
- old
+ new
@@ -1,8 +1,8 @@
require File.join(File.dirname(__FILE__), "spec_helper")
-require "handler"
+require "safe_yaml/handler"
describe SafeYAML::Handler do
let(:handler) { SafeYAML::Handler.new }
let(:parser) { Psych::Parser.new(handler) }
let(:result) { handler.result }
@@ -29,10 +29,31 @@
it "translates valid decimal numbers to floats" do
parser.parse "float: 3.14"
result.should == { "float" => 3.14 }
end
+ it "translates valid true/false values to booleans" do
+ parser.parse <<-YAML
+ - yes
+ - true
+ - no
+ - false
+ YAML
+
+ result.should == [true, true, false, false]
+ end
+
+ it "translates valid nulls to nil" do
+ parser.parse <<-YAML
+ -
+ - ~
+ - null
+ YAML
+
+ result.should == [nil] * 3
+ end
+
it "applies the same transformations to values as to keys" do
parse <<-YAML
string: value
symbol: :value
integer: 1
@@ -102,7 +123,50 @@
bar:
marco: polo
YAML
result.should == { "foo" => { "bar" => { "marco" => "polo" } } }
+ end
+
+ it "deals just fine with aliases and anchors" do
+ parse <<-YAML
+ - &id001 {}
+ - *id001
+ - *id001
+ YAML
+
+ result.should == [{}, {}, {}]
+ end
+
+ it "deals just fine with sections" do
+ parse <<-YAML
+ mysql: &mysql
+ adapter: mysql
+ pool: 30
+ login: &login
+ username: dan
+ password: gobbledygook
+ local: &local
+ <<: *mysql
+ <<: *login
+ host: localhost
+ YAML
+
+ result.should == {
+ "mysql" => {
+ "adapter" => "mysql",
+ "pool" => 30
+ },
+ "login" => {
+ "username" => "dan",
+ "password" => "gobbledygook"
+ },
+ "local" => {
+ "adapter" => "mysql",
+ "pool" => 30,
+ "username" => "dan",
+ "password" => "gobbledygook",
+ "host" => "localhost"
+ }
+ }
end
end