diff options
Diffstat (limited to 'spec/ruby/library/yaml/dump_spec.rb')
| -rw-r--r-- | spec/ruby/library/yaml/dump_spec.rb | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/spec/ruby/library/yaml/dump_spec.rb b/spec/ruby/library/yaml/dump_spec.rb index c3613521e0..97b665d6a5 100644 --- a/spec/ruby/library/yaml/dump_spec.rb +++ b/spec/ruby/library/yaml/dump_spec.rb @@ -1,17 +1,21 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/common', __FILE__) +require_relative '../../spec_helper' + +require 'yaml' -# TODO: WTF is this using a global? describe "YAML.dump" do + before :each do + @test_file = tmp("yaml_test_file") + end + after :each do - rm_r $test_file + 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| + File.open(@test_file, 'w' ) do |io| YAML.dump( ['badger', 'elephant', 'tiger'], io ) end - YAML.load_file($test_file).should == ['badger', 'elephant', 'tiger'] + YAML.load_file(@test_file).should == ['badger', 'elephant', 'tiger'] end it "returns a string containing dumped YAML when no io provided" do @@ -35,9 +39,18 @@ describe "YAML.dump" do end it "dumps an OpenStruct" do - require "ostruct" + begin + require "ostruct" + rescue LoadError + skip "OpenStruct is not available" + end os = OpenStruct.new("age" => 20, "name" => "John") - YAML.dump(os).should match_yaml("--- !ruby/object:OpenStruct\ntable:\n :age: 20\n :name: John\n") + yaml_dump = YAML.dump(os) + + [ + "--- !ruby/object:OpenStruct\nage: 20\nname: John\n", + "--- !ruby/object:OpenStruct\ntable:\n :age: 20\n :name: John\n", + ].should.include?(yaml_dump) end it "dumps a File without any state" do |
