mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
95e8c48dd3
* For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
47 lines
1.4 KiB
Ruby
47 lines
1.4 KiB
Ruby
require File.expand_path('../../../spec_helper', __FILE__)
|
|
require File.expand_path('../fixtures/common', __FILE__)
|
|
|
|
# TODO: WTF is this using a global?
|
|
describe "YAML.dump" do
|
|
after :each do
|
|
rm_r $test_file
|
|
end
|
|
|
|
it "converts an object to YAML and write result to io when io provided" do
|
|
File.open($test_file, 'w' ) do |io|
|
|
YAML.dump( ['badger', 'elephant', 'tiger'], io )
|
|
end
|
|
YAML.load_file($test_file).should == ['badger', 'elephant', 'tiger']
|
|
end
|
|
|
|
it "returns a string containing dumped YAML when no io provided" do
|
|
YAML.dump( :locked ).should match_yaml("--- :locked\n")
|
|
end
|
|
|
|
it "returns the same string that #to_yaml on objects" do
|
|
["a", "b", "c"].to_yaml.should == YAML.dump(["a", "b", "c"])
|
|
end
|
|
|
|
it "dumps strings into YAML strings" do
|
|
YAML.dump("str").should match_yaml("--- str\n")
|
|
end
|
|
|
|
it "dumps hashes into YAML key-values" do
|
|
YAML.dump({ "a" => "b" }).should match_yaml("--- \na: b\n")
|
|
end
|
|
|
|
it "dumps Arrays into YAML collection" do
|
|
YAML.dump(["a", "b", "c"]).should match_yaml("--- \n- a\n- b\n- c\n")
|
|
end
|
|
|
|
it "dumps an OpenStruct" do
|
|
require "ostruct"
|
|
os = OpenStruct.new("age" => 20, "name" => "John")
|
|
YAML.dump(os).should match_yaml("--- !ruby/object:OpenStruct\ntable:\n :age: 20\n :name: John\n")
|
|
end
|
|
|
|
it "dumps a File without any state" do
|
|
file = File.new(__FILE__)
|
|
YAML.dump(file).should match_yaml("--- !ruby/object:File {}\n")
|
|
end
|
|
end
|