diff --git a/library/yaml/dump_spec.rb b/library/yaml/dump_spec.rb index 3107a8f51d..ea94b2f856 100644 --- a/library/yaml/dump_spec.rb +++ b/library/yaml/dump_spec.rb @@ -1,17 +1,21 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -# TODO: WTF is this using a global? +require 'yaml' + 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 diff --git a/library/yaml/dump_stream_spec.rb b/library/yaml/dump_stream_spec.rb index 9d30fef819..f0578fa800 100644 --- a/library/yaml/dump_stream_spec.rb +++ b/library/yaml/dump_stream_spec.rb @@ -1,5 +1,6 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' + +require 'yaml' describe "YAML.dump_stream" do it "returns a YAML stream containing the objects passed" do diff --git a/library/yaml/fixtures/common.rb b/library/yaml/fixtures/common.rb deleted file mode 100644 index 895213b844..0000000000 --- a/library/yaml/fixtures/common.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'yaml' - -$test_file = tmp("yaml_test_file") -$test_parse_file = __dir__ + "/test_yaml.yml" diff --git a/library/yaml/load_file_spec.rb b/library/yaml/load_file_spec.rb index 2363c08120..4941d0485b 100644 --- a/library/yaml/load_file_spec.rb +++ b/library/yaml/load_file_spec.rb @@ -1,13 +1,18 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' + +require 'yaml' describe "YAML.load_file" do + before :each do + @test_file = tmp("yaml_test_file") + end + after :each do - rm_r $test_file + rm_r @test_file end it "returns a hash" do - File.open($test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) } - YAML.load_file($test_file).should == {"bar"=>2, "car"=>1} + File.open(@test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) } + YAML.load_file(@test_file).should == {"bar"=>2, "car"=>1} end end diff --git a/library/yaml/load_stream_spec.rb b/library/yaml/load_stream_spec.rb index 689653c8cd..31bc862f5e 100644 --- a/library/yaml/load_stream_spec.rb +++ b/library/yaml/load_stream_spec.rb @@ -1,8 +1,9 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' require_relative 'fixtures/strings' require_relative 'shared/each_document' +require 'yaml' + describe "YAML.load_stream" do it_behaves_like :yaml_each_document, :load_stream end diff --git a/library/yaml/parse_file_spec.rb b/library/yaml/parse_file_spec.rb index 8c59a2d7ef..7bffcdc62f 100644 --- a/library/yaml/parse_file_spec.rb +++ b/library/yaml/parse_file_spec.rb @@ -1,8 +1,10 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -describe "YAML#parse_file" do +require 'yaml' + +describe "YAML.parse_file" do it "returns a YAML::Syck::Map object after parsing a YAML file" do - YAML.parse_file($test_parse_file).should be_kind_of(Psych::Nodes::Document) + test_parse_file = fixture __FILE__, "test_yaml.yml" + YAML.parse_file(test_parse_file).should be_kind_of(Psych::Nodes::Document) end end diff --git a/library/yaml/parse_spec.rb b/library/yaml/parse_spec.rb index d5dbfdcee2..37e2b7fa0a 100644 --- a/library/yaml/parse_spec.rb +++ b/library/yaml/parse_spec.rb @@ -1,13 +1,14 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -describe "YAML#parse with an empty string" do +require 'yaml' + +describe "YAML.parse with an empty string" do it "returns false" do YAML.parse('').should be_false end end -describe "YAML#parse" do +describe "YAML.parse" do before :each do @string_yaml = "foo".to_yaml end diff --git a/library/yaml/shared/each_document.rb b/library/yaml/shared/each_document.rb index 999123dc2a..7d32c6001f 100644 --- a/library/yaml/shared/each_document.rb +++ b/library/yaml/shared/each_document.rb @@ -9,7 +9,8 @@ end it "works on files" do - File.open($test_parse_file, "r") do |file| + test_parse_file = fixture __FILE__, "test_yaml.yml" + File.open(test_parse_file, "r") do |file| YAML.send(@method, file) do |doc| doc.should == {"project"=>{"name"=>"RubySpec"}} end diff --git a/library/yaml/shared/load.rb b/library/yaml/shared/load.rb index 185a5a60cd..1ebe08be2c 100644 --- a/library/yaml/shared/load.rb +++ b/library/yaml/shared/load.rb @@ -1,14 +1,16 @@ -require_relative '../fixtures/common' require_relative '../fixtures/strings' +require 'yaml' + describe :yaml_load_safe, shared: true do it "returns a document from current io stream when io provided" do - File.open($test_file, 'w') do |io| + @test_file = tmp("yaml_test_file") + File.open(@test_file, 'w') do |io| YAML.dump( ['badger', 'elephant', 'tiger'], io ) end - File.open($test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger'] + File.open(@test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger'] ensure - rm_r $test_file + rm_r @test_file end it "loads strings" do diff --git a/library/yaml/to_yaml_spec.rb b/library/yaml/to_yaml_spec.rb index 8e80b02cb4..d70ae76d68 100644 --- a/library/yaml/to_yaml_spec.rb +++ b/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