diff options
Diffstat (limited to 'spec/ruby/library/yaml/to_yaml_spec.rb')
-rw-r--r-- | spec/ruby/library/yaml/to_yaml_spec.rb | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/spec/ruby/library/yaml/to_yaml_spec.rb b/spec/ruby/library/yaml/to_yaml_spec.rb index 03ec4f6916..547009c942 100644 --- a/spec/ruby/library/yaml/to_yaml_spec.rb +++ b/spec/ruby/library/yaml/to_yaml_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' require_relative 'fixtures/example_class' +require 'yaml' + describe "Object#to_yaml" do it "returns the YAML representation of an Array object" do @@ -12,13 +13,21 @@ describe "Object#to_yaml" do { "a" => "b"}.to_yaml.should match_yaml("--- \na: b\n") end - it "returns the YAML representation of a Class object" do + it "returns the YAML representation of an object" do YAMLSpecs::Example.new("baz").to_yaml.should match_yaml("--- !ruby/object:YAMLSpecs::Example\nname: baz\n") end + it "returns the YAML representation of a Class object" do + YAMLSpecs::Example.to_yaml.should match_yaml("--- !ruby/class 'YAMLSpecs::Example'\n") + end + + it "returns the YAML representation of a Module object" do + Enumerable.to_yaml.should match_yaml("--- !ruby/module 'Enumerable'\n") + end + it "returns the YAML representation of a Date object" do require 'date' - Date.parse('1997/12/30').to_yaml.should match_yaml("--- 1997-12-30\n") + Date.new(1997, 12, 30).to_yaml.should match_yaml("--- 1997-12-30\n") end it "returns the YAML representation of a FalseClass" do @@ -58,6 +67,11 @@ describe "Object#to_yaml" do Person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct:Person\nname: Jane\ngender: female\n") end + it "returns the YAML representation of an unnamed Struct object" do + person = Struct.new(:name, :gender) + person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct\nname: Jane\ngender: female\n") + end + it "returns the YAML representation of a Symbol object" do :symbol.to_yaml.should match_yaml("--- :symbol\n") end @@ -72,16 +86,8 @@ describe "Object#to_yaml" do true_klass.to_yaml.should match_yaml("--- true\n") end - ruby_version_is ""..."2.7" do - it "returns the YAML representation of a Error object" do - StandardError.new("foobar").to_yaml.should match_yaml("--- !ruby/exception:StandardError\nmessage: foobar\n") - end - end - - ruby_version_is "2.7" do - it "returns the YAML representation of a Error object" do - StandardError.new("foobar").to_yaml.should match_yaml("--- !ruby/exception:StandardError\nmessage: foobar\nbacktrace: \n") - end + it "returns the YAML representation of a Error object" do + StandardError.new("foobar").to_yaml.should match_yaml("--- !ruby/exception:StandardError\nmessage: foobar\nbacktrace: \n") end it "returns the YAML representation for Range objects" do |