mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Ignore rexml examples on ruby/spec
This commit is contained in:
parent
83240f315a
commit
e61cab3a36
Notes:
git
2020-01-12 12:29:06 +09:00
104 changed files with 1863 additions and 1551 deletions
|
@ -1,11 +1,14 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#clone" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns a copy of this Attribute" do
|
require 'rexml/document'
|
||||||
orig = REXML::Attribute.new("name", "value&&")
|
|
||||||
orig.should == orig.clone
|
describe "REXML::Attribute#clone" do
|
||||||
orig.clone.to_s.should == orig.to_s
|
it "returns a copy of this Attribute" do
|
||||||
orig.clone.to_string.should == orig.to_string
|
orig = REXML::Attribute.new("name", "value&&")
|
||||||
|
orig.should == orig.clone
|
||||||
|
orig.clone.to_s.should == orig.to_s
|
||||||
|
orig.clone.to_string.should == orig.to_string
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#element" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the parent element" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new "root"
|
|
||||||
|
|
||||||
REXML::Attribute.new("name", "value", e).element.should == e
|
describe "REXML::Attribute#element" do
|
||||||
REXML::Attribute.new("name", "default_constructor").element.should == nil
|
it "returns the parent element" do
|
||||||
end
|
e = REXML::Element.new "root"
|
||||||
end
|
|
||||||
|
REXML::Attribute.new("name", "value", e).element.should == e
|
||||||
describe "REXML::Attribute#element=" do
|
REXML::Attribute.new("name", "default_constructor").element.should == nil
|
||||||
it "sets the parent element" do
|
end
|
||||||
e = REXML::Element.new "root"
|
end
|
||||||
f = REXML::Element.new "temp"
|
|
||||||
a = REXML::Attribute.new("name", "value", e)
|
describe "REXML::Attribute#element=" do
|
||||||
a.element.should == e
|
it "sets the parent element" do
|
||||||
|
e = REXML::Element.new "root"
|
||||||
a.element = f
|
f = REXML::Element.new "temp"
|
||||||
a.element.should == f
|
a = REXML::Attribute.new("name", "value", e)
|
||||||
|
a.element.should == e
|
||||||
|
|
||||||
|
a.element = f
|
||||||
|
a.element.should == f
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#==" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns true if other has equal name and value" do
|
require 'rexml/document'
|
||||||
a1 = REXML::Attribute.new("foo", "bar")
|
|
||||||
a1.should == a1.clone
|
|
||||||
|
|
||||||
a2 = REXML::Attribute.new("foo", "bar")
|
describe "REXML::Attribute#==" do
|
||||||
a1.should == a2
|
it "returns true if other has equal name and value" do
|
||||||
|
a1 = REXML::Attribute.new("foo", "bar")
|
||||||
|
a1.should == a1.clone
|
||||||
|
|
||||||
a3 = REXML::Attribute.new("foo", "bla")
|
a2 = REXML::Attribute.new("foo", "bar")
|
||||||
a1.should_not == a3
|
a1.should == a2
|
||||||
|
|
||||||
a4 = REXML::Attribute.new("baz", "bar")
|
a3 = REXML::Attribute.new("foo", "bla")
|
||||||
a1.should_not == a4
|
a1.should_not == a3
|
||||||
|
|
||||||
|
a4 = REXML::Attribute.new("baz", "bar")
|
||||||
|
a1.should_not == a4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#hash" do
|
ruby_version_is ''...'2.8' do
|
||||||
# These are not really complete, any idea on how to make them more
|
require 'rexml/document'
|
||||||
# "testable" will be appreciated.
|
|
||||||
it "returns a hashcode made of the name and value of self" do
|
describe "REXML::Attribute#hash" do
|
||||||
a = REXML::Attribute.new("name", "value")
|
# These are not really complete, any idea on how to make them more
|
||||||
a.hash.should be_kind_of(Numeric)
|
# "testable" will be appreciated.
|
||||||
b = REXML::Attribute.new(a)
|
it "returns a hashcode made of the name and value of self" do
|
||||||
a.hash.should == b.hash
|
a = REXML::Attribute.new("name", "value")
|
||||||
|
a.hash.should be_kind_of(Numeric)
|
||||||
|
b = REXML::Attribute.new(a)
|
||||||
|
a.hash.should == b.hash
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +1,32 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#initialize" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new "root"
|
|
||||||
@name = REXML::Attribute.new("name", "Nicko")
|
|
||||||
@e.add_attribute @name
|
|
||||||
end
|
|
||||||
|
|
||||||
it "receives two strings for name and value" do
|
describe "REXML::Attribute#initialize" do
|
||||||
@e.attributes["name"].should == "Nicko"
|
before :each do
|
||||||
@e.add_attribute REXML::Attribute.new("last_name", nil)
|
@e = REXML::Element.new "root"
|
||||||
@e.attributes["last_name"].should == ""
|
@name = REXML::Attribute.new("name", "Nicko")
|
||||||
end
|
@e.add_attribute @name
|
||||||
|
end
|
||||||
|
|
||||||
it "receives an Attribute and clones it" do
|
it "receives two strings for name and value" do
|
||||||
copy = REXML::Attribute.new(@name)
|
@e.attributes["name"].should == "Nicko"
|
||||||
copy.should == @name
|
@e.add_attribute REXML::Attribute.new("last_name", nil)
|
||||||
end
|
@e.attributes["last_name"].should == ""
|
||||||
|
end
|
||||||
|
|
||||||
it "receives a parent node" do
|
it "receives an Attribute and clones it" do
|
||||||
last_name = REXML::Attribute.new("last_name", "McBrain", @e)
|
copy = REXML::Attribute.new(@name)
|
||||||
last_name.element.should == @e
|
copy.should == @name
|
||||||
|
end
|
||||||
|
|
||||||
last_name = REXML::Attribute.new(@name, @e)
|
it "receives a parent node" do
|
||||||
last_name.element.should == @e
|
last_name = REXML::Attribute.new("last_name", "McBrain", @e)
|
||||||
|
last_name.element.should == @e
|
||||||
|
|
||||||
|
last_name = REXML::Attribute.new(@name, @e)
|
||||||
|
last_name.element.should == @e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#inspect" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the name and value as a string" do
|
require 'rexml/document'
|
||||||
a = REXML::Attribute.new("my_name", "my_value")
|
|
||||||
a.inspect.should == "my_name='my_value'"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "accepts attributes with no value" do
|
describe "REXML::Attribute#inspect" do
|
||||||
a = REXML::Attribute.new("my_name")
|
it "returns the name and value as a string" do
|
||||||
a.inspect.should == "my_name=''"
|
a = REXML::Attribute.new("my_name", "my_value")
|
||||||
end
|
a.inspect.should == "my_name='my_value'"
|
||||||
|
end
|
||||||
|
|
||||||
it "does not escape text" do
|
it "accepts attributes with no value" do
|
||||||
a = REXML::Attribute.new("name", "<>")
|
a = REXML::Attribute.new("my_name")
|
||||||
a.inspect.should == "name='<>'"
|
a.inspect.should == "my_name=''"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not escape text" do
|
||||||
|
a = REXML::Attribute.new("name", "<>")
|
||||||
|
a.inspect.should == "name='<>'"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#namespace" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the namespace url" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new("root")
|
|
||||||
e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
|
||||||
e.namespace("ns").should == "http://some_uri"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns nil if namespace is not defined" do
|
describe "REXML::Attribute#namespace" do
|
||||||
e = REXML::Element.new("root")
|
it "returns the namespace url" do
|
||||||
e.add_attribute REXML::Attribute.new("test", "value")
|
e = REXML::Element.new("root")
|
||||||
e.namespace("test").should == nil
|
e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
||||||
e.namespace("ns").should == nil
|
e.namespace("ns").should == "http://some_uri"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "defaults arg to nil" do
|
it "returns nil if namespace is not defined" do
|
||||||
e = REXML::Element.new("root")
|
e = REXML::Element.new("root")
|
||||||
e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
e.add_attribute REXML::Attribute.new("test", "value")
|
||||||
e.namespace.should == ""
|
e.namespace("test").should == nil
|
||||||
e.namespace("ns").should == "http://some_uri"
|
e.namespace("ns").should == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "defaults arg to nil" do
|
||||||
|
e = REXML::Element.new("root")
|
||||||
|
e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
||||||
|
e.namespace.should == ""
|
||||||
|
e.namespace("ns").should == "http://some_uri"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#node_type" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "always returns :attribute" do
|
require 'rexml/document'
|
||||||
attr = REXML::Attribute.new("foo", "bar")
|
|
||||||
attr.node_type.should == :attribute
|
describe "REXML::Attribute#node_type" do
|
||||||
REXML::Attribute.new(attr).node_type.should == :attribute
|
it "always returns :attribute" do
|
||||||
|
attr = REXML::Attribute.new("foo", "bar")
|
||||||
|
attr.node_type.should == :attribute
|
||||||
|
REXML::Attribute.new(attr).node_type.should == :attribute
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#prefix" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the namespace of the Attribute" do
|
require 'rexml/document'
|
||||||
ans = REXML::Attribute.new("ns:someattr", "some_value")
|
|
||||||
out = REXML::Attribute.new("out:something", "some_other_value")
|
|
||||||
|
|
||||||
ans.prefix.should == "ns"
|
describe "REXML::Attribute#prefix" do
|
||||||
out.prefix.should == "out"
|
it "returns the namespace of the Attribute" do
|
||||||
end
|
ans = REXML::Attribute.new("ns:someattr", "some_value")
|
||||||
|
out = REXML::Attribute.new("out:something", "some_other_value")
|
||||||
|
|
||||||
it "returns an empty string for Attributes with no prefixes" do
|
ans.prefix.should == "ns"
|
||||||
attr = REXML::Attribute.new("foo", "bar")
|
out.prefix.should == "out"
|
||||||
|
end
|
||||||
|
|
||||||
attr.prefix.should == ""
|
it "returns an empty string for Attributes with no prefixes" do
|
||||||
|
attr = REXML::Attribute.new("foo", "bar")
|
||||||
|
|
||||||
|
attr.prefix.should == ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#remove" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new "Root"
|
|
||||||
@attr = REXML::Attribute.new("foo", "bar")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes this Attribute from parent" do
|
describe "REXML::Attribute#remove" do
|
||||||
@e.add_attribute(@attr)
|
before :each do
|
||||||
@e.attributes["foo"].should_not == nil
|
@e = REXML::Element.new "Root"
|
||||||
@attr.remove
|
@attr = REXML::Attribute.new("foo", "bar")
|
||||||
@e.attributes["foo"].should == nil
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "does not anything if element has no parent" do
|
it "deletes this Attribute from parent" do
|
||||||
-> {@attr.remove}.should_not raise_error(Exception)
|
@e.add_attribute(@attr)
|
||||||
|
@e.attributes["foo"].should_not == nil
|
||||||
|
@attr.remove
|
||||||
|
@e.attributes["foo"].should == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not anything if element has no parent" do
|
||||||
|
-> {@attr.remove}.should_not raise_error(Exception)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#to_s" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the value of the Attribute" do
|
require 'rexml/document'
|
||||||
REXML::Attribute.new("name", "some_value").to_s.should == "some_value"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the escaped value if it was created from Attribute" do
|
describe "REXML::Attribute#to_s" do
|
||||||
orig = REXML::Attribute.new("name", "<&>")
|
it "returns the value of the Attribute" do
|
||||||
copy = REXML::Attribute.new(orig)
|
REXML::Attribute.new("name", "some_value").to_s.should == "some_value"
|
||||||
copy.to_s.should == "<&>"
|
end
|
||||||
|
|
||||||
|
it "returns the escaped value if it was created from Attribute" do
|
||||||
|
orig = REXML::Attribute.new("name", "<&>")
|
||||||
|
copy = REXML::Attribute.new(orig)
|
||||||
|
copy.to_s.should == "<&>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#to_string" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the attribute as XML" do
|
require 'rexml/document'
|
||||||
attr = REXML::Attribute.new("name", "value")
|
|
||||||
attr_empty = REXML::Attribute.new("name")
|
|
||||||
attr_ns = REXML::Attribute.new("xmlns:ns", "http://uri")
|
|
||||||
|
|
||||||
attr.to_string.should == "name='value'"
|
describe "REXML::Attribute#to_string" do
|
||||||
attr_empty.to_string.should == "name=''"
|
it "returns the attribute as XML" do
|
||||||
attr_ns.to_string.should == "xmlns:ns='http://uri'"
|
attr = REXML::Attribute.new("name", "value")
|
||||||
|
attr_empty = REXML::Attribute.new("name")
|
||||||
|
attr_ns = REXML::Attribute.new("xmlns:ns", "http://uri")
|
||||||
|
|
||||||
|
attr.to_string.should == "name='value'"
|
||||||
|
attr_empty.to_string.should == "name=''"
|
||||||
|
attr_ns.to_string.should == "xmlns:ns='http://uri'"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#value" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the value of the Attribute unnormalized" do
|
require 'rexml/document'
|
||||||
attr = REXML::Attribute.new("name", "value")
|
|
||||||
attr_ents = REXML::Attribute.new("name", "<&>")
|
|
||||||
attr_empty = REXML::Attribute.new("name")
|
|
||||||
|
|
||||||
attr.value.should == "value"
|
describe "REXML::Attribute#value" do
|
||||||
attr_ents.value.should == "<&>"
|
it "returns the value of the Attribute unnormalized" do
|
||||||
attr_empty.value.should == ""
|
attr = REXML::Attribute.new("name", "value")
|
||||||
|
attr_ents = REXML::Attribute.new("name", "<&>")
|
||||||
|
attr_empty = REXML::Attribute.new("name")
|
||||||
|
|
||||||
|
attr.value.should == "value"
|
||||||
|
attr_ents.value.should == "<&>"
|
||||||
|
attr_empty.value.should == ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#write" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@attr = REXML::Attribute.new("name", "Charlotte")
|
|
||||||
@s = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
it "writes the name and value to output" do
|
describe "REXML::Attribute#write" do
|
||||||
@attr.write(@s)
|
before :each do
|
||||||
@s.should == "name='Charlotte'"
|
@attr = REXML::Attribute.new("name", "Charlotte")
|
||||||
end
|
@s = ""
|
||||||
|
end
|
||||||
|
|
||||||
it "currently ignores the second argument" do
|
it "writes the name and value to output" do
|
||||||
@attr.write(@s, 3)
|
@attr.write(@s)
|
||||||
@s.should == "name='Charlotte'"
|
@s.should == "name='Charlotte'"
|
||||||
|
end
|
||||||
|
|
||||||
@s = ""
|
it "currently ignores the second argument" do
|
||||||
@attr.write(@s, "foo")
|
@attr.write(@s, 3)
|
||||||
@s.should == "name='Charlotte'"
|
@s.should == "name='Charlotte'"
|
||||||
|
|
||||||
|
@s = ""
|
||||||
|
@attr.write(@s, "foo")
|
||||||
|
@s.should == "name='Charlotte'"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attribute#xpath" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
before :each do
|
describe "REXML::Attribute#xpath" do
|
||||||
@e = REXML::Element.new "root"
|
|
||||||
@attr = REXML::Attribute.new("year", "1989")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the path for Attribute" do
|
before :each do
|
||||||
@e.add_attribute @attr
|
@e = REXML::Element.new "root"
|
||||||
@attr.xpath.should == "root/@year"
|
@attr = REXML::Attribute.new("year", "1989")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error if attribute has no parent" do
|
it "returns the path for Attribute" do
|
||||||
-> { @attr.xpath }.should raise_error(Exception)
|
@e.add_attribute @attr
|
||||||
|
@attr.xpath.should == "root/@year"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an error if attribute has no parent" do
|
||||||
|
-> { @attr.xpath }.should raise_error(Exception)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require_relative 'shared/add'
|
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#add" do
|
ruby_version_is ''...'2.8' do
|
||||||
it_behaves_like :rexml_attribute_add, :add
|
require_relative 'shared/add'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
describe "REXML::Attributes#add" do
|
||||||
|
it_behaves_like :rexml_attribute_add, :add
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require_relative 'shared/add'
|
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#<<" do
|
ruby_version_is ''...'2.8' do
|
||||||
it_behaves_like :rexml_attribute_add, :<<
|
require_relative 'shared/add'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
describe "REXML::Attributes#<<" do
|
||||||
|
it_behaves_like :rexml_attribute_add, :<<
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#delete_all" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes all attributes that match name" do
|
describe "REXML::Attributes#delete_all" do
|
||||||
uri = REXML::Attribute.new("uri", "http://something")
|
before :each do
|
||||||
@e.attributes << uri
|
@e = REXML::Element.new("root")
|
||||||
@e.attributes.delete_all("uri")
|
end
|
||||||
@e.attributes.should be_empty
|
|
||||||
@e.attributes["uri"].should == nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes all attributes that match name with a namespace" do
|
it "deletes all attributes that match name" do
|
||||||
ns_uri = REXML::Attribute.new("xmlns:uri", "http://something_here_too")
|
uri = REXML::Attribute.new("uri", "http://something")
|
||||||
@e.attributes << ns_uri
|
@e.attributes << uri
|
||||||
@e.attributes.delete_all("xmlns:uri")
|
@e.attributes.delete_all("uri")
|
||||||
@e.attributes.should be_empty
|
@e.attributes.should be_empty
|
||||||
@e.attributes["xmlns:uri"].should == nil
|
@e.attributes["uri"].should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the removed attribute" do
|
it "deletes all attributes that match name with a namespace" do
|
||||||
uri = REXML::Attribute.new("uri", "http://something_here_too")
|
ns_uri = REXML::Attribute.new("xmlns:uri", "http://something_here_too")
|
||||||
@e.attributes << uri
|
@e.attributes << ns_uri
|
||||||
attrs = @e.attributes.delete_all("uri")
|
@e.attributes.delete_all("xmlns:uri")
|
||||||
attrs.first.should == uri
|
@e.attributes.should be_empty
|
||||||
|
@e.attributes["xmlns:uri"].should == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the removed attribute" do
|
||||||
|
uri = REXML::Attribute.new("uri", "http://something_here_too")
|
||||||
|
@e.attributes << uri
|
||||||
|
attrs = @e.attributes.delete_all("uri")
|
||||||
|
attrs.first.should == uri
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#delete" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
@name = REXML::Attribute.new("name", "Pepe")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "takes an attribute name and deletes the attribute" do
|
describe "REXML::Attributes#delete" do
|
||||||
@e.attributes.delete("name")
|
before :each do
|
||||||
@e.attributes["name"].should be_nil
|
@e = REXML::Element.new("root")
|
||||||
@e.attributes.should be_empty
|
@name = REXML::Attribute.new("name", "Pepe")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "takes an Attribute and deletes it" do
|
it "takes an attribute name and deletes the attribute" do
|
||||||
@e.attributes.delete(@name)
|
@e.attributes.delete("name")
|
||||||
@e.attributes["name"].should be_nil
|
@e.attributes["name"].should be_nil
|
||||||
@e.attributes.should be_empty
|
@e.attributes.should be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the element with the attribute removed" do
|
it "takes an Attribute and deletes it" do
|
||||||
ret_val = @e.attributes.delete(@name)
|
@e.attributes.delete(@name)
|
||||||
ret_val.should == @e
|
@e.attributes["name"].should be_nil
|
||||||
ret_val.attributes.should be_empty
|
@e.attributes.should be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the element with the attribute removed" do
|
||||||
|
ret_val = @e.attributes.delete(@name)
|
||||||
|
ret_val.should == @e
|
||||||
|
ret_val.attributes.should be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#each_attribute" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "iterates over the attributes yielding actual Attribute objects" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new("root")
|
|
||||||
name = REXML::Attribute.new("name", "Joe")
|
|
||||||
ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
|
||||||
e.add_attribute name
|
|
||||||
e.add_attribute ns_uri
|
|
||||||
|
|
||||||
attributes = []
|
describe "REXML::Attributes#each_attribute" do
|
||||||
|
it "iterates over the attributes yielding actual Attribute objects" do
|
||||||
|
e = REXML::Element.new("root")
|
||||||
|
name = REXML::Attribute.new("name", "Joe")
|
||||||
|
ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
||||||
|
e.add_attribute name
|
||||||
|
e.add_attribute ns_uri
|
||||||
|
|
||||||
e.attributes.each_attribute do |attr|
|
attributes = []
|
||||||
attributes << attr
|
|
||||||
|
e.attributes.each_attribute do |attr|
|
||||||
|
attributes << attr
|
||||||
|
end
|
||||||
|
|
||||||
|
attributes = attributes.sort_by {|a| a.name }
|
||||||
|
attributes.first.should == name
|
||||||
|
attributes.last.should == ns_uri
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes = attributes.sort_by {|a| a.name }
|
|
||||||
attributes.first.should == name
|
|
||||||
attributes.last.should == ns_uri
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#each" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
@name = REXML::Attribute.new("name", "Joe")
|
|
||||||
@ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
|
||||||
@e.add_attribute @name
|
|
||||||
@e.add_attribute @ns_uri
|
|
||||||
end
|
|
||||||
|
|
||||||
it "iterates over the attributes yielding expanded-name/value" do
|
describe "REXML::Attributes#each" do
|
||||||
attributes = []
|
before :each do
|
||||||
@e.attributes.each do |attr|
|
@e = REXML::Element.new("root")
|
||||||
attr.should be_kind_of(Array)
|
@name = REXML::Attribute.new("name", "Joe")
|
||||||
attributes << attr
|
@ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri")
|
||||||
|
@e.add_attribute @name
|
||||||
|
@e.add_attribute @ns_uri
|
||||||
|
end
|
||||||
|
|
||||||
|
it "iterates over the attributes yielding expanded-name/value" do
|
||||||
|
attributes = []
|
||||||
|
@e.attributes.each do |attr|
|
||||||
|
attr.should be_kind_of(Array)
|
||||||
|
attributes << attr
|
||||||
|
end
|
||||||
|
attributes = attributes.sort_by {|a| a.first }
|
||||||
|
attributes.first.should == ["name", "Joe"]
|
||||||
|
attributes.last.should == ["xmlns:ns", "http://some_uri"]
|
||||||
end
|
end
|
||||||
attributes = attributes.sort_by {|a| a.first }
|
|
||||||
attributes.first.should == ["name", "Joe"]
|
|
||||||
attributes.last.should == ["xmlns:ns", "http://some_uri"]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#[]" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
@lang = REXML::Attribute.new("language", "english")
|
|
||||||
@e.attributes << @lang
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the value of an attribute" do
|
describe "REXML::Attributes#[]" do
|
||||||
@e.attributes["language"].should == "english"
|
before :each do
|
||||||
end
|
@e = REXML::Element.new("root")
|
||||||
|
@lang = REXML::Attribute.new("language", "english")
|
||||||
|
@e.attributes << @lang
|
||||||
|
end
|
||||||
|
|
||||||
it "returns nil if the attribute does not exist" do
|
it "returns the value of an attribute" do
|
||||||
@e.attributes["chunky bacon"].should == nil
|
@e.attributes["language"].should == "english"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil if the attribute does not exist" do
|
||||||
|
@e.attributes["chunky bacon"].should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#[]=" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("song")
|
|
||||||
@name = REXML::Attribute.new("name", "Holy Smoke!")
|
|
||||||
@e.attributes << @name
|
|
||||||
end
|
|
||||||
|
|
||||||
it "sets an attribute" do
|
describe "REXML::Attributes#[]=" do
|
||||||
@e.attributes["author"] = "_why's foxes"
|
before :each do
|
||||||
@e.attributes["author"].should == "_why's foxes"
|
@e = REXML::Element.new("song")
|
||||||
end
|
@name = REXML::Attribute.new("name", "Holy Smoke!")
|
||||||
|
@e.attributes << @name
|
||||||
|
end
|
||||||
|
|
||||||
it "overwrites an existing attribute" do
|
it "sets an attribute" do
|
||||||
@e.attributes["name"] = "Chunky Bacon"
|
@e.attributes["author"] = "_why's foxes"
|
||||||
@e.attributes["name"].should == "Chunky Bacon"
|
@e.attributes["author"].should == "_why's foxes"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "deletes an attribute is value is nil" do
|
it "overwrites an existing attribute" do
|
||||||
@e.attributes["name"] = nil
|
@e.attributes["name"] = "Chunky Bacon"
|
||||||
@e.attributes.length.should == 0
|
@e.attributes["name"].should == "Chunky Bacon"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "deletes an attribute is value is nil" do
|
||||||
|
@e.attributes["name"] = nil
|
||||||
|
@e.attributes.length.should == 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#get_attribute_ns" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns an attribute by name and namespace" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new("root")
|
|
||||||
attr = REXML::Attribute.new("xmlns:ns", "http://some_url")
|
describe "REXML::Attributes#get_attribute_ns" do
|
||||||
e.attributes << attr
|
it "returns an attribute by name and namespace" do
|
||||||
attr.prefix.should == "xmlns"
|
e = REXML::Element.new("root")
|
||||||
# This might be a bug in Attribute, commenting until those specs
|
attr = REXML::Attribute.new("xmlns:ns", "http://some_url")
|
||||||
# are ready
|
e.attributes << attr
|
||||||
# e.attributes.get_attribute_ns(attr.prefix, "name").should == "http://some_url"
|
attr.prefix.should == "xmlns"
|
||||||
|
# This might be a bug in Attribute, commenting until those specs
|
||||||
|
# are ready
|
||||||
|
# e.attributes.get_attribute_ns(attr.prefix, "name").should == "http://some_url"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +1,32 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#get_attribute" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
@name = REXML::Attribute.new("name", "Dave")
|
|
||||||
@e.attributes << @name
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fetches an attributes" do
|
describe "REXML::Attributes#get_attribute" do
|
||||||
@e.attributes.get_attribute("name").should == @name
|
before :each do
|
||||||
end
|
@e = REXML::Element.new("root")
|
||||||
|
@name = REXML::Attribute.new("name", "Dave")
|
||||||
|
@e.attributes << @name
|
||||||
|
end
|
||||||
|
|
||||||
it "fetches an namespaced attribute" do
|
it "fetches an attributes" do
|
||||||
ns_name = REXML::Attribute.new("im:name", "Murray")
|
@e.attributes.get_attribute("name").should == @name
|
||||||
@e.attributes << ns_name
|
end
|
||||||
@e.attributes.get_attribute("name").should == @name
|
|
||||||
@e.attributes.get_attribute("im:name").should == ns_name
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns an Attribute" do
|
it "fetches an namespaced attribute" do
|
||||||
@e.attributes.get_attribute("name").should be_kind_of(REXML::Attribute)
|
ns_name = REXML::Attribute.new("im:name", "Murray")
|
||||||
end
|
@e.attributes << ns_name
|
||||||
|
@e.attributes.get_attribute("name").should == @name
|
||||||
|
@e.attributes.get_attribute("im:name").should == ns_name
|
||||||
|
end
|
||||||
|
|
||||||
it "returns nil if it attribute does not exist" do
|
it "returns an Attribute" do
|
||||||
@e.attributes.get_attribute("fake").should be_nil
|
@e.attributes.get_attribute("name").should be_kind_of(REXML::Attribute)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil if it attribute does not exist" do
|
||||||
|
@e.attributes.get_attribute("fake").should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#initialize" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "is auto initialized by Element" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new "root"
|
|
||||||
e.attributes.should be_kind_of(REXML::Attributes)
|
|
||||||
|
|
||||||
e.attributes << REXML::Attribute.new("name", "Paul")
|
describe "REXML::Attributes#initialize" do
|
||||||
e.attributes["name"].should == "Paul"
|
it "is auto initialized by Element" do
|
||||||
end
|
e = REXML::Element.new "root"
|
||||||
|
e.attributes.should be_kind_of(REXML::Attributes)
|
||||||
|
|
||||||
it "receives a parent node" do
|
e.attributes << REXML::Attribute.new("name", "Paul")
|
||||||
e = REXML::Element.new "root"
|
e.attributes["name"].should == "Paul"
|
||||||
e.attributes << REXML::Attribute.new("name", "Vic")
|
end
|
||||||
e.attributes["name"].should == "Vic"
|
|
||||||
|
it "receives a parent node" do
|
||||||
|
e = REXML::Element.new "root"
|
||||||
|
e.attributes << REXML::Attribute.new("name", "Vic")
|
||||||
|
e.attributes["name"].should == "Vic"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require_relative 'shared/length'
|
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#length" do
|
ruby_version_is ''...'2.8' do
|
||||||
it_behaves_like :rexml_attribute_length, :length
|
require_relative 'shared/length'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
describe "REXML::Attributes#length" do
|
||||||
|
it_behaves_like :rexml_attribute_length, :length
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#namespaces" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "needs to be reviewed for spec completeness"
|
require 'rexml/document'
|
||||||
|
|
||||||
|
describe "REXML::Attributes#namespaces" do
|
||||||
|
it "needs to be reviewed for spec completeness"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#prefixes" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
a1 = REXML::Attribute.new("xmlns:a", "bar")
|
|
||||||
a2 = REXML::Attribute.new("xmlns:b", "bla")
|
|
||||||
a3 = REXML::Attribute.new("xmlns:c", "baz")
|
|
||||||
@e.attributes << a1
|
|
||||||
@e.attributes << a2
|
|
||||||
@e.attributes << a3
|
|
||||||
|
|
||||||
@e.attributes << REXML::Attribute.new("xmlns", "foo")
|
describe "REXML::Attributes#prefixes" do
|
||||||
end
|
before :each do
|
||||||
|
@e = REXML::Element.new("root")
|
||||||
|
a1 = REXML::Attribute.new("xmlns:a", "bar")
|
||||||
|
a2 = REXML::Attribute.new("xmlns:b", "bla")
|
||||||
|
a3 = REXML::Attribute.new("xmlns:c", "baz")
|
||||||
|
@e.attributes << a1
|
||||||
|
@e.attributes << a2
|
||||||
|
@e.attributes << a3
|
||||||
|
|
||||||
it "returns an array with the prefixes of each attribute" do
|
@e.attributes << REXML::Attribute.new("xmlns", "foo")
|
||||||
@e.attributes.prefixes.sort.should == ["a", "b", "c"]
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "does not include the default namespace" do
|
it "returns an array with the prefixes of each attribute" do
|
||||||
@e.attributes.prefixes.include?("xmlns").should == false
|
@e.attributes.prefixes.sort.should == ["a", "b", "c"]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not include the default namespace" do
|
||||||
|
@e.attributes.prefixes.include?("xmlns").should == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require_relative 'shared/length'
|
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#size" do
|
ruby_version_is ''...'2.8' do
|
||||||
it_behaves_like :rexml_attribute_length, :size
|
require_relative 'shared/length'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
describe "REXML::Attributes#size" do
|
||||||
|
it_behaves_like :rexml_attribute_length, :size
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Attributes#to_a" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns an array with the attributes" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new("root")
|
|
||||||
name = REXML::Attribute.new("name", "Dave")
|
|
||||||
last = REXML::Attribute.new("last_name", "Murray")
|
|
||||||
|
|
||||||
e.attributes << name
|
describe "REXML::Attributes#to_a" do
|
||||||
e.attributes << last
|
it "returns an array with the attributes" do
|
||||||
|
e = REXML::Element.new("root")
|
||||||
|
name = REXML::Attribute.new("name", "Dave")
|
||||||
|
last = REXML::Attribute.new("last_name", "Murray")
|
||||||
|
|
||||||
e.attributes.to_a.sort{|a,b|a.to_s<=>b.to_s}.should == [name, last]
|
e.attributes << name
|
||||||
end
|
e.attributes << last
|
||||||
|
|
||||||
it "returns an empty array if it has no attributes" do
|
e.attributes.to_a.sort{|a,b|a.to_s<=>b.to_s}.should == [name, last]
|
||||||
REXML::Element.new("root").attributes.to_a.should == []
|
end
|
||||||
|
|
||||||
|
it "returns an empty array if it has no attributes" do
|
||||||
|
REXML::Element.new("root").attributes.to_a.should == []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::CData#clone" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "makes a copy of itself" do
|
require 'rexml/document'
|
||||||
c = REXML::CData.new("some text")
|
|
||||||
c.clone.to_s.should == c.to_s
|
describe "REXML::CData#clone" do
|
||||||
c.clone.should == c
|
it "makes a copy of itself" do
|
||||||
|
c = REXML::CData.new("some text")
|
||||||
|
c.clone.to_s.should == c.to_s
|
||||||
|
c.clone.should == c
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::CData#initialize" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "creates a new CData object" do
|
require 'rexml/document'
|
||||||
c = REXML::CData.new("some text")
|
|
||||||
c.should be_kind_of(REXML::CData)
|
|
||||||
c.should be_kind_of(REXML::Text)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "respects whitespace if whitespace is true" do
|
describe "REXML::CData#initialize" do
|
||||||
c = REXML::CData.new("whitespace test", true)
|
it "creates a new CData object" do
|
||||||
c1 = REXML::CData.new("whitespace test", false)
|
c = REXML::CData.new("some text")
|
||||||
|
c.should be_kind_of(REXML::CData)
|
||||||
|
c.should be_kind_of(REXML::Text)
|
||||||
|
end
|
||||||
|
|
||||||
c.to_s.should == "whitespace test"
|
it "respects whitespace if whitespace is true" do
|
||||||
c1.to_s.should == "whitespace test"
|
c = REXML::CData.new("whitespace test", true)
|
||||||
end
|
c1 = REXML::CData.new("whitespace test", false)
|
||||||
|
|
||||||
it "receives parent as third argument" do
|
c.to_s.should == "whitespace test"
|
||||||
e = REXML::Element.new("root")
|
c1.to_s.should == "whitespace test"
|
||||||
REXML::CData.new("test", true, e)
|
end
|
||||||
e.to_s.should == "<root><![CDATA[test]]></root>"
|
|
||||||
|
it "receives parent as third argument" do
|
||||||
|
e = REXML::Element.new("root")
|
||||||
|
REXML::CData.new("test", true, e)
|
||||||
|
e.to_s.should == "<root><![CDATA[test]]></root>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require_relative 'shared/to_s'
|
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::CData#to_s" do
|
ruby_version_is ''...'2.8' do
|
||||||
it_behaves_like :rexml_cdata_to_s, :to_s
|
require_relative 'shared/to_s'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
describe "REXML::CData#to_s" do
|
||||||
|
it_behaves_like :rexml_cdata_to_s, :to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require_relative 'shared/to_s'
|
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::CData#value" do
|
ruby_version_is ''...'2.8' do
|
||||||
it_behaves_like :rexml_cdata_to_s, :value
|
require_relative 'shared/to_s'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
describe "REXML::CData#value" do
|
||||||
|
it_behaves_like :rexml_cdata_to_s, :value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#add_element" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "adds arg1 with attributes arg2 as root node" do
|
require 'rexml/document'
|
||||||
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
|
describe "REXML::Document#add_element" do
|
||||||
d = REXML::Document.new
|
it "adds arg1 with attributes arg2 as root node" do
|
||||||
e = REXML::Element.new("root")
|
d = REXML::Document.new
|
||||||
attr = {"foo" => "bar"}
|
e = REXML::Element.new("root")
|
||||||
d.add_element(e,attr)
|
d.add_element e
|
||||||
d.root.attributes["foo"].should == attr["foo"]
|
d.root.should == e
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts a node name as arg1 and adds it as root" do
|
it "sets arg2 as arg1's attributes" do
|
||||||
d = REXML::Document.new
|
d = REXML::Document.new
|
||||||
d.add_element "foo"
|
e = REXML::Element.new("root")
|
||||||
d.root.name.should == "foo"
|
attr = {"foo" => "bar"}
|
||||||
end
|
d.add_element(e,attr)
|
||||||
|
d.root.attributes["foo"].should == attr["foo"]
|
||||||
|
end
|
||||||
|
|
||||||
it "sets arg1's context to the root's context" do
|
it "accepts a node name as arg1 and adds it as root" do
|
||||||
d = REXML::Document.new("", {"foo" => "bar"})
|
d = REXML::Document.new
|
||||||
d.add_element "foo"
|
d.add_element "foo"
|
||||||
d.root.context.should == d.context
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,57 +1,60 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
# This spec defines Document#add and Document#<<
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
describe :rexml_document_add, shared: true do
|
# This spec defines Document#add and Document#<<
|
||||||
before :each do
|
|
||||||
@doc = REXML::Document.new("<root/>")
|
describe :rexml_document_add, shared: true do
|
||||||
@decl = REXML::XMLDecl.new("1.0")
|
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
|
||||||
|
-> { @doc.send(@method, REXML::Element.new("foo")) }.should raise_error(RuntimeError)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets document's XML declaration" do
|
describe "REXML::Document#add" do
|
||||||
@doc.send(@method, @decl)
|
it_behaves_like :rexml_document_add, :add
|
||||||
@doc.xml_decl.should == @decl
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "inserts XML declaration as first node" do
|
describe "REXML::Document#<<" do
|
||||||
@doc.send(@method, @decl)
|
it_behaves_like :rexml_document_add, :<<
|
||||||
@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
|
|
||||||
-> { @doc.send(@method, REXML::Element.new("foo")) }.should raise_error(RuntimeError)
|
|
||||||
end
|
end
|
||||||
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
|
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
# According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html),
|
ruby_version_is ''...'2.8' do
|
||||||
# clone's behavior "should be obvious". Apparently "obvious" means cloning
|
require 'rexml/document'
|
||||||
# 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
|
# According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html),
|
||||||
d = REXML::Document.new("foo", {"foo" => "bar"})
|
# clone's behavior "should be obvious". Apparently "obvious" means cloning
|
||||||
e = d.clone
|
# only the attributes and the context of the document, not its children.
|
||||||
e.context.should == d.context
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#doctype" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the doctype" do
|
require 'rexml/document'
|
||||||
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
|
describe "REXML::Document#doctype" do
|
||||||
REXML::Document.new.doctype.should == nil
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#encoding" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@doc = REXML::Document.new
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns encoding from XML declaration" do
|
describe "REXML::Document#encoding" do
|
||||||
@doc.add REXML::XMLDecl.new(nil, "UTF-16", nil)
|
before :each do
|
||||||
@doc.encoding.should == "UTF-16"
|
@doc = REXML::Document.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns encoding from XML declaration (for UTF-16 as well)" do
|
it "returns encoding from XML declaration" do
|
||||||
@doc.add REXML::XMLDecl.new("1.0", "UTF-8", nil)
|
@doc.add REXML::XMLDecl.new(nil, "UTF-16", nil)
|
||||||
@doc.encoding.should == "UTF-8"
|
@doc.encoding.should == "UTF-16"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses UTF-8 as default encoding" do
|
it "returns encoding from XML declaration (for UTF-16 as well)" do
|
||||||
@doc.encoding.should == "UTF-8"
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe :document_expanded_name, shared: true do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns an empty string for root" do # root nodes have no expanded name
|
require 'rexml/document'
|
||||||
REXML::Document.new.send(@method).should == ""
|
|
||||||
|
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
|
end
|
||||||
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
|
|
||||||
|
|
|
@ -1,36 +1,39 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Document#new" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
it "initializes context of {} unless specified" do
|
describe "REXML::Document#new" do
|
||||||
d = REXML::Document.new("<foo />")
|
|
||||||
d.context.should == {}
|
|
||||||
end
|
|
||||||
|
|
||||||
it "has empty attributes if source is nil" do
|
it "initializes context of {} unless specified" do
|
||||||
d = REXML::Document.new(nil)
|
d = REXML::Document.new("<foo />")
|
||||||
d.elements.should be_empty
|
d.context.should == {}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can use other document context" do
|
it "has empty attributes if source is nil" do
|
||||||
s = REXML::Document.new("")
|
d = REXML::Document.new(nil)
|
||||||
d = REXML::Document.new(s)
|
d.elements.should be_empty
|
||||||
d.context.should == s.context
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "clones source attributes" do
|
it "can use other document context" do
|
||||||
s = REXML::Document.new("<root />")
|
s = REXML::Document.new("")
|
||||||
s.attributes["some_attr"] = "some_val"
|
d = REXML::Document.new(s)
|
||||||
d = REXML::Document.new(s)
|
d.context.should == s.context
|
||||||
d.attributes.should == s.attributes
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "raises an error if source is not a Document, String or IO" do
|
it "clones source attributes" do
|
||||||
-> {REXML::Document.new(3)}.should raise_error(RuntimeError)
|
s = REXML::Document.new("<root />")
|
||||||
end
|
s.attributes["some_attr"] = "some_val"
|
||||||
|
d = REXML::Document.new(s)
|
||||||
|
d.attributes.should == s.attributes
|
||||||
|
end
|
||||||
|
|
||||||
it "does not perform XML validation" do
|
it "raises an error if source is not a Document, String or IO" do
|
||||||
REXML::Document.new("Invalid document").should be_kind_of(REXML::Document)
|
-> {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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#node_type" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns :document" do
|
require 'rexml/document'
|
||||||
REXML::Document.new.node_type.should == :document
|
|
||||||
|
describe "REXML::Document#node_type" do
|
||||||
|
it "returns :document" do
|
||||||
|
REXML::Document.new.node_type.should == :document
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#root" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns document root tag name" do
|
require 'rexml/document'
|
||||||
REXML::Document.new("<foo/>").root.name.should == "foo"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns nil if there is not root" do
|
describe "REXML::Document#root" do
|
||||||
REXML::Document.new.root.should == nil
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#stand_alone?" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the XMLDecl standalone value" do
|
require 'rexml/document'
|
||||||
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
|
describe "REXML::Document#stand_alone?" do
|
||||||
# will carry some more problems when printing the document. Currently, it
|
it "returns the XMLDecl standalone value" do
|
||||||
# returns nil. See http://www.ruby-forum.com/topic/146812#650061
|
d = REXML::Document.new
|
||||||
it "returns the default value when no XML declaration present" do
|
decl = REXML::XMLDecl.new("1.0", "UTF-8", "yes")
|
||||||
REXML::Document.new.stand_alone?.should == nil
|
d.add decl
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#version" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns XML version from declaration" do
|
require 'rexml/document'
|
||||||
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
|
describe "REXML::Document#version" do
|
||||||
REXML::Document.new.version.should == REXML::XMLDecl::DEFAULT_VERSION
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,35 +1,38 @@
|
||||||
require 'rexml/document'
|
|
||||||
require 'rexml/formatters/transitive'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
# Maybe this can be cleaned
|
ruby_version_is ''...'2.8' do
|
||||||
describe "REXML::Document#write" do
|
require 'rexml/document'
|
||||||
before :each do
|
require 'rexml/formatters/transitive'
|
||||||
@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
|
# Maybe this can be cleaned
|
||||||
@d.write(@str)
|
describe "REXML::Document#write" do
|
||||||
@str.should == "<Springfield><EvergreenTerrace><House742/></EvergreenTerrace></Springfield>"
|
before :each do
|
||||||
end
|
@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 indented" do
|
it "returns document source as string" do
|
||||||
@d.write(@str, 2)
|
@d.write(@str)
|
||||||
@str.should =~ /\s*<Springfield>\s*<EvergreenTerrace>\s*<House742\/>\s*<\/EvergreenTerrace>\s*<\/Springfield>/
|
@str.should == "<Springfield><EvergreenTerrace><House742/></EvergreenTerrace></Springfield>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns document with transitive support" do
|
it "returns document indented" do
|
||||||
@d.write(@str, 2, true)
|
@d.write(@str, 2)
|
||||||
@str.should =~ /\s*<Springfield\s*><EvergreenTerrace\s*><House742\s*\/><\/EvergreenTerrace\s*><\/Springfield\s*>/
|
@str.should =~ /\s*<Springfield>\s*<EvergreenTerrace>\s*<House742\/>\s*<\/EvergreenTerrace>\s*<\/Springfield>/
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns document with support for IE" do
|
it "returns document with transitive support" do
|
||||||
@d.write(@str, -1, false, true)
|
@d.write(@str, 2, true)
|
||||||
@str.should == "<Springfield><EvergreenTerrace><House742 /></EvergreenTerrace></Springfield>"
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Document#xml_decl" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns XML declaration of the document" do
|
require 'rexml/document'
|
||||||
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
|
describe "REXML::Document#xml_decl" do
|
||||||
REXML::Document.new.xml_decl.should == REXML::XMLDecl.new
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,41 +1,44 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#add_attribute" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@person = REXML::Element.new "person"
|
|
||||||
@person.attributes["name"] = "Bill"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "adds a new attribute" do
|
describe "REXML::Element#add_attribute" do
|
||||||
@person.add_attribute("age", "17")
|
before :each do
|
||||||
@person.attributes["age"].should == "17"
|
@person = REXML::Element.new "person"
|
||||||
end
|
@person.attributes["name"] = "Bill"
|
||||||
|
end
|
||||||
|
|
||||||
it "overwrites an existing attribute" do
|
it "adds a new attribute" do
|
||||||
@person.add_attribute("name", "Bill")
|
@person.add_attribute("age", "17")
|
||||||
@person.attributes["name"].should == "Bill"
|
@person.attributes["age"].should == "17"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts a pair of strings" do
|
it "overwrites an existing attribute" do
|
||||||
@person.add_attribute("male", "true")
|
@person.add_attribute("name", "Bill")
|
||||||
@person.attributes["male"].should == "true"
|
@person.attributes["name"].should == "Bill"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts an Attribute for key" do
|
it "accepts a pair of strings" do
|
||||||
attr = REXML::Attribute.new("male", "true")
|
@person.add_attribute("male", "true")
|
||||||
@person.add_attribute attr
|
@person.attributes["male"].should == "true"
|
||||||
@person.attributes["male"].should == "true"
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "ignores value if key is an Attribute" do
|
it "accepts an Attribute for key" do
|
||||||
attr = REXML::Attribute.new("male", "true")
|
attr = REXML::Attribute.new("male", "true")
|
||||||
@person.add_attribute(attr, "false")
|
@person.add_attribute attr
|
||||||
@person.attributes["male"].should == "true"
|
@person.attributes["male"].should == "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the attribute added" do
|
it "ignores value if key is an Attribute" do
|
||||||
attr = REXML::Attribute.new("name", "Tony")
|
attr = REXML::Attribute.new("male", "true")
|
||||||
@person.add_attribute(attr).should == attr
|
@person.add_attribute(attr, "false")
|
||||||
|
@person.attributes["male"].should == "true"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the attribute added" do
|
||||||
|
attr = REXML::Attribute.new("name", "Tony")
|
||||||
|
@person.add_attribute(attr).should == attr
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#add_attributes" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@person = REXML::Element.new "person"
|
|
||||||
@person.attributes["name"] = "Bill"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "adds multiple attributes from a hash" do
|
describe "REXML::Element#add_attributes" do
|
||||||
@person.add_attributes({"name" => "Joe", "age" => "27"})
|
before :each do
|
||||||
@person.attributes["name"].should == "Joe"
|
@person = REXML::Element.new "person"
|
||||||
@person.attributes["age"].should == "27"
|
@person.attributes["name"] = "Bill"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds multiple attributes from an array" do
|
it "adds multiple attributes from a hash" do
|
||||||
attrs = { "name" => "Joe", "age" => "27"}
|
@person.add_attributes({"name" => "Joe", "age" => "27"})
|
||||||
@person.add_attributes attrs.to_a
|
@person.attributes["name"].should == "Joe"
|
||||||
@person.attributes["name"].should == "Joe"
|
@person.attributes["age"].should == "27"
|
||||||
@person.attributes["age"].should == "27"
|
end
|
||||||
|
|
||||||
|
it "adds multiple attributes from an array" do
|
||||||
|
attrs = { "name" => "Joe", "age" => "27"}
|
||||||
|
@person.add_attributes attrs.to_a
|
||||||
|
@person.attributes["name"].should == "Joe"
|
||||||
|
@person.attributes["age"].should == "27"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,39 +1,41 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
describe "REXML::Element#add_element" do
|
describe "REXML::Element#add_element" do
|
||||||
before :each do
|
before :each do
|
||||||
@root = REXML::Element.new("root")
|
@root = REXML::Element.new("root")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds a child without attributes" do
|
it "adds a child without attributes" do
|
||||||
name = REXML::Element.new("name")
|
name = REXML::Element.new("name")
|
||||||
@root.add_element name
|
@root.add_element name
|
||||||
@root.elements["name"].name.should == name.name
|
@root.elements["name"].name.should == name.name
|
||||||
@root.elements["name"].attributes.should == name.attributes
|
@root.elements["name"].attributes.should == name.attributes
|
||||||
@root.elements["name"].context.should == name.context
|
@root.elements["name"].context.should == name.context
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds a child with attributes" do
|
it "adds a child with attributes" do
|
||||||
person = REXML::Element.new("person")
|
person = REXML::Element.new("person")
|
||||||
@root.add_element(person, {"name" => "Madonna"})
|
@root.add_element(person, {"name" => "Madonna"})
|
||||||
@root.elements["person"].name.should == person.name
|
@root.elements["person"].name.should == person.name
|
||||||
@root.elements["person"].attributes.should == person.attributes
|
@root.elements["person"].attributes.should == person.attributes
|
||||||
@root.elements["person"].context.should == person.context
|
@root.elements["person"].context.should == person.context
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds a child with name" do
|
it "adds a child with name" do
|
||||||
@root.add_element "name"
|
@root.add_element "name"
|
||||||
@root.elements["name"].name.should == "name"
|
@root.elements["name"].name.should == "name"
|
||||||
@root.elements["name"].attributes.should == {}
|
@root.elements["name"].attributes.should == {}
|
||||||
@root.elements["name"].context.should == nil
|
@root.elements["name"].context.should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the added child" do
|
it "returns the added child" do
|
||||||
name = @root.add_element "name"
|
name = @root.add_element "name"
|
||||||
@root.elements["name"].name.should == name.name
|
@root.elements["name"].name.should == name.name
|
||||||
@root.elements["name"].attributes.should == name.attributes
|
@root.elements["name"].attributes.should == name.attributes
|
||||||
@root.elements["name"].context.should == name.context
|
@root.elements["name"].context.should == name.context
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#add_namespace" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@elem = REXML::Element.new("person")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "adds a namespace to element" do
|
describe "REXML::Element#add_namespace" do
|
||||||
@elem.add_namespace("foo", "bar")
|
before :each do
|
||||||
@elem.namespace("foo").should == "bar"
|
@elem = REXML::Element.new("person")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts a prefix string as prefix" do
|
it "adds a namespace to element" do
|
||||||
@elem.add_namespace("xmlns:foo", "bar")
|
@elem.add_namespace("foo", "bar")
|
||||||
@elem.namespace("foo").should == "bar"
|
@elem.namespace("foo").should == "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses prefix as URI if uri is nil" do
|
it "accepts a prefix string as prefix" do
|
||||||
@elem.add_namespace("some_uri", nil)
|
@elem.add_namespace("xmlns:foo", "bar")
|
||||||
@elem.namespace.should == "some_uri"
|
@elem.namespace("foo").should == "bar"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "uses prefix as URI if uri is nil" do
|
||||||
|
@elem.add_namespace("some_uri", nil)
|
||||||
|
@elem.namespace.should == "some_uri"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#add_text" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@name = REXML::Element.new "Name"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "adds text to an element" do
|
describe "REXML::Element#add_text" do
|
||||||
@name.add_text "Ringo"
|
before :each do
|
||||||
@name.to_s.should == "<Name>Ringo</Name>"
|
@name = REXML::Element.new "Name"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts a Text" do
|
it "adds text to an element" do
|
||||||
@name.add_text(REXML::Text.new("Ringo"))
|
@name.add_text "Ringo"
|
||||||
@name.to_s.should == "<Name>Ringo</Name>"
|
@name.to_s.should == "<Name>Ringo</Name>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "joins the new text with the old one" do
|
it "accepts a Text" do
|
||||||
@name.add_text "Ringo"
|
@name.add_text(REXML::Text.new("Ringo"))
|
||||||
@name.add_text " Starr"
|
@name.to_s.should == "<Name>Ringo</Name>"
|
||||||
@name.to_s.should == "<Name>Ringo Starr</Name>"
|
end
|
||||||
|
|
||||||
|
it "joins the new text with the old one" do
|
||||||
|
@name.add_text "Ringo"
|
||||||
|
@name.add_text " Starr"
|
||||||
|
@name.to_s.should == "<Name>Ringo Starr</Name>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#attribute" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns an attribute by name" do
|
require 'rexml/document'
|
||||||
person = REXML::Element.new "Person"
|
|
||||||
attribute = REXML::Attribute.new("drink", "coffee")
|
|
||||||
person.add_attribute(attribute)
|
|
||||||
person.attribute("drink").should == attribute
|
|
||||||
end
|
|
||||||
|
|
||||||
it "supports attributes inside namespaces" do
|
describe "REXML::Element#attribute" do
|
||||||
e = REXML::Element.new("element")
|
it "returns an attribute by name" do
|
||||||
e.add_attributes({"xmlns:ns" => "http://some_uri"})
|
person = REXML::Element.new "Person"
|
||||||
e.attribute("ns", "ns").to_s.should == "http://some_uri"
|
attribute = REXML::Attribute.new("drink", "coffee")
|
||||||
|
person.add_attribute(attribute)
|
||||||
|
person.attribute("drink").should == attribute
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports attributes inside namespaces" do
|
||||||
|
e = REXML::Element.new("element")
|
||||||
|
e.add_attributes({"xmlns:ns" => "http://some_uri"})
|
||||||
|
e.attribute("ns", "ns").to_s.should == "http://some_uri"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#attributes" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns element's Attributes" do
|
require 'rexml/document'
|
||||||
p = REXML::Element.new "Person"
|
|
||||||
|
|
||||||
name = REXML::Attribute.new("name", "John")
|
describe "REXML::Element#attributes" do
|
||||||
attrs = REXML::Attributes.new(p)
|
it "returns element's Attributes" do
|
||||||
attrs.add name
|
p = REXML::Element.new "Person"
|
||||||
|
|
||||||
p.add_attribute name
|
name = REXML::Attribute.new("name", "John")
|
||||||
p.attributes.should == attrs
|
attrs = REXML::Attributes.new(p)
|
||||||
end
|
attrs.add name
|
||||||
|
|
||||||
it "returns an empty hash if element has no attributes" do
|
p.add_attribute name
|
||||||
REXML::Element.new("Person").attributes.should == {}
|
p.attributes.should == attrs
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an empty hash if element has no attributes" do
|
||||||
|
REXML::Element.new("Person").attributes.should == {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#cdatas" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("Root")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the array of children cdatas" do
|
describe "REXML::Element#cdatas" do
|
||||||
c = REXML::CData.new("Primary")
|
before :each do
|
||||||
d = REXML::CData.new("Secondary")
|
@e = REXML::Element.new("Root")
|
||||||
@e << c
|
end
|
||||||
@e << d
|
|
||||||
@e.cdatas.should == [c, d]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "freezes the returned array" do
|
it "returns the array of children cdatas" do
|
||||||
@e.cdatas.frozen?.should == true
|
c = REXML::CData.new("Primary")
|
||||||
end
|
d = REXML::CData.new("Secondary")
|
||||||
|
@e << c
|
||||||
|
@e << d
|
||||||
|
@e.cdatas.should == [c, d]
|
||||||
|
end
|
||||||
|
|
||||||
it "returns an empty array if element has no cdata" do
|
it "freezes the returned array" do
|
||||||
@e.cdatas.should == []
|
@e.cdatas.frozen?.should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an empty array if element has no cdata" do
|
||||||
|
@e.cdatas.should == []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +1,32 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#clone" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new "a"
|
|
||||||
end
|
|
||||||
it "creates a copy of element" do
|
|
||||||
@e.clone.to_s.should == @e.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
it "copies the attributes" do
|
describe "REXML::Element#clone" do
|
||||||
@e.add_attribute("foo", "bar")
|
before :each do
|
||||||
@e.clone.to_s.should == @e.to_s
|
@e = REXML::Element.new "a"
|
||||||
end
|
end
|
||||||
|
it "creates a copy of element" do
|
||||||
|
@e.clone.to_s.should == @e.to_s
|
||||||
|
end
|
||||||
|
|
||||||
it "does not copy the text" do
|
it "copies the attributes" do
|
||||||
@e.add_text "some text..."
|
@e.add_attribute("foo", "bar")
|
||||||
@e.clone.to_s.should_not == @e
|
@e.clone.to_s.should == @e.to_s
|
||||||
@e.clone.to_s.should == "<a/>"
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "does not copy the child elements" do
|
it "does not copy the text" do
|
||||||
b = REXML::Element.new "b"
|
@e.add_text "some text..."
|
||||||
@e << b
|
@e.clone.to_s.should_not == @e
|
||||||
@e.clone.should_not == @e
|
@e.clone.to_s.should == "<a/>"
|
||||||
@e.clone.to_s.should == "<a/>"
|
end
|
||||||
|
|
||||||
|
it "does not copy the child elements" do
|
||||||
|
b = REXML::Element.new "b"
|
||||||
|
@e << b
|
||||||
|
@e.clone.should_not == @e
|
||||||
|
@e.clone.to_s.should == "<a/>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#comments" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new "root"
|
|
||||||
@c1 = REXML::Comment.new "this is a comment"
|
|
||||||
@c2 = REXML::Comment.new "this is another comment"
|
|
||||||
@e << @c1
|
|
||||||
@e << @c2
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the array of comments" do
|
describe "REXML::Element#comments" do
|
||||||
@e.comments.should == [@c1, @c2]
|
before :each do
|
||||||
end
|
@e = REXML::Element.new "root"
|
||||||
|
@c1 = REXML::Comment.new "this is a comment"
|
||||||
|
@c2 = REXML::Comment.new "this is another comment"
|
||||||
|
@e << @c1
|
||||||
|
@e << @c2
|
||||||
|
end
|
||||||
|
|
||||||
it "returns a frozen object" do
|
it "returns the array of comments" do
|
||||||
@e.comments.frozen?.should == true
|
@e.comments.should == [@c1, @c2]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a frozen object" do
|
||||||
|
@e.comments.frozen?.should == true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,39 +1,43 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#delete_attribute" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("Person")
|
|
||||||
@attr = REXML::Attribute.new("name", "Sean")
|
|
||||||
@e.add_attribute(@attr)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes an attribute from the element" do
|
describe "REXML::Element#delete_attribute" do
|
||||||
@e.delete_attribute("name")
|
before :each do
|
||||||
@e.attributes["name"].should be_nil
|
@e = REXML::Element.new("Person")
|
||||||
end
|
@attr = REXML::Attribute.new("name", "Sean")
|
||||||
|
|
||||||
# Bug was filled with a patch in Ruby's tracker #20298
|
|
||||||
quarantine! do
|
|
||||||
it "receives an Attribute" do
|
|
||||||
@e.add_attribute(@attr)
|
@e.add_attribute(@attr)
|
||||||
@e.delete_attribute(@attr)
|
end
|
||||||
|
|
||||||
|
it "deletes an attribute from the element" do
|
||||||
|
@e.delete_attribute("name")
|
||||||
@e.attributes["name"].should be_nil
|
@e.attributes["name"].should be_nil
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Docs say that it returns the removed attribute but then examples
|
# Bug was filled with a patch in Ruby's tracker #20298
|
||||||
# show it returns the element with the attribute removed.
|
quarantine! do
|
||||||
# Also fixed in #20298
|
it "receives an Attribute" do
|
||||||
it "returns the element with the attribute removed" do
|
@e.add_attribute(@attr)
|
||||||
elem = @e.delete_attribute("name")
|
@e.delete_attribute(@attr)
|
||||||
elem.attributes.should be_empty
|
@e.attributes["name"].should be_nil
|
||||||
elem.to_s.should eql("<Person/>")
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil if the attribute does not exist" do
|
# Docs say that it returns the removed attribute but then examples
|
||||||
@e.delete_attribute("name")
|
# show it returns the element with the attribute removed.
|
||||||
at = @e.delete_attribute("name")
|
# Also fixed in #20298
|
||||||
at.should be_nil
|
it "returns the element with the attribute removed" do
|
||||||
|
elem = @e.delete_attribute("name")
|
||||||
|
elem.attributes.should be_empty
|
||||||
|
elem.to_s.should eql("<Person/>")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil if the attribute does not exist" do
|
||||||
|
@e.delete_attribute("name")
|
||||||
|
at = @e.delete_attribute("name")
|
||||||
|
at.should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,49 +1,52 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#delete_element" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@root = REXML::Element.new("root")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes the child element" do
|
describe "REXML::Element#delete_element" do
|
||||||
node = REXML::Element.new("some_node")
|
before :each do
|
||||||
@root.add_element node
|
@root = REXML::Element.new("root")
|
||||||
@root.delete_element node
|
end
|
||||||
@root.elements.size.should == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes a child via XPath" do
|
it "deletes the child element" do
|
||||||
@root.add_element "some_node"
|
node = REXML::Element.new("some_node")
|
||||||
@root.delete_element "some_node"
|
@root.add_element node
|
||||||
@root.elements.size.should == 0
|
@root.delete_element node
|
||||||
end
|
@root.elements.size.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
it "deletes the child at index" do
|
it "deletes a child via XPath" do
|
||||||
@root.add_element "some_node"
|
@root.add_element "some_node"
|
||||||
@root.delete_element 1
|
@root.delete_element "some_node"
|
||||||
@root.elements.size.should == 0
|
@root.elements.size.should == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# According to the docs this should return the deleted element
|
it "deletes the child at index" do
|
||||||
# but it won't if it's an Element.
|
@root.add_element "some_node"
|
||||||
it "deletes Element and returns it" do
|
@root.delete_element 1
|
||||||
node = REXML::Element.new("some_node")
|
@root.elements.size.should == 0
|
||||||
@root.add_element node
|
end
|
||||||
del_node = @root.delete_element node
|
|
||||||
del_node.should == node
|
|
||||||
end
|
|
||||||
|
|
||||||
# Note how passing the string will return the removed element
|
# According to the docs this should return the deleted element
|
||||||
# but passing the Element as above won't.
|
# but it won't if it's an Element.
|
||||||
it "deletes an element and returns it" do
|
it "deletes Element and returns it" do
|
||||||
node = REXML::Element.new("some_node")
|
node = REXML::Element.new("some_node")
|
||||||
@root.add_element node
|
@root.add_element node
|
||||||
del_node = @root.delete_element "some_node"
|
del_node = @root.delete_element node
|
||||||
del_node.should == node
|
del_node.should == node
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil unless element exists" do
|
# Note how passing the string will return the removed element
|
||||||
@root.delete_element("something").should == nil
|
# but passing the Element as above won't.
|
||||||
|
it "deletes an element and returns it" do
|
||||||
|
node = REXML::Element.new("some_node")
|
||||||
|
@root.add_element node
|
||||||
|
del_node = @root.delete_element "some_node"
|
||||||
|
del_node.should == node
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil unless element exists" do
|
||||||
|
@root.delete_element("something").should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#delete_namespace" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
before :each do
|
describe "REXML::Element#delete_namespace" do
|
||||||
@doc = REXML::Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes a namespace from the element" do
|
before :each do
|
||||||
@doc.root.delete_namespace 'foo'
|
@doc = REXML::Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
|
||||||
@doc.root.namespace("foo").should be_nil
|
end
|
||||||
@doc.root.to_s.should == "<a xmlns='twiddle'/>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes default namespace when called with no args" do
|
it "deletes a namespace from the element" do
|
||||||
@doc.root.delete_namespace
|
@doc.root.delete_namespace 'foo'
|
||||||
@doc.root.namespace.should be_empty
|
@doc.root.namespace("foo").should be_nil
|
||||||
@doc.root.to_s.should == "<a xmlns:foo='bar'/>"
|
@doc.root.to_s.should == "<a xmlns='twiddle'/>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the element" do
|
it "deletes default namespace when called with no args" do
|
||||||
@doc.root.delete_namespace.should == @doc.root
|
@doc.root.delete_namespace
|
||||||
|
@doc.root.namespace.should be_empty
|
||||||
|
@doc.root.to_s.should == "<a xmlns:foo='bar'/>"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the element" do
|
||||||
|
@doc.root.delete_namespace.should == @doc.root
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#document" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
it "returns the element's document" do
|
describe "REXML::Element#document" do
|
||||||
d = REXML::Document.new("<root><elem/></root>")
|
|
||||||
d << REXML::XMLDecl.new
|
|
||||||
d.root.document.should == d
|
|
||||||
d.root.document.to_s.should == d.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns nil if it belongs to no document" do
|
it "returns the element's document" do
|
||||||
REXML::Element.new("standalone").document.should be_nil
|
d = REXML::Document.new("<root><elem/></root>")
|
||||||
|
d << REXML::XMLDecl.new
|
||||||
|
d.root.document.should == d
|
||||||
|
d.root.document.to_s.should == d.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil if it belongs to no document" do
|
||||||
|
REXML::Element.new("standalone").document.should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,35 +1,38 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#each_element_with_attributes" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@document = REXML::Element.new("people")
|
|
||||||
@father = REXML::Element.new("Person")
|
|
||||||
@father.attributes["name"] = "Joe"
|
|
||||||
@son = REXML::Element.new("Child")
|
|
||||||
@son.attributes["name"] = "Fred"
|
|
||||||
@document.root << @father
|
|
||||||
@document.root << @son
|
|
||||||
@childs = []
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns childs with attribute" do
|
describe "REXML::Element#each_element_with_attributes" do
|
||||||
@document.each_element_with_attribute("name") { |elem| @childs << elem }
|
before :each do
|
||||||
@childs[0].should == @father
|
@document = REXML::Element.new("people")
|
||||||
@childs[1].should == @son
|
@father = REXML::Element.new("Person")
|
||||||
end
|
@father.attributes["name"] = "Joe"
|
||||||
|
@son = REXML::Element.new("Child")
|
||||||
|
@son.attributes["name"] = "Fred"
|
||||||
|
@document.root << @father
|
||||||
|
@document.root << @son
|
||||||
|
@childs = []
|
||||||
|
end
|
||||||
|
|
||||||
it "takes attribute value as second argument" do
|
it "returns childs with attribute" do
|
||||||
@document.each_element_with_attribute("name", "Fred"){ |elem| elem.should == @son }
|
@document.each_element_with_attribute("name") { |elem| @childs << elem }
|
||||||
end
|
@childs[0].should == @father
|
||||||
|
@childs[1].should == @son
|
||||||
|
end
|
||||||
|
|
||||||
it "takes max number of childs as third argument" do
|
it "takes attribute value as second argument" do
|
||||||
@document.each_element_with_attribute("name", nil, 1) { |elem| @childs << elem }
|
@document.each_element_with_attribute("name", "Fred"){ |elem| elem.should == @son }
|
||||||
@childs.size.should == 1
|
end
|
||||||
@childs[0].should == @father
|
|
||||||
end
|
|
||||||
|
|
||||||
it "takes XPath filter as fourth argument" do
|
it "takes max number of childs as third argument" do
|
||||||
@document.each_element_with_attribute("name", nil, 0, "Child"){ |elem| elem.should == @son}
|
@document.each_element_with_attribute("name", nil, 1) { |elem| @childs << elem }
|
||||||
|
@childs.size.should == 1
|
||||||
|
@childs[0].should == @father
|
||||||
|
end
|
||||||
|
|
||||||
|
it "takes XPath filter as fourth argument" do
|
||||||
|
@document.each_element_with_attribute("name", nil, 0, "Child"){ |elem| elem.should == @son}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#each_element_with_text" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@document = REXML::Element.new("people")
|
|
||||||
|
|
||||||
@joe = REXML::Element.new("Person")
|
describe "REXML::Element#each_element_with_text" do
|
||||||
@joe.text = "Joe"
|
before :each do
|
||||||
@fred = REXML::Element.new("Person")
|
@document = REXML::Element.new("people")
|
||||||
@fred.text = "Fred"
|
|
||||||
@another = REXML::Element.new("AnotherPerson")
|
|
||||||
@another.text = "Fred"
|
|
||||||
@document.root << @joe
|
|
||||||
@document.root << @fred
|
|
||||||
@document.root << @another
|
|
||||||
@childs = []
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns childs with text" do
|
@joe = REXML::Element.new("Person")
|
||||||
@document.each_element_with_text("Joe"){|c| c.should == @joe}
|
@joe.text = "Joe"
|
||||||
end
|
@fred = REXML::Element.new("Person")
|
||||||
|
@fred.text = "Fred"
|
||||||
|
@another = REXML::Element.new("AnotherPerson")
|
||||||
|
@another.text = "Fred"
|
||||||
|
@document.root << @joe
|
||||||
|
@document.root << @fred
|
||||||
|
@document.root << @another
|
||||||
|
@childs = []
|
||||||
|
end
|
||||||
|
|
||||||
it "takes max as second argument" do
|
it "returns childs with text" do
|
||||||
@document.each_element_with_text("Fred", 1){ |c| c.should == @fred}
|
@document.each_element_with_text("Joe"){|c| c.should == @joe}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "takes XPath filter as third argument" do
|
it "takes max as second argument" do
|
||||||
@document.each_element_with_text("Fred", 0, "Person"){ |c| c.should == @fred}
|
@document.each_element_with_text("Fred", 1){ |c| c.should == @fred}
|
||||||
|
end
|
||||||
|
|
||||||
|
it "takes XPath filter as third argument" do
|
||||||
|
@document.each_element_with_text("Fred", 0, "Person"){ |c| c.should == @fred}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#[]" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
before :each do
|
describe "REXML::Element#[]" do
|
||||||
@doc = REXML::Document.new("<root foo='bar'></root>")
|
|
||||||
@child = REXML::Element.new("child")
|
|
||||||
@doc.root.add_element @child
|
|
||||||
end
|
|
||||||
|
|
||||||
it "return attribute value if argument is string or symbol" do
|
before :each do
|
||||||
@doc.root[:foo].should == 'bar'
|
@doc = REXML::Document.new("<root foo='bar'></root>")
|
||||||
@doc.root['foo'].should == 'bar'
|
@child = REXML::Element.new("child")
|
||||||
end
|
@doc.root.add_element @child
|
||||||
|
end
|
||||||
|
|
||||||
it "return nth element if argument is int" do
|
it "return attribute value if argument is string or symbol" do
|
||||||
@doc.root[0].should == @child
|
@doc.root[:foo].should == 'bar'
|
||||||
|
@doc.root['foo'].should == 'bar'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "return nth element if argument is int" do
|
||||||
|
@doc.root[0].should == @child
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#get_text" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@doc = REXML::Document.new "<p>some text<b>this is bold!</b> more text</p>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the first text child node" do
|
describe "REXML::Element#get_text" do
|
||||||
@doc.root.get_text.value.should == "some text"
|
before :each do
|
||||||
@doc.root.get_text.should be_kind_of(REXML::Text)
|
@doc = REXML::Document.new "<p>some text<b>this is bold!</b> more text</p>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns text from an element matching path" do
|
it "returns the first text child node" do
|
||||||
@doc.root.get_text("b").value.should == "this is bold!"
|
@doc.root.get_text.value.should == "some text"
|
||||||
@doc.root.get_text("b").should be_kind_of(REXML::Text)
|
@doc.root.get_text.should be_kind_of(REXML::Text)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns text from an element matching path" do
|
||||||
|
@doc.root.get_text("b").value.should == "this is bold!"
|
||||||
|
@doc.root.get_text("b").should be_kind_of(REXML::Text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#has_attributes?" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("test_elem")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns true when element has any attributes" do
|
describe "REXML::Element#has_attributes?" do
|
||||||
@e.add_attribute("name", "Joe")
|
before :each do
|
||||||
@e.has_attributes?.should be_true
|
@e = REXML::Element.new("test_elem")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if element has no attributes" do
|
it "returns true when element has any attributes" do
|
||||||
@e.has_attributes?.should be_false
|
@e.add_attribute("name", "Joe")
|
||||||
|
@e.has_attributes?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if element has no attributes" do
|
||||||
|
@e.has_attributes?.should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#has_elements?" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns true if element has child elements" do
|
describe "REXML::Element#has_elements?" do
|
||||||
child = REXML::Element.new("child")
|
before :each do
|
||||||
@e << child
|
@e = REXML::Element.new("root")
|
||||||
@e.has_elements?.should be_true
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false if element doesn't have child elements" do
|
it "returns true if element has child elements" do
|
||||||
@e.has_elements?.should be_false
|
child = REXML::Element.new("child")
|
||||||
|
@e << child
|
||||||
|
@e.has_elements?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if element doesn't have child elements" do
|
||||||
|
@e.has_elements?.should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#has_text?" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
it "returns true if element has a Text child" do
|
describe "REXML::Element#has_text?" do
|
||||||
e = REXML::Element.new("Person")
|
|
||||||
e.text = "My text"
|
|
||||||
e.has_text?.should be_true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false if it has no Text childs" do
|
it "returns true if element has a Text child" do
|
||||||
e = REXML::Element.new("Person")
|
e = REXML::Element.new("Person")
|
||||||
e.has_text?.should be_false
|
e.text = "My text"
|
||||||
|
e.has_text?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if it has no Text childs" do
|
||||||
|
e = REXML::Element.new("Person")
|
||||||
|
e.has_text?.should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#inspect" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
before :each do
|
describe "REXML::Element#inspect" do
|
||||||
@name = REXML::Element.new "name"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the node as a string" do
|
before :each do
|
||||||
@name.inspect.should == "<name/>"
|
@name = REXML::Element.new "name"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "inserts '...' if the node has children" do
|
it "returns the node as a string" do
|
||||||
e = REXML::Element.new "last_name"
|
@name.inspect.should == "<name/>"
|
||||||
@name << e
|
end
|
||||||
@name.inspect.should == "<name> ... </>"
|
|
||||||
# This might make more sense but differs from MRI's default behavior
|
|
||||||
# @name.inspect.should == "<name> ... </name>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "inserts the attributes in the string" do
|
it "inserts '...' if the node has children" do
|
||||||
@name.add_attribute "language"
|
e = REXML::Element.new "last_name"
|
||||||
@name.attributes["language"] = "english"
|
@name << e
|
||||||
@name.inspect.should == "<name language='english'/>"
|
@name.inspect.should == "<name> ... </>"
|
||||||
|
# This might make more sense but differs from MRI's default behavior
|
||||||
|
# @name.inspect.should == "<name> ... </name>"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "inserts the attributes in the string" do
|
||||||
|
@name.add_attribute "language"
|
||||||
|
@name.attributes["language"] = "english"
|
||||||
|
@name.inspect.should == "<name language='english'/>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#instructions" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@elem = REXML::Element.new("root")
|
|
||||||
end
|
|
||||||
it "returns the Instruction children nodes" do
|
|
||||||
inst = REXML::Instruction.new("xml-stylesheet", "href='headlines.css'")
|
|
||||||
@elem << inst
|
|
||||||
@elem.instructions.first.should == inst
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns an empty array if it has no Instruction children" do
|
describe "REXML::Element#instructions" do
|
||||||
@elem.instructions.should be_empty
|
before :each do
|
||||||
end
|
@elem = REXML::Element.new("root")
|
||||||
|
end
|
||||||
|
it "returns the Instruction children nodes" do
|
||||||
|
inst = REXML::Instruction.new("xml-stylesheet", "href='headlines.css'")
|
||||||
|
@elem << inst
|
||||||
|
@elem.instructions.first.should == inst
|
||||||
|
end
|
||||||
|
|
||||||
it "freezes the returned array" do
|
it "returns an empty array if it has no Instruction children" do
|
||||||
@elem.instructions.frozen?.should be_true
|
@elem.instructions.should be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "freezes the returned array" do
|
||||||
|
@elem.instructions.frozen?.should be_true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#namespace" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
|
||||||
@elem = @doc.elements["//b"]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the default namespace" do
|
describe "REXML::Element#namespace" do
|
||||||
@elem.namespace.should == "1"
|
before :each do
|
||||||
end
|
@doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
||||||
|
@elem = @doc.elements["//b"]
|
||||||
|
end
|
||||||
|
|
||||||
it "accepts a namespace prefix" do
|
it "returns the default namespace" do
|
||||||
@elem.namespace("y").should == "2"
|
@elem.namespace.should == "1"
|
||||||
@doc.elements["//c"].namespace("z").should == "3"
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "returns an empty String if default namespace is not defined" do
|
it "accepts a namespace prefix" do
|
||||||
e = REXML::Document.new("<a/>")
|
@elem.namespace("y").should == "2"
|
||||||
e.root.namespace.should be_empty
|
@doc.elements["//c"].namespace("z").should == "3"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil if namespace is not defined" do
|
it "returns an empty String if default namespace is not defined" do
|
||||||
@elem.namespace("z").should be_nil
|
e = REXML::Document.new("<a/>")
|
||||||
|
e.root.namespace.should be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil if namespace is not defined" do
|
||||||
|
@elem.namespace("z").should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,32 +1,35 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#namespaces" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
|
||||||
@elem = doc.elements["//c"]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns a hash of the namespaces" do
|
describe "REXML::Element#namespaces" do
|
||||||
ns = {"y"=>"2", "z"=>"3", "xmlns"=>"1"}
|
before :each do
|
||||||
@elem.namespaces.keys.sort.should == ns.keys.sort
|
doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
||||||
@elem.namespaces.values.sort.should == ns.values.sort
|
@elem = doc.elements["//c"]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an empty hash if no namespaces exist" do
|
it "returns a hash of the namespaces" do
|
||||||
e = REXML::Element.new "element"
|
ns = {"y"=>"2", "z"=>"3", "xmlns"=>"1"}
|
||||||
e.namespaces.kind_of?(Hash).should == true
|
@elem.namespaces.keys.sort.should == ns.keys.sort
|
||||||
e.namespaces.should be_empty
|
@elem.namespaces.values.sort.should == ns.values.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses namespace prefixes as keys" do
|
it "returns an empty hash if no namespaces exist" do
|
||||||
prefixes = ["y", "z", "xmlns"]
|
e = REXML::Element.new "element"
|
||||||
@elem.namespaces.keys.sort.should == prefixes.sort
|
e.namespaces.kind_of?(Hash).should == true
|
||||||
end
|
e.namespaces.should be_empty
|
||||||
|
end
|
||||||
|
|
||||||
it "uses namespace values as the hash values" do
|
it "uses namespace prefixes as keys" do
|
||||||
values = ["2", "3", "1"]
|
prefixes = ["y", "z", "xmlns"]
|
||||||
@elem.namespaces.values.sort.should == values.sort
|
@elem.namespaces.keys.sort.should == prefixes.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "uses namespace values as the hash values" do
|
||||||
|
values = ["2", "3", "1"]
|
||||||
|
@elem.namespaces.values.sort.should == values.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,35 +1,38 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#new" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
it "creates element from tag name" do
|
describe "REXML::Element#new" do
|
||||||
REXML::Element.new("foo").name.should == "foo"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates element with default attributes" do
|
it "creates element from tag name" do
|
||||||
e = REXML::Element.new
|
REXML::Element.new("foo").name.should == "foo"
|
||||||
e.name.should == REXML::Element::UNDEFINED
|
end
|
||||||
e.context.should == nil
|
|
||||||
e.parent.should == nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates element from another element" do
|
it "creates element with default attributes" do
|
||||||
e = REXML::Element.new "foo"
|
e = REXML::Element.new
|
||||||
f = REXML::Element.new e
|
e.name.should == REXML::Element::UNDEFINED
|
||||||
e.name.should == f.name
|
e.context.should == nil
|
||||||
e.context.should == f.context
|
e.parent.should == nil
|
||||||
e.parent.should == f.parent
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "takes parent as second argument" do
|
it "creates element from another element" do
|
||||||
parent = REXML::Element.new "foo"
|
e = REXML::Element.new "foo"
|
||||||
child = REXML::Element.new "bar", parent
|
f = REXML::Element.new e
|
||||||
child.parent.should == parent
|
e.name.should == f.name
|
||||||
end
|
e.context.should == f.context
|
||||||
|
e.parent.should == f.parent
|
||||||
|
end
|
||||||
|
|
||||||
it "takes context as third argument" do
|
it "takes parent as second argument" do
|
||||||
context = {"some_key" => "some_value"}
|
parent = REXML::Element.new "foo"
|
||||||
REXML::Element.new("foo", nil, context).context.should == context
|
child = REXML::Element.new "bar", parent
|
||||||
|
child.parent.should == parent
|
||||||
|
end
|
||||||
|
|
||||||
|
it "takes context as third argument" do
|
||||||
|
context = {"some_key" => "some_value"}
|
||||||
|
REXML::Element.new("foo", nil, context).context.should == context
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#next_element" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@a = REXML::Element.new "a"
|
|
||||||
@b = REXML::Element.new "b"
|
|
||||||
@c = REXML::Element.new "c"
|
|
||||||
@a.root << @b
|
|
||||||
@a.root << @c
|
|
||||||
end
|
|
||||||
it "returns next existing element" do
|
|
||||||
@a.elements["b"].next_element.should == @c
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns nil on last element" do
|
describe "REXML::Element#next_element" do
|
||||||
@a.elements["c"].next_element.should == nil
|
before :each do
|
||||||
|
@a = REXML::Element.new "a"
|
||||||
|
@b = REXML::Element.new "b"
|
||||||
|
@c = REXML::Element.new "c"
|
||||||
|
@a.root << @b
|
||||||
|
@a.root << @c
|
||||||
|
end
|
||||||
|
it "returns next existing element" do
|
||||||
|
@a.elements["b"].next_element.should == @c
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil on last element" do
|
||||||
|
@a.elements["c"].next_element.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#node_type" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns :element" do
|
require 'rexml/document'
|
||||||
REXML::Element.new("MyElem").node_type.should == :element
|
|
||||||
|
describe "REXML::Element#node_type" do
|
||||||
|
it "returns :element" do
|
||||||
|
REXML::Element.new("MyElem").node_type.should == :element
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#prefixes" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
|
||||||
@elem = doc.elements["//c"]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns an array of the prefixes of the namespaces" do
|
describe "REXML::Element#prefixes" do
|
||||||
@elem.prefixes.should == ["y", "z"]
|
before :each do
|
||||||
end
|
doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
||||||
|
@elem = doc.elements["//c"]
|
||||||
|
end
|
||||||
|
|
||||||
it "does not include the default namespace" do
|
it "returns an array of the prefixes of the namespaces" do
|
||||||
@elem.prefixes.include?("xmlns").should == false
|
@elem.prefixes.should == ["y", "z"]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an empty array if no namespace was defined" do
|
it "does not include the default namespace" do
|
||||||
doc = REXML::Document.new "<root><something/></root>"
|
@elem.prefixes.include?("xmlns").should == false
|
||||||
root = doc.elements["//root"]
|
end
|
||||||
root.prefixes.should == []
|
|
||||||
|
it "returns an empty array if no namespace was defined" do
|
||||||
|
doc = REXML::Document.new "<root><something/></root>"
|
||||||
|
root = doc.elements["//root"]
|
||||||
|
root.prefixes.should == []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#previous_element" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@a = REXML::Element.new "a"
|
|
||||||
@b = REXML::Element.new "b"
|
|
||||||
@c = REXML::Element.new "c"
|
|
||||||
@a.root << @b
|
|
||||||
@a.root << @c
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns previous element" do
|
describe "REXML::Element#previous_element" do
|
||||||
@a.elements["c"].previous_element.should == @b
|
before :each do
|
||||||
end
|
@a = REXML::Element.new "a"
|
||||||
|
@b = REXML::Element.new "b"
|
||||||
|
@c = REXML::Element.new "c"
|
||||||
|
@a.root << @b
|
||||||
|
@a.root << @c
|
||||||
|
end
|
||||||
|
|
||||||
it "returns nil on first element" do
|
it "returns previous element" do
|
||||||
@a.elements["b"].previous_element.should == nil
|
@a.elements["c"].previous_element.should == @b
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil on first element" do
|
||||||
|
@a.elements["b"].previous_element.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#raw" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns true if raw mode is set to all" do
|
require 'rexml/document'
|
||||||
REXML::Element.new("MyElem", nil, {raw: :all}).raw.should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns true if raw mode is set to expanded_name" do
|
describe "REXML::Element#raw" do
|
||||||
REXML::Element.new("MyElem", nil, {raw: "MyElem"}).raw.should == true
|
it "returns true if raw mode is set to all" do
|
||||||
end
|
REXML::Element.new("MyElem", nil, {raw: :all}).raw.should == true
|
||||||
|
end
|
||||||
|
|
||||||
it "returns false if raw mode is not set" do
|
it "returns true if raw mode is set to expanded_name" do
|
||||||
REXML::Element.new("MyElem", nil, {raw: ""}).raw.should == false
|
REXML::Element.new("MyElem", nil, {raw: "MyElem"}).raw.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if raw is not :all or expanded_name" do
|
it "returns false if raw mode is not set" do
|
||||||
REXML::Element.new("MyElem", nil, {raw: "Something"}).raw.should == false
|
REXML::Element.new("MyElem", nil, {raw: ""}).raw.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil if context is not set" do
|
it "returns false if raw is not :all or expanded_name" do
|
||||||
REXML::Element.new("MyElem").raw.should == nil
|
REXML::Element.new("MyElem", nil, {raw: "Something"}).raw.should == false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil if context is not set" do
|
||||||
|
REXML::Element.new("MyElem").raw.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,28 +1,31 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Element#root" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@doc = REXML::Document.new
|
|
||||||
@root = REXML::Element.new "root"
|
|
||||||
@node = REXML::Element.new "node"
|
|
||||||
@doc << @root << @node
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns first child on documents" do
|
describe "REXML::Element#root" do
|
||||||
@doc.root.should == @root
|
before :each do
|
||||||
end
|
@doc = REXML::Document.new
|
||||||
|
@root = REXML::Element.new "root"
|
||||||
|
@node = REXML::Element.new "node"
|
||||||
|
@doc << @root << @node
|
||||||
|
end
|
||||||
|
|
||||||
it "returns self on root nodes" do
|
it "returns first child on documents" do
|
||||||
@root.root.should == @root
|
@doc.root.should == @root
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns parent's root on child nodes" do
|
it "returns self on root nodes" do
|
||||||
@node.root.should == @root
|
@root.root.should == @root
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns self on standalone nodes" do
|
it "returns parent's root on child nodes" do
|
||||||
e = REXML::Element.new "Elem" # Note that it doesn't have a parent node
|
@node.root.should == @root
|
||||||
e.root.should == e
|
end
|
||||||
|
|
||||||
|
it "returns self on standalone nodes" do
|
||||||
|
e = REXML::Element.new "Elem" # Note that it doesn't have a parent node
|
||||||
|
e.root.should == e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,46 +1,49 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#text" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new "name"
|
|
||||||
@e.text = "John"
|
describe "REXML::Element#text" do
|
||||||
|
before :each do
|
||||||
|
@e = REXML::Element.new "name"
|
||||||
|
@e.text = "John"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the text node of element" do
|
||||||
|
@e.text.should == "John"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the text node value" do
|
||||||
|
t = REXML::Text.new "Joe"
|
||||||
|
@e.text = t
|
||||||
|
@e.text.should == "Joe"
|
||||||
|
@e.text.should_not == t
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil if no text is attached" do
|
||||||
|
elem = REXML::Element.new "name"
|
||||||
|
elem.text.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the text node of element" do
|
describe "REXML::Element#text=" do
|
||||||
@e.text.should == "John"
|
before :each do
|
||||||
end
|
@e = REXML::Element.new "name"
|
||||||
|
@e.text = "John"
|
||||||
|
end
|
||||||
|
|
||||||
it "returns the text node value" do
|
it "sets the text node" do
|
||||||
t = REXML::Text.new "Joe"
|
@e.to_s.should == "<name>John</name>"
|
||||||
@e.text = t
|
end
|
||||||
@e.text.should == "Joe"
|
|
||||||
@e.text.should_not == t
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns nil if no text is attached" do
|
it "replaces existing text" do
|
||||||
elem = REXML::Element.new "name"
|
@e.text = "Joe"
|
||||||
elem.text.should == nil
|
@e.to_s.should == "<name>Joe</name>"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
it "receives nil as an argument" do
|
||||||
describe "REXML::Element#text=" do
|
@e.text = nil
|
||||||
before :each do
|
@e.to_s.should == "<name/>"
|
||||||
@e = REXML::Element.new "name"
|
end
|
||||||
@e.text = "John"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "sets the text node" do
|
|
||||||
@e.to_s.should == "<name>John</name>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "replaces existing text" do
|
|
||||||
@e.text = "Joe"
|
|
||||||
@e.to_s.should == "<name>Joe</name>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "receives nil as an argument" do
|
|
||||||
@e.text = nil
|
|
||||||
@e.to_s.should == "<name/>"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#texts" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
it "returns an array of the Text children" do
|
describe "REXML::Element#texts" do
|
||||||
e = REXML::Element.new("root")
|
|
||||||
e.add_text "First"
|
|
||||||
e.add_text "Second"
|
|
||||||
e.texts.should == ["FirstSecond"]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns an empty array if it has no Text children" do
|
it "returns an array of the Text children" do
|
||||||
REXML::Element.new("root").texts.should == []
|
e = REXML::Element.new("root")
|
||||||
|
e.add_text "First"
|
||||||
|
e.add_text "Second"
|
||||||
|
e.texts.should == ["FirstSecond"]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an empty array if it has no Text children" do
|
||||||
|
REXML::Element.new("root").texts.should == []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
require 'rexml/document'
|
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "REXML::Element#whitespace" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns true if whitespace is respected in the element" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new("root")
|
|
||||||
e.whitespace.should be_true
|
|
||||||
|
|
||||||
e = REXML::Element.new("root", nil, respect_whitespace: :all)
|
describe "REXML::Element#whitespace" do
|
||||||
e.whitespace.should be_true
|
it "returns true if whitespace is respected in the element" do
|
||||||
|
e = REXML::Element.new("root")
|
||||||
|
e.whitespace.should be_true
|
||||||
|
|
||||||
e = REXML::Element.new("root", nil, respect_whitespace: ["root"])
|
e = REXML::Element.new("root", nil, respect_whitespace: :all)
|
||||||
e.whitespace.should be_true
|
e.whitespace.should be_true
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false if whitespace is ignored inside element" do
|
e = REXML::Element.new("root", nil, respect_whitespace: ["root"])
|
||||||
e = REXML::Element.new("root", nil, compress_whitespace: :all)
|
e.whitespace.should be_true
|
||||||
e.whitespace.should be_false
|
end
|
||||||
|
|
||||||
e = REXML::Element.new("root", nil, compress_whitespace: ["root"])
|
it "returns false if whitespace is ignored inside element" do
|
||||||
e.whitespace.should be_false
|
e = REXML::Element.new("root", nil, compress_whitespace: :all)
|
||||||
|
e.whitespace.should be_false
|
||||||
|
|
||||||
|
e = REXML::Element.new("root", nil, compress_whitespace: ["root"])
|
||||||
|
e.whitespace.should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Node#each_recursive" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@doc = REXML::Document.new
|
|
||||||
@doc << REXML::XMLDecl.new
|
|
||||||
@root = REXML::Element.new "root"
|
|
||||||
@child1 = REXML::Element.new "child1"
|
|
||||||
@child2 = REXML::Element.new "child2"
|
|
||||||
@root << @child1
|
|
||||||
@root << @child2
|
|
||||||
@doc << @root
|
|
||||||
end
|
|
||||||
|
|
||||||
it "visits all subnodes of self" do
|
describe "REXML::Node#each_recursive" do
|
||||||
nodes = []
|
before :each do
|
||||||
@doc.each_recursive { |node| nodes << node}
|
@doc = REXML::Document.new
|
||||||
nodes.should == [@root, @child1, @child2]
|
@doc << REXML::XMLDecl.new
|
||||||
|
@root = REXML::Element.new "root"
|
||||||
|
@child1 = REXML::Element.new "child1"
|
||||||
|
@child2 = REXML::Element.new "child2"
|
||||||
|
@root << @child1
|
||||||
|
@root << @child2
|
||||||
|
@doc << @root
|
||||||
|
end
|
||||||
|
|
||||||
|
it "visits all subnodes of self" do
|
||||||
|
nodes = []
|
||||||
|
@doc.each_recursive { |node| nodes << node}
|
||||||
|
nodes.should == [@root, @child1, @child2]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Node#find_first_recursive" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
@node1 = REXML::Element.new("node")
|
|
||||||
@node2 = REXML::Element.new("another node")
|
|
||||||
@subnode = REXML::Element.new("another node")
|
|
||||||
@node1 << @subnode
|
|
||||||
@e << @node1
|
|
||||||
@e << @node2
|
|
||||||
end
|
|
||||||
|
|
||||||
it "finds the first element that matches block" do
|
describe "REXML::Node#find_first_recursive" do
|
||||||
found = @e.find_first_recursive { |n| n.to_s == "<node><another node/></node>"}
|
before :each do
|
||||||
found.should == @node1
|
@e = REXML::Element.new("root")
|
||||||
end
|
@node1 = REXML::Element.new("node")
|
||||||
|
@node2 = REXML::Element.new("another node")
|
||||||
|
@subnode = REXML::Element.new("another node")
|
||||||
|
@node1 << @subnode
|
||||||
|
@e << @node1
|
||||||
|
@e << @node2
|
||||||
|
end
|
||||||
|
|
||||||
it "visits the nodes in preorder" do
|
it "finds the first element that matches block" do
|
||||||
found = @e.find_first_recursive { |n| n.to_s == "<another node/>"}
|
found = @e.find_first_recursive { |n| n.to_s == "<node><another node/></node>"}
|
||||||
found.should == @subnode
|
found.should == @node1
|
||||||
found.should_not == @node2
|
end
|
||||||
|
|
||||||
|
it "visits the nodes in preorder" do
|
||||||
|
found = @e.find_first_recursive { |n| n.to_s == "<another node/>"}
|
||||||
|
found.should == @subnode
|
||||||
|
found.should_not == @node2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Node#index_in_parent" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the index (starting from 1) of self in parent" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new("root")
|
|
||||||
node1 = REXML::Element.new("node")
|
|
||||||
node2 = REXML::Element.new("another node")
|
|
||||||
e << node1
|
|
||||||
e << node2
|
|
||||||
|
|
||||||
node1.index_in_parent.should == 1
|
describe "REXML::Node#index_in_parent" do
|
||||||
node2.index_in_parent.should == 2
|
it "returns the index (starting from 1) of self in parent" do
|
||||||
|
e = REXML::Element.new("root")
|
||||||
|
node1 = REXML::Element.new("node")
|
||||||
|
node2 = REXML::Element.new("another node")
|
||||||
|
e << node1
|
||||||
|
e << node2
|
||||||
|
|
||||||
|
node1.index_in_parent.should == 1
|
||||||
|
node2.index_in_parent.should == 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Node#next_sibling_node" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
@node1 = REXML::Element.new("node")
|
|
||||||
@node2 = REXML::Element.new("another node")
|
|
||||||
@e << @node1
|
|
||||||
@e << @node2
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the next child node in parent" do
|
describe "REXML::Node#next_sibling_node" do
|
||||||
@node1.next_sibling_node.should == @node2
|
before :each do
|
||||||
end
|
@e = REXML::Element.new("root")
|
||||||
|
@node1 = REXML::Element.new("node")
|
||||||
|
@node2 = REXML::Element.new("another node")
|
||||||
|
@e << @node1
|
||||||
|
@e << @node2
|
||||||
|
end
|
||||||
|
|
||||||
it "returns nil if there are no more child nodes next" do
|
it "returns the next child node in parent" do
|
||||||
@node2.next_sibling_node.should == nil
|
@node1.next_sibling_node.should == @node2
|
||||||
@e.next_sibling_node.should == nil
|
end
|
||||||
|
|
||||||
|
it "returns nil if there are no more child nodes next" do
|
||||||
|
@node2.next_sibling_node.should == nil
|
||||||
|
@e.next_sibling_node.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Node#parent?" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns true for Elements" do
|
require 'rexml/document'
|
||||||
e = REXML::Element.new("foo")
|
|
||||||
e.parent?.should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns true for Documents" do
|
describe "REXML::Node#parent?" do
|
||||||
e = REXML::Document.new
|
it "returns true for Elements" do
|
||||||
e.parent?.should == true
|
e = REXML::Element.new("foo")
|
||||||
end
|
e.parent?.should == true
|
||||||
|
end
|
||||||
|
|
||||||
# This includes attributes, CDatas and declarations.
|
it "returns true for Documents" do
|
||||||
it "returns false for Texts" do
|
e = REXML::Document.new
|
||||||
e = REXML::Text.new("foo")
|
e.parent?.should == true
|
||||||
e.parent?.should == false
|
end
|
||||||
|
|
||||||
|
# This includes attributes, CDatas and declarations.
|
||||||
|
it "returns false for Texts" do
|
||||||
|
e = REXML::Text.new("foo")
|
||||||
|
e.parent?.should == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Node#previous_sibling_node" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@e = REXML::Element.new("root")
|
|
||||||
@node1 = REXML::Element.new("node")
|
|
||||||
@node2 = REXML::Element.new("another node")
|
|
||||||
@e << @node1
|
|
||||||
@e << @node2
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the previous child node in parent" do
|
describe "REXML::Node#previous_sibling_node" do
|
||||||
@node2.previous_sibling_node.should == @node1
|
before :each do
|
||||||
end
|
@e = REXML::Element.new("root")
|
||||||
|
@node1 = REXML::Element.new("node")
|
||||||
|
@node2 = REXML::Element.new("another node")
|
||||||
|
@e << @node1
|
||||||
|
@e << @node2
|
||||||
|
end
|
||||||
|
|
||||||
it "returns nil if there are no more child nodes before" do
|
it "returns the previous child node in parent" do
|
||||||
@node1.previous_sibling_node.should == nil
|
@node2.previous_sibling_node.should == @node1
|
||||||
@e.previous_sibling_node.should == nil
|
end
|
||||||
|
|
||||||
|
it "returns nil if there are no more child nodes before" do
|
||||||
|
@node1.previous_sibling_node.should == nil
|
||||||
|
@e.previous_sibling_node.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#<<" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "appends a string to this text node" do
|
require 'rexml/document'
|
||||||
text = REXML::Text.new("foo")
|
|
||||||
text << "bar"
|
describe "REXML::Text#<<" do
|
||||||
text.should == "foobar"
|
it "appends a string to this text node" do
|
||||||
|
text = REXML::Text.new("foo")
|
||||||
|
text << "bar"
|
||||||
|
text.should == "foobar"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#clone" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "creates a copy of this node" do
|
require 'rexml/document'
|
||||||
text = REXML::Text.new("foo")
|
|
||||||
text.clone.should == "foo"
|
describe "REXML::Text#clone" do
|
||||||
text.clone.should == text
|
it "creates a copy of this node" do
|
||||||
|
text = REXML::Text.new("foo")
|
||||||
|
text.clone.should == "foo"
|
||||||
|
text.clone.should == text
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#<=>" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@first = REXML::Text.new("abc")
|
|
||||||
@last = REXML::Text.new("def")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns -1 if lvalue is less than rvalue" do
|
describe "REXML::Text#<=>" do
|
||||||
val = @first <=> @last
|
before :each do
|
||||||
val.should == -1
|
@first = REXML::Text.new("abc")
|
||||||
end
|
@last = REXML::Text.new("def")
|
||||||
|
end
|
||||||
|
|
||||||
it "returns -1 if lvalue is greater than rvalue" do
|
it "returns -1 if lvalue is less than rvalue" do
|
||||||
val = @last <=> @first
|
val = @first <=> @last
|
||||||
val.should == 1
|
val.should == -1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns 0 if both values are equal" do
|
it "returns -1 if lvalue is greater than rvalue" do
|
||||||
tmp = REXML::Text.new("tmp")
|
val = @last <=> @first
|
||||||
val = tmp <=> tmp
|
val.should == 1
|
||||||
val.should == 0
|
end
|
||||||
|
|
||||||
|
it "returns 0 if both values are equal" do
|
||||||
|
tmp = REXML::Text.new("tmp")
|
||||||
|
val = tmp <=> tmp
|
||||||
|
val.should == 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#empty?" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns true if the text is empty" do
|
require 'rexml/document'
|
||||||
REXML::Text.new("").empty?.should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false if the text is not empty" do
|
describe "REXML::Text#empty?" do
|
||||||
REXML::Text.new("some_text").empty?.should == false
|
it "returns true if the text is empty" do
|
||||||
|
REXML::Text.new("").empty?.should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if the text is not empty" do
|
||||||
|
REXML::Text.new("some_text").empty?.should == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#indent_text" do
|
ruby_version_is ''...'2.8' do
|
||||||
before :each do
|
require 'rexml/document'
|
||||||
@t = REXML::Text.new("")
|
|
||||||
end
|
|
||||||
it "indents a string with default parameters" do
|
|
||||||
@t.indent_text("foo").should == "\tfoo"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "accepts a custom indentation level as second argument" do
|
describe "REXML::Text#indent_text" do
|
||||||
@t.indent_text("foo", 2, "\t", true).should == "\t\tfoo"
|
before :each do
|
||||||
end
|
@t = REXML::Text.new("")
|
||||||
|
end
|
||||||
|
it "indents a string with default parameters" do
|
||||||
|
@t.indent_text("foo").should == "\tfoo"
|
||||||
|
end
|
||||||
|
|
||||||
it "accepts a custom separator as third argument" do
|
it "accepts a custom indentation level as second argument" do
|
||||||
@t.indent_text("foo", 1, "\n", true).should == "\nfoo"
|
@t.indent_text("foo", 2, "\t", true).should == "\t\tfoo"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts a fourth parameter to skip the first line" do
|
it "accepts a custom separator as third argument" do
|
||||||
@t.indent_text("foo", 1, "\t", false).should == "foo"
|
@t.indent_text("foo", 1, "\n", true).should == "\nfoo"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts a fourth parameter to skip the first line" do
|
||||||
|
@t.indent_text("foo", 1, "\t", false).should == "foo"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#inspect" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "inspects the string attribute as a string" do
|
require 'rexml/document'
|
||||||
REXML::Text.new("a text").inspect.should == "a text".inspect
|
|
||||||
|
describe "REXML::Text#inspect" do
|
||||||
|
it "inspects the string attribute as a string" do
|
||||||
|
REXML::Text.new("a text").inspect.should == "a text".inspect
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,48 +1,51 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text.new" do
|
ruby_version_is ''...'2.8' do
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
it "creates a Text child node with no parent" do
|
describe "REXML::Text.new" do
|
||||||
t = REXML::Text.new("test")
|
|
||||||
t.should be_kind_of(REXML::Child)
|
|
||||||
t.should == "test"
|
|
||||||
t.parent.should == nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it "respects whitespace if second argument is true" do
|
it "creates a Text child node with no parent" do
|
||||||
t = REXML::Text.new("testing whitespace", true)
|
t = REXML::Text.new("test")
|
||||||
t.should == "testing whitespace"
|
t.should be_kind_of(REXML::Child)
|
||||||
t = REXML::Text.new(" ", true)
|
t.should == "test"
|
||||||
t.should == " "
|
t.parent.should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "receives a parent as third argument" do
|
it "respects whitespace if second argument is true" do
|
||||||
e = REXML::Element.new("root")
|
t = REXML::Text.new("testing whitespace", true)
|
||||||
t = REXML::Text.new("test", false, e)
|
t.should == "testing whitespace"
|
||||||
t.parent.should == e
|
t = REXML::Text.new(" ", true)
|
||||||
e.to_s.should == "<root>test</root>"
|
t.should == " "
|
||||||
end
|
end
|
||||||
|
|
||||||
it "expects escaped text if raw is true" do
|
it "receives a parent as third argument" do
|
||||||
t = REXML::Text.new("<&>", false, nil, true)
|
e = REXML::Element.new("root")
|
||||||
t.should == "<&>"
|
t = REXML::Text.new("test", false, e)
|
||||||
|
t.parent.should == e
|
||||||
|
e.to_s.should == "<root>test</root>"
|
||||||
|
end
|
||||||
|
|
||||||
->{ REXML::Text.new("<&>", false, nil, true)}.should raise_error(Exception)
|
it "expects escaped text if raw is true" do
|
||||||
end
|
t = REXML::Text.new("<&>", false, nil, true)
|
||||||
|
t.should == "<&>"
|
||||||
|
|
||||||
it "uses raw value of the parent if raw is nil" do
|
->{ REXML::Text.new("<&>", false, nil, true)}.should raise_error(Exception)
|
||||||
e1 = REXML::Element.new("root", nil, { raw: :all})
|
end
|
||||||
-> {REXML::Text.new("<&>", false, e1)}.should raise_error(Exception)
|
|
||||||
|
|
||||||
e2 = REXML::Element.new("root", nil, { raw: []})
|
it "uses raw value of the parent if raw is nil" do
|
||||||
e2.raw.should be_false
|
e1 = REXML::Element.new("root", nil, { raw: :all})
|
||||||
t1 = REXML::Text.new("<&>", false, e2)
|
-> {REXML::Text.new("<&>", false, e1)}.should raise_error(Exception)
|
||||||
t1.should == "<&>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "escapes the values if raw is false" do
|
e2 = REXML::Element.new("root", nil, { raw: []})
|
||||||
t = REXML::Text.new("<&>", false, nil, false)
|
e2.raw.should be_false
|
||||||
t.should == "<&>"
|
t1 = REXML::Text.new("<&>", false, e2)
|
||||||
|
t1.should == "<&>"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "escapes the values if raw is false" do
|
||||||
|
t = REXML::Text.new("<&>", false, nil, false)
|
||||||
|
t.should == "<&>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#node_type" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns :text" do
|
require 'rexml/document'
|
||||||
REXML::Text.new("test").node_type.should == :text
|
|
||||||
|
describe "REXML::Text#node_type" do
|
||||||
|
it "returns :text" do
|
||||||
|
REXML::Text.new("test").node_type.should == :text
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text.normalize" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "escapes a string with <, >, &, ' and \" " do
|
require 'rexml/document'
|
||||||
REXML::Text.normalize("< > & \" '").should == "< > & " '"
|
|
||||||
|
describe "REXML::Text.normalize" do
|
||||||
|
it "escapes a string with <, >, &, ' and \" " do
|
||||||
|
REXML::Text.normalize("< > & \" '").should == "< > & " '"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text.read_with_substitution" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "reads a text and escapes entities" do
|
require 'rexml/document'
|
||||||
REXML::Text.read_with_substitution("< > & " '").should == "< > & \" '"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "accepts an regex for invalid expressions and raises an error if text matches" do
|
describe "REXML::Text.read_with_substitution" do
|
||||||
-> {REXML::Text.read_with_substitution("this is illegal", /illegal/)}.should raise_error(Exception)
|
it "reads a text and escapes entities" do
|
||||||
|
REXML::Text.read_with_substitution("< > & " '").should == "< > & \" '"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts an regex for invalid expressions and raises an error if text matches" do
|
||||||
|
-> {REXML::Text.read_with_substitution("this is illegal", /illegal/)}.should raise_error(Exception)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
require 'rexml/document'
|
|
||||||
|
|
||||||
describe "REXML::Text#to_s" do
|
ruby_version_is ''...'2.8' do
|
||||||
it "returns the string of this Text node" do
|
require 'rexml/document'
|
||||||
u = REXML::Text.new("sean russell", false, nil, true)
|
|
||||||
u.to_s.should == "sean russell"
|
|
||||||
|
|
||||||
t = REXML::Text.new("some test text")
|
describe "REXML::Text#to_s" do
|
||||||
t.to_s.should == "some test text"
|
it "returns the string of this Text node" do
|
||||||
end
|
u = REXML::Text.new("sean russell", false, nil, true)
|
||||||
|
u.to_s.should == "sean russell"
|
||||||
|
|
||||||
it "escapes the text" do
|
t = REXML::Text.new("some test text")
|
||||||
t = REXML::Text.new("& < >")
|
t.to_s.should == "some test text"
|
||||||
t.to_s.should == "& < >"
|
end
|
||||||
|
|
||||||
|
it "escapes the text" do
|
||||||
|
t = REXML::Text.new("& < >")
|
||||||
|
t.to_s.should == "& < >"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue