mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
31
spec/ruby/library/rexml/document/add_element_spec.rb
Normal file
31
spec/ruby/library/rexml/document/add_element_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#add_element" do
|
||||
it "adds arg1 with attributes arg2 as root node" do
|
||||
d = REXML::Document.new
|
||||
e = REXML::Element.new("root")
|
||||
d.add_element e
|
||||
d.root.should == e
|
||||
end
|
||||
|
||||
it "sets arg2 as arg1's attributes" do
|
||||
d = REXML::Document.new
|
||||
e = REXML::Element.new("root")
|
||||
attr = {"foo" => "bar"}
|
||||
d.add_element(e,attr)
|
||||
d.root.attributes["foo"].should == attr["foo"]
|
||||
end
|
||||
|
||||
it "accepts a node name as arg1 and adds it as root" do
|
||||
d = REXML::Document.new
|
||||
d.add_element "foo"
|
||||
d.root.name.should == "foo"
|
||||
end
|
||||
|
||||
it "sets arg1's context to the root's context" do
|
||||
d = REXML::Document.new("", {"foo" => "bar"})
|
||||
d.add_element "foo"
|
||||
d.root.context.should == d.context
|
||||
end
|
||||
end
|
57
spec/ruby/library/rexml/document/add_spec.rb
Normal file
57
spec/ruby/library/rexml/document/add_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
# This spec defines Document#add and Document#<<
|
||||
|
||||
describe :rexml_document_add, shared: true do
|
||||
before :each do
|
||||
@doc = REXML::Document.new("<root/>")
|
||||
@decl = REXML::XMLDecl.new("1.0")
|
||||
end
|
||||
|
||||
it "sets document's XML declaration" do
|
||||
@doc.send(@method, @decl)
|
||||
@doc.xml_decl.should == @decl
|
||||
end
|
||||
|
||||
it "inserts XML declaration as first node" do
|
||||
@doc.send(@method, @decl)
|
||||
@doc.children[0].version.should == "1.0"
|
||||
end
|
||||
|
||||
it "overwrites existing XML declaration" do
|
||||
@doc.send(@method, @decl)
|
||||
@doc.send(@method, REXML::XMLDecl.new("2.0"))
|
||||
@doc.xml_decl.version.should == "2.0"
|
||||
end
|
||||
|
||||
it "sets document DocType" do
|
||||
@doc.send(@method, REXML::DocType.new("transitional"))
|
||||
@doc.doctype.name.should == "transitional"
|
||||
end
|
||||
|
||||
it "overwrites existing DocType" do
|
||||
@doc.send(@method, REXML::DocType.new("transitional"))
|
||||
@doc.send(@method, REXML::DocType.new("strict"))
|
||||
@doc.doctype.name.should == "strict"
|
||||
end
|
||||
|
||||
it "adds root node unless it exists" do
|
||||
d = REXML::Document.new("")
|
||||
elem = REXML::Element.new "root"
|
||||
d.send(@method, elem)
|
||||
d.root.should == elem
|
||||
end
|
||||
|
||||
it "refuses to add second root" do
|
||||
lambda { @doc.send(@method, REXML::Element.new("foo")) }.should raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "REXML::Document#add" do
|
||||
it_behaves_like(:rexml_document_add, :add)
|
||||
end
|
||||
|
||||
describe "REXML::Document#<<" do
|
||||
it_behaves_like(:rexml_document_add, :<<)
|
||||
end
|
20
spec/ruby/library/rexml/document/clone_spec.rb
Normal file
20
spec/ruby/library/rexml/document/clone_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
# According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html),
|
||||
# clone's behavior "should be obvious". Apparently "obvious" means cloning
|
||||
# only the attributes and the context of the document, not its children.
|
||||
describe "REXML::Document#clone" do
|
||||
it "clones document attributes" do
|
||||
d = REXML::Document.new("foo")
|
||||
d.attributes["foo"] = "bar"
|
||||
e = d.clone
|
||||
e.attributes.should == d.attributes
|
||||
end
|
||||
|
||||
it "clones document context" do
|
||||
d = REXML::Document.new("foo", {"foo" => "bar"})
|
||||
e = d.clone
|
||||
e.context.should == d.context
|
||||
end
|
||||
end
|
15
spec/ruby/library/rexml/document/doctype_spec.rb
Normal file
15
spec/ruby/library/rexml/document/doctype_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#doctype" do
|
||||
it "returns the doctype" do
|
||||
d = REXML::Document.new
|
||||
dt = REXML::DocType.new("foo")
|
||||
d.add dt
|
||||
d.doctype.should == dt
|
||||
end
|
||||
|
||||
it "returns nil if there's no doctype" do
|
||||
REXML::Document.new.doctype.should == nil
|
||||
end
|
||||
end
|
22
spec/ruby/library/rexml/document/encoding_spec.rb
Normal file
22
spec/ruby/library/rexml/document/encoding_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#encoding" do
|
||||
before :each do
|
||||
@doc = REXML::Document.new
|
||||
end
|
||||
|
||||
it "returns encoding from XML declaration" do
|
||||
@doc.add REXML::XMLDecl.new(nil, "UTF-16", nil)
|
||||
@doc.encoding.should == "UTF-16"
|
||||
end
|
||||
|
||||
it "returns encoding from XML declaration (for UTF-16 as well)" do
|
||||
@doc.add REXML::XMLDecl.new("1.0", "UTF-8", nil)
|
||||
@doc.encoding.should == "UTF-8"
|
||||
end
|
||||
|
||||
it "uses UTF-8 as default encoding" do
|
||||
@doc.encoding.should == "UTF-8"
|
||||
end
|
||||
end
|
16
spec/ruby/library/rexml/document/expanded_name_spec.rb
Normal file
16
spec/ruby/library/rexml/document/expanded_name_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe :document_expanded_name, shared: true do
|
||||
it "returns an empty string for root" do # root nodes have no expanded name
|
||||
REXML::Document.new.send(@method).should == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "REXML::Document#expanded_name" do
|
||||
it_behaves_like(:document_expanded_name, :expanded_name)
|
||||
end
|
||||
|
||||
describe "REXML::Document#name" do
|
||||
it_behaves_like(:document_expanded_name, :name)
|
||||
end
|
36
spec/ruby/library/rexml/document/new_spec.rb
Normal file
36
spec/ruby/library/rexml/document/new_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require 'rexml/document'
|
||||
|
||||
describe "REXML::Document#new" do
|
||||
|
||||
it "initializes context of {} unless specified" do
|
||||
d = REXML::Document.new("<foo />")
|
||||
d.context.should == {}
|
||||
end
|
||||
|
||||
it "has empty attributes if source is nil" do
|
||||
d = REXML::Document.new(nil)
|
||||
d.elements.should be_empty
|
||||
end
|
||||
|
||||
it "can use other document context" do
|
||||
s = REXML::Document.new("")
|
||||
d = REXML::Document.new(s)
|
||||
d.context.should == s.context
|
||||
end
|
||||
|
||||
it "clones source attributes" do
|
||||
s = REXML::Document.new("<root />")
|
||||
s.attributes["some_attr"] = "some_val"
|
||||
d = REXML::Document.new(s)
|
||||
d.attributes.should == s.attributes
|
||||
end
|
||||
|
||||
it "raises an error if source is not a Document, String or IO" do
|
||||
lambda {REXML::Document.new(3)}.should raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "does not perform XML validation" do
|
||||
REXML::Document.new("Invalid document").should be_kind_of(REXML::Document)
|
||||
end
|
||||
end
|
8
spec/ruby/library/rexml/document/node_type_spec.rb
Normal file
8
spec/ruby/library/rexml/document/node_type_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#node_type" do
|
||||
it "returns :document" do
|
||||
REXML::Document.new.node_type.should == :document
|
||||
end
|
||||
end
|
12
spec/ruby/library/rexml/document/root_spec.rb
Normal file
12
spec/ruby/library/rexml/document/root_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#root" do
|
||||
it "returns document root tag name" do
|
||||
REXML::Document.new("<foo/>").root.name.should == "foo"
|
||||
end
|
||||
|
||||
it "returns nil if there is not root" do
|
||||
REXML::Document.new.root.should == nil
|
||||
end
|
||||
end
|
19
spec/ruby/library/rexml/document/stand_alone_spec.rb
Normal file
19
spec/ruby/library/rexml/document/stand_alone_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#stand_alone?" do
|
||||
it "returns the XMLDecl standalone value" do
|
||||
d = REXML::Document.new
|
||||
decl = REXML::XMLDecl.new("1.0", "UTF-8", "yes")
|
||||
d.add decl
|
||||
d.stand_alone?.should == "yes"
|
||||
end
|
||||
|
||||
# According to the docs this should return the default XMLDecl but that
|
||||
# will carry some more problems when printing the document. Currently, it
|
||||
# returns nil. See http://www.ruby-forum.com/topic/146812#650061
|
||||
it "returns the default value when no XML declaration present" do
|
||||
REXML::Document.new.stand_alone?.should == nil
|
||||
end
|
||||
|
||||
end
|
14
spec/ruby/library/rexml/document/version_spec.rb
Normal file
14
spec/ruby/library/rexml/document/version_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#version" do
|
||||
it "returns XML version from declaration" do
|
||||
d = REXML::Document.new
|
||||
d.add REXML::XMLDecl.new("1.1")
|
||||
d.version.should == "1.1"
|
||||
end
|
||||
|
||||
it "returns the default version when declaration is not present" do
|
||||
REXML::Document.new.version.should == REXML::XMLDecl::DEFAULT_VERSION
|
||||
end
|
||||
end
|
35
spec/ruby/library/rexml/document/write_spec.rb
Normal file
35
spec/ruby/library/rexml/document/write_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'rexml/document'
|
||||
require 'rexml/formatters/transitive'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
# Maybe this can be cleaned
|
||||
describe "REXML::Document#write" do
|
||||
before :each do
|
||||
@d = REXML::Document.new
|
||||
city = REXML::Element.new "Springfield"
|
||||
street = REXML::Element.new "EvergreenTerrace"
|
||||
address = REXML::Element.new "House742"
|
||||
@d << city << street << address
|
||||
@str = ""
|
||||
end
|
||||
|
||||
it "returns document source as string" do
|
||||
@d.write(@str)
|
||||
@str.should == "<Springfield><EvergreenTerrace><House742/></EvergreenTerrace></Springfield>"
|
||||
end
|
||||
|
||||
it "returns document indented" do
|
||||
@d.write(@str, 2)
|
||||
@str.should =~ /\s*<Springfield>\s*<EvergreenTerrace>\s*<House742\/>\s*<\/EvergreenTerrace>\s*<\/Springfield>/
|
||||
end
|
||||
|
||||
it "returns document with transitive support" do
|
||||
@d.write(@str, 2, true)
|
||||
@str.should =~ /\s*<Springfield\s*><EvergreenTerrace\s*><House742\s*\/><\/EvergreenTerrace\s*><\/Springfield\s*>/
|
||||
end
|
||||
|
||||
it "returns document with support for IE" do
|
||||
@d.write(@str, -1, false, true)
|
||||
@str.should == "<Springfield><EvergreenTerrace><House742 /></EvergreenTerrace></Springfield>"
|
||||
end
|
||||
end
|
15
spec/ruby/library/rexml/document/xml_decl_spec.rb
Normal file
15
spec/ruby/library/rexml/document/xml_decl_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'rexml/document'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
describe "REXML::Document#xml_decl" do
|
||||
it "returns XML declaration of the document" do
|
||||
d = REXML::Document.new
|
||||
decl = REXML::XMLDecl.new("1.0", "UTF-16", "yes")
|
||||
d.add decl
|
||||
d.xml_decl.should == decl
|
||||
end
|
||||
|
||||
it "returns default XML declaration unless present" do
|
||||
REXML::Document.new.xml_decl.should == REXML::XMLDecl.new
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue