summaryrefslogtreecommitdiff
path: root/spec/ruby/library/yaml/shared/load.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/yaml/shared/load.rb')
-rw-r--r--spec/ruby/library/yaml/shared/load.rb24
1 files changed, 15 insertions, 9 deletions
diff --git a/spec/ruby/library/yaml/shared/load.rb b/spec/ruby/library/yaml/shared/load.rb
index 185a5a60cd..7e5669f2d0 100644
--- a/spec/ruby/library/yaml/shared/load.rb
+++ b/spec/ruby/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
@@ -58,7 +60,7 @@ describe :yaml_load_safe, shared: true do
else
error = ArgumentError
end
- -> { YAML.send(@method, "key1: value\ninvalid_key") }.should raise_error(error)
+ -> { YAML.send(@method, "key1: value\ninvalid_key") }.should.raise(error)
end
it "accepts symbols" do
@@ -104,7 +106,7 @@ describe :yaml_load_unsafe, shared: true do
Date.new( 2001, 8, 12 ),
Date.new( 2001, 8, 14 ) ]
}
- YAML.send(@method, $complex_key_1).should == expected
+ YAML.send(@method, YAMLSpecs::COMPLEX_KEY_1).should == expected
end
describe "with iso8601 timestamp" do
@@ -115,13 +117,17 @@ describe :yaml_load_unsafe, shared: true do
].should be_computed_by(:usec)
end
- it "rounds values smaller than 1 usec to 0 " do
+ it "rounds values smaller than 1 usec to 0" do
YAML.send(@method, "2011-03-22t23:32:11.000000342222+01:00").usec.should == 0
end
end
it "loads an OpenStruct" do
- require "ostruct"
+ begin
+ require "ostruct"
+ rescue LoadError
+ skip "OpenStruct is not available"
+ end
os = OpenStruct.new("age" => 20, "name" => "John")
loaded = YAML.send(@method, "--- !ruby/object:OpenStruct\ntable:\n :age: 20\n :name: John\n")
loaded.should == os
@@ -131,6 +137,6 @@ describe :yaml_load_unsafe, shared: true do
loaded = YAML.send(@method, "--- !ruby/object:File {}\n")
-> {
loaded.read(1)
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
end