summaryrefslogtreecommitdiff
path: root/spec/ruby/library/yaml/dump_spec.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
commit1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch)
treea3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/yaml/dump_spec.rb
parent75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff)
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/yaml/dump_spec.rb')
-rw-r--r--spec/ruby/library/yaml/dump_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/ruby/library/yaml/dump_spec.rb b/spec/ruby/library/yaml/dump_spec.rb
new file mode 100644
index 0000000000..c3613521e0
--- /dev/null
+++ b/spec/ruby/library/yaml/dump_spec.rb
@@ -0,0 +1,51 @@
+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__)
+ begin
+ YAML.dump(file).should match_yaml("--- !ruby/object:File {}\n")
+ ensure
+ file.close
+ end
+ end
+end