summaryrefslogtreecommitdiff
path: root/spec/ruby/library/yaml
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/yaml')
-rw-r--r--spec/ruby/library/yaml/dump_spec.rb6
-rw-r--r--spec/ruby/library/yaml/fixtures/strings.rb56
-rw-r--r--spec/ruby/library/yaml/load_stream_spec.rb20
-rw-r--r--spec/ruby/library/yaml/parse_file_spec.rb2
-rw-r--r--spec/ruby/library/yaml/parse_spec.rb2
-rw-r--r--spec/ruby/library/yaml/shared/each_document.rb19
-rw-r--r--spec/ruby/library/yaml/shared/load.rb14
-rw-r--r--spec/ruby/library/yaml/to_yaml_spec.rb20
8 files changed, 67 insertions, 72 deletions
diff --git a/spec/ruby/library/yaml/dump_spec.rb b/spec/ruby/library/yaml/dump_spec.rb
index ea94b2f856..97b665d6a5 100644
--- a/spec/ruby/library/yaml/dump_spec.rb
+++ b/spec/ruby/library/yaml/dump_spec.rb
@@ -39,7 +39,11 @@ 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 = YAML.dump(os)
diff --git a/spec/ruby/library/yaml/fixtures/strings.rb b/spec/ruby/library/yaml/fixtures/strings.rb
index 6f66dc3659..f478f89823 100644
--- a/spec/ruby/library/yaml/fixtures/strings.rb
+++ b/spec/ruby/library/yaml/fixtures/strings.rb
@@ -1,36 +1,26 @@
-$complex_key_1 = <<EOY
- ? # PLAY SCHEDULE
- - Detroit Tigers
- - Chicago Cubs
- :
- - 2001-07-23
+module YAMLSpecs
+ COMPLEX_KEY_1 = <<~EOY
+ ? # PLAY SCHEDULE
+ - Detroit Tigers
+ - Chicago Cubs
+ :
+ - 2001-07-23
- ? [ New York Yankees,
- Atlanta Braves ]
- : [ 2001-07-02, 2001-08-12,
- 2001-08-14 ]
-EOY
+ ? [ New York Yankees,
+ Atlanta Braves ]
+ : [ 2001-07-02, 2001-08-12,
+ 2001-08-14 ]
+ EOY
-$to_yaml_hash =
-<<EOY
--
- avg: 0.278
- hr: 65
- name: Mark McGwire
--
- avg: 0.288
- hr: 63
- name: Sammy Sosa
-EOY
+ MULTIDOCUMENT = <<~EOY
+ ---
+ - Mark McGwire
+ - Sammy Sosa
+ - Ken Griffey
-$multidocument = <<EOY
----
-- Mark McGwire
-- Sammy Sosa
-- Ken Griffey
-
-# Team ranking
----
-- Chicago Cubs
-- St Louis Cardinals
-EOY
+ # Team ranking
+ ---
+ - Chicago Cubs
+ - St Louis Cardinals
+ EOY
+end
diff --git a/spec/ruby/library/yaml/load_stream_spec.rb b/spec/ruby/library/yaml/load_stream_spec.rb
index 31bc862f5e..5f5d4c7337 100644
--- a/spec/ruby/library/yaml/load_stream_spec.rb
+++ b/spec/ruby/library/yaml/load_stream_spec.rb
@@ -1,9 +1,23 @@
require_relative '../../spec_helper'
require_relative 'fixtures/strings'
-require_relative 'shared/each_document'
-
require 'yaml'
describe "YAML.load_stream" do
- it_behaves_like :yaml_each_document, :load_stream
+ it "calls the block on each successive document" do
+ documents = []
+ YAML.load_stream(YAMLSpecs::MULTIDOCUMENT) do |doc|
+ documents << doc
+ end
+ documents.should == [["Mark McGwire", "Sammy Sosa", "Ken Griffey"],
+ ["Chicago Cubs", "St Louis Cardinals"]]
+ end
+
+ it "works on files" do
+ test_parse_file = fixture __FILE__, "test_yaml.yml"
+ File.open(test_parse_file, "r") do |file|
+ YAML.load_stream(file) do |doc|
+ doc.should == {"project"=>{"name"=>"RubySpec"}}
+ end
+ end
+ end
end
diff --git a/spec/ruby/library/yaml/parse_file_spec.rb b/spec/ruby/library/yaml/parse_file_spec.rb
index 7bffcdc62f..a29377f163 100644
--- a/spec/ruby/library/yaml/parse_file_spec.rb
+++ b/spec/ruby/library/yaml/parse_file_spec.rb
@@ -5,6 +5,6 @@ require 'yaml'
describe "YAML.parse_file" do
it "returns a YAML::Syck::Map object after parsing a YAML file" do
test_parse_file = fixture __FILE__, "test_yaml.yml"
- YAML.parse_file(test_parse_file).should be_kind_of(Psych::Nodes::Document)
+ YAML.parse_file(test_parse_file).should.is_a?(Psych::Nodes::Document)
end
end
diff --git a/spec/ruby/library/yaml/parse_spec.rb b/spec/ruby/library/yaml/parse_spec.rb
index 37e2b7fa0a..832cd99d03 100644
--- a/spec/ruby/library/yaml/parse_spec.rb
+++ b/spec/ruby/library/yaml/parse_spec.rb
@@ -4,7 +4,7 @@ require 'yaml'
describe "YAML.parse with an empty string" do
it "returns false" do
- YAML.parse('').should be_false
+ YAML.parse('').should == false
end
end
diff --git a/spec/ruby/library/yaml/shared/each_document.rb b/spec/ruby/library/yaml/shared/each_document.rb
deleted file mode 100644
index 7d32c6001f..0000000000
--- a/spec/ruby/library/yaml/shared/each_document.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-describe :yaml_each_document, shared: true do
- it "calls the block on each successive document" do
- documents = []
- YAML.send(@method, $multidocument) do |doc|
- documents << doc
- end
- documents.should == [["Mark McGwire", "Sammy Sosa", "Ken Griffey"],
- ["Chicago Cubs", "St Louis Cardinals"]]
- end
-
- it "works on files" do
- 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
- end
- end
-end
diff --git a/spec/ruby/library/yaml/shared/load.rb b/spec/ruby/library/yaml/shared/load.rb
index 1ebe08be2c..7e5669f2d0 100644
--- a/spec/ruby/library/yaml/shared/load.rb
+++ b/spec/ruby/library/yaml/shared/load.rb
@@ -60,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
@@ -106,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
@@ -117,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
@@ -133,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
diff --git a/spec/ruby/library/yaml/to_yaml_spec.rb b/spec/ruby/library/yaml/to_yaml_spec.rb
index 547009c942..328ab25552 100644
--- a/spec/ruby/library/yaml/to_yaml_spec.rb
+++ b/spec/ruby/library/yaml/to_yaml_spec.rb
@@ -32,25 +32,25 @@ describe "Object#to_yaml" do
it "returns the YAML representation of a FalseClass" do
false_klass = false
- false_klass.should be_kind_of(FalseClass)
+ false_klass.should.is_a?(FalseClass)
false_klass.to_yaml.should match_yaml("--- false\n")
end
it "returns the YAML representation of a Float object" do
float = 1.2
- float.should be_kind_of(Float)
+ float.should.is_a?(Float)
float.to_yaml.should match_yaml("--- 1.2\n")
end
it "returns the YAML representation of an Integer object" do
int = 20
- int.should be_kind_of(Integer)
+ int.should.is_a?(Integer)
int.to_yaml.should match_yaml("--- 20\n")
end
it "returns the YAML representation of a NilClass object" do
nil_klass = nil
- nil_klass.should be_kind_of(NilClass)
+ nil_klass.should.is_a?(NilClass)
nil_klass.to_yaml.should match_yaml("--- \n")
end
@@ -65,6 +65,8 @@ describe "Object#to_yaml" do
it "returns the YAML representation of a Struct object" do
Person = Struct.new(:name, :gender)
Person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct:Person\nname: Jane\ngender: female\n")
+ ensure
+ Object.send(:remove_const, :Person)
end
it "returns the YAML representation of an unnamed Struct object" do
@@ -82,7 +84,7 @@ describe "Object#to_yaml" do
it "returns the YAML representation of a TrueClass" do
true_klass = true
- true_klass.should be_kind_of(TrueClass)
+ true_klass.should.is_a?(TrueClass)
true_klass.to_yaml.should match_yaml("--- true\n")
end
@@ -92,10 +94,10 @@ describe "Object#to_yaml" do
it "returns the YAML representation for Range objects" do
yaml = Range.new(1,3).to_yaml
- yaml.include?("!ruby/range").should be_true
- yaml.include?("begin: 1").should be_true
- yaml.include?("end: 3").should be_true
- yaml.include?("excl: false").should be_true
+ yaml.include?("!ruby/range").should == true
+ yaml.include?("begin: 1").should == true
+ yaml.include?("end: 3").should == true
+ yaml.include?("excl: false").should == true
end
it "returns the YAML representation of numeric constants" do