From e61cab3a367c4040a2a487dd893c7be9a37889a9 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Sun, 12 Jan 2020 08:14:26 +0900 Subject: [PATCH] Ignore rexml examples on ruby/spec --- .../library/rexml/attribute/clone_spec.rb | 17 ++-- .../library/rexml/attribute/element_spec.rb | 39 ++++---- .../rexml/attribute/equal_value_spec.rb | 25 ++--- .../ruby/library/rexml/attribute/hash_spec.rb | 21 ++-- .../rexml/attribute/initialize_spec.rb | 45 +++++---- .../library/rexml/attribute/inspect_spec.rb | 29 +++--- .../library/rexml/attribute/namespace_spec.rb | 39 ++++---- .../library/rexml/attribute/node_type_spec.rb | 15 +-- .../library/rexml/attribute/prefix_spec.rb | 25 ++--- .../library/rexml/attribute/remove_spec.rb | 31 +++--- .../ruby/library/rexml/attribute/to_s_spec.rb | 21 ++-- .../library/rexml/attribute/to_string_spec.rb | 21 ++-- .../library/rexml/attribute/value_spec.rb | 21 ++-- .../library/rexml/attribute/write_spec.rb | 35 ++++--- .../library/rexml/attribute/xpath_spec.rb | 27 ++--- .../ruby/library/rexml/attributes/add_spec.rb | 11 ++- .../library/rexml/attributes/append_spec.rb | 11 ++- .../rexml/attributes/delete_all_spec.rb | 51 +++++----- .../library/rexml/attributes/delete_spec.rb | 43 ++++---- .../rexml/attributes/each_attribute_spec.rb | 33 ++++--- .../library/rexml/attributes/each_spec.rb | 37 +++---- .../attributes/element_reference_spec.rb | 27 ++--- .../rexml/attributes/element_set_spec.rb | 39 ++++---- .../rexml/attributes/get_attribute_ns_spec.rb | 23 +++-- .../rexml/attributes/get_attribute_spec.rb | 45 +++++---- .../rexml/attributes/initialize_spec.rb | 27 ++--- .../library/rexml/attributes/length_spec.rb | 11 ++- .../rexml/attributes/namespaces_spec.rb | 9 +- .../library/rexml/attributes/prefixes_spec.rb | 37 +++---- .../library/rexml/attributes/size_spec.rb | 11 ++- .../library/rexml/attributes/to_a_spec.rb | 27 ++--- spec/ruby/library/rexml/cdata/clone_spec.rb | 15 +-- .../library/rexml/cdata/initialize_spec.rb | 37 +++---- spec/ruby/library/rexml/cdata/to_s_spec.rb | 11 ++- spec/ruby/library/rexml/cdata/value_spec.rb | 11 ++- .../rexml/document/add_element_spec.rb | 51 +++++----- spec/ruby/library/rexml/document/add_spec.rb | 99 ++++++++++--------- .../ruby/library/rexml/document/clone_spec.rb | 33 ++++--- .../library/rexml/document/doctype_spec.rb | 23 +++-- .../library/rexml/document/encoding_spec.rb | 33 ++++--- .../rexml/document/expanded_name_spec.rb | 27 ++--- spec/ruby/library/rexml/document/new_spec.rb | 55 ++++++----- .../library/rexml/document/node_type_spec.rb | 11 ++- spec/ruby/library/rexml/document/root_spec.rb | 17 ++-- .../rexml/document/stand_alone_spec.rb | 31 +++--- .../library/rexml/document/version_spec.rb | 21 ++-- .../ruby/library/rexml/document/write_spec.rb | 57 ++++++----- .../library/rexml/document/xml_decl_spec.rb | 23 +++-- .../rexml/element/add_attribute_spec.rb | 65 ++++++------ .../rexml/element/add_attributes_spec.rb | 35 ++++--- .../library/rexml/element/add_element_spec.rb | 62 ++++++------ .../rexml/element/add_namespace_spec.rb | 35 ++++--- .../library/rexml/element/add_text_spec.rb | 37 +++---- .../library/rexml/element/attribute_spec.rb | 27 ++--- .../library/rexml/element/attributes_spec.rb | 27 ++--- .../ruby/library/rexml/element/cdatas_spec.rb | 37 +++---- spec/ruby/library/rexml/element/clone_spec.rb | 47 ++++----- .../library/rexml/element/comments_spec.rb | 31 +++--- .../rexml/element/delete_attribute_spec.rb | 62 ++++++------ .../rexml/element/delete_element_spec.rb | 81 +++++++-------- .../rexml/element/delete_namespace_spec.rb | 37 +++---- .../library/rexml/element/document_spec.rb | 23 +++-- .../each_element_with_attribute_spec.rb | 57 ++++++----- .../element/each_element_with_text_spec.rb | 49 ++++----- .../rexml/element/element_reference_spec.rb | 29 +++--- .../library/rexml/element/get_text_spec.rb | 27 ++--- .../rexml/element/has_attributes_spec.rb | 25 ++--- .../rexml/element/has_elements_spec.rb | 27 ++--- .../library/rexml/element/has_text_spec.rb | 23 +++-- .../library/rexml/element/inspect_spec.rb | 41 ++++---- .../rexml/element/instructions_spec.rb | 33 ++++--- .../library/rexml/element/namespace_spec.rb | 41 ++++---- .../library/rexml/element/namespaces_spec.rb | 51 +++++----- spec/ruby/library/rexml/element/new_spec.rb | 55 ++++++----- .../rexml/element/next_element_spec.rb | 31 +++--- .../library/rexml/element/node_type_spec.rb | 11 ++- .../library/rexml/element/prefixes_spec.rb | 35 ++++--- .../rexml/element/previous_element_spec.rb | 31 +++--- spec/ruby/library/rexml/element/raw_spec.rb | 35 ++++--- spec/ruby/library/rexml/element/root_spec.rb | 43 ++++---- spec/ruby/library/rexml/element/text_spec.rb | 79 ++++++++------- spec/ruby/library/rexml/element/texts_spec.rb | 23 +++-- .../library/rexml/element/whitespace_spec.rb | 33 ++++--- .../library/rexml/node/each_recursive_spec.rb | 35 ++++--- .../rexml/node/find_first_recursive_spec.rb | 41 ++++---- .../rexml/node/index_in_parent_spec.rb | 23 +++-- .../rexml/node/next_sibling_node_spec.rb | 33 ++++--- spec/ruby/library/rexml/node/parent_spec.rb | 31 +++--- .../rexml/node/previous_sibling_node_spec.rb | 33 ++++--- spec/ruby/library/rexml/text/append_spec.rb | 15 +-- spec/ruby/library/rexml/text/clone_spec.rb | 15 +-- .../library/rexml/text/comparison_spec.rb | 39 ++++---- spec/ruby/library/rexml/text/empty_spec.rb | 17 ++-- .../library/rexml/text/indent_text_spec.rb | 35 ++++--- spec/ruby/library/rexml/text/inspect_spec.rb | 11 ++- spec/ruby/library/rexml/text/new_spec.rb | 75 +++++++------- .../ruby/library/rexml/text/node_type_spec.rb | 11 ++- .../ruby/library/rexml/text/normalize_spec.rb | 11 ++- .../rexml/text/read_with_substitution_spec.rb | 17 ++-- spec/ruby/library/rexml/text/to_s_spec.rb | 25 ++--- .../library/rexml/text/unnormalize_spec.rb | 11 ++- spec/ruby/library/rexml/text/value_spec.rb | 61 ++++++------ spec/ruby/library/rexml/text/wrap_spec.rb | 29 +++--- .../text/write_with_substitution_spec.rb | 53 +++++----- 104 files changed, 1863 insertions(+), 1551 deletions(-) diff --git a/spec/ruby/library/rexml/attribute/clone_spec.rb b/spec/ruby/library/rexml/attribute/clone_spec.rb index 9a4a4079e1..44c8ddebcc 100644 --- a/spec/ruby/library/rexml/attribute/clone_spec.rb +++ b/spec/ruby/library/rexml/attribute/clone_spec.rb @@ -1,11 +1,14 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#clone" do - it "returns a copy of this Attribute" do - 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 +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Attribute#clone" do + it "returns a copy of this Attribute" do + 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 diff --git a/spec/ruby/library/rexml/attribute/element_spec.rb b/spec/ruby/library/rexml/attribute/element_spec.rb index 832e7e9a41..4fc4d9ed58 100644 --- a/spec/ruby/library/rexml/attribute/element_spec.rb +++ b/spec/ruby/library/rexml/attribute/element_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#element" do - it "returns the parent element" do - e = REXML::Element.new "root" +ruby_version_is ''...'2.8' do + require 'rexml/document' - REXML::Attribute.new("name", "value", e).element.should == e - REXML::Attribute.new("name", "default_constructor").element.should == nil - end -end - -describe "REXML::Attribute#element=" do - it "sets the parent element" do - e = REXML::Element.new "root" - f = REXML::Element.new "temp" - a = REXML::Attribute.new("name", "value", e) - a.element.should == e - - a.element = f - a.element.should == f + describe "REXML::Attribute#element" do + it "returns the parent element" do + e = REXML::Element.new "root" + + REXML::Attribute.new("name", "value", e).element.should == e + REXML::Attribute.new("name", "default_constructor").element.should == nil + end + end + + describe "REXML::Attribute#element=" do + it "sets the parent element" do + e = REXML::Element.new "root" + f = REXML::Element.new "temp" + a = REXML::Attribute.new("name", "value", e) + a.element.should == e + + a.element = f + a.element.should == f + end end end diff --git a/spec/ruby/library/rexml/attribute/equal_value_spec.rb b/spec/ruby/library/rexml/attribute/equal_value_spec.rb index 8bf2c0a3a1..a51e1cc390 100644 --- a/spec/ruby/library/rexml/attribute/equal_value_spec.rb +++ b/spec/ruby/library/rexml/attribute/equal_value_spec.rb @@ -1,18 +1,21 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#==" do - it "returns true if other has equal name and value" do - a1 = REXML::Attribute.new("foo", "bar") - a1.should == a1.clone +ruby_version_is ''...'2.8' do + require 'rexml/document' - a2 = REXML::Attribute.new("foo", "bar") - a1.should == a2 + describe "REXML::Attribute#==" do + 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") - a1.should_not == a3 + a2 = REXML::Attribute.new("foo", "bar") + a1.should == a2 - a4 = REXML::Attribute.new("baz", "bar") - a1.should_not == a4 + a3 = REXML::Attribute.new("foo", "bla") + a1.should_not == a3 + + a4 = REXML::Attribute.new("baz", "bar") + a1.should_not == a4 + end end end diff --git a/spec/ruby/library/rexml/attribute/hash_spec.rb b/spec/ruby/library/rexml/attribute/hash_spec.rb index dd71b28108..544cb39515 100644 --- a/spec/ruby/library/rexml/attribute/hash_spec.rb +++ b/spec/ruby/library/rexml/attribute/hash_spec.rb @@ -1,13 +1,16 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#hash" do - # These are not really complete, any idea on how to make them more - # "testable" will be appreciated. - it "returns a hashcode made of the name and value of self" do - a = REXML::Attribute.new("name", "value") - a.hash.should be_kind_of(Numeric) - b = REXML::Attribute.new(a) - a.hash.should == b.hash +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Attribute#hash" do + # These are not really complete, any idea on how to make them more + # "testable" will be appreciated. + it "returns a hashcode made of the name and value of self" do + 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 diff --git a/spec/ruby/library/rexml/attribute/initialize_spec.rb b/spec/ruby/library/rexml/attribute/initialize_spec.rb index 9f5e30c517..84c17d8b7c 100644 --- a/spec/ruby/library/rexml/attribute/initialize_spec.rb +++ b/spec/ruby/library/rexml/attribute/initialize_spec.rb @@ -1,29 +1,32 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#initialize" do - before :each do - @e = REXML::Element.new "root" - @name = REXML::Attribute.new("name", "Nicko") - @e.add_attribute @name - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "receives two strings for name and value" do - @e.attributes["name"].should == "Nicko" - @e.add_attribute REXML::Attribute.new("last_name", nil) - @e.attributes["last_name"].should == "" - end + describe "REXML::Attribute#initialize" do + before :each do + @e = REXML::Element.new "root" + @name = REXML::Attribute.new("name", "Nicko") + @e.add_attribute @name + end - it "receives an Attribute and clones it" do - copy = REXML::Attribute.new(@name) - copy.should == @name - end + it "receives two strings for name and value" do + @e.attributes["name"].should == "Nicko" + @e.add_attribute REXML::Attribute.new("last_name", nil) + @e.attributes["last_name"].should == "" + end - it "receives a parent node" do - last_name = REXML::Attribute.new("last_name", "McBrain", @e) - last_name.element.should == @e + it "receives an Attribute and clones it" do + copy = REXML::Attribute.new(@name) + copy.should == @name + end - last_name = REXML::Attribute.new(@name, @e) - last_name.element.should == @e + it "receives a parent node" do + 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 diff --git a/spec/ruby/library/rexml/attribute/inspect_spec.rb b/spec/ruby/library/rexml/attribute/inspect_spec.rb index 632b477cca..ffacf78de8 100644 --- a/spec/ruby/library/rexml/attribute/inspect_spec.rb +++ b/spec/ruby/library/rexml/attribute/inspect_spec.rb @@ -1,19 +1,22 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#inspect" do - it "returns the name and value as a string" do - a = REXML::Attribute.new("my_name", "my_value") - a.inspect.should == "my_name='my_value'" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "accepts attributes with no value" do - a = REXML::Attribute.new("my_name") - a.inspect.should == "my_name=''" - end + describe "REXML::Attribute#inspect" do + it "returns the name and value as a string" do + a = REXML::Attribute.new("my_name", "my_value") + a.inspect.should == "my_name='my_value'" + end - it "does not escape text" do - a = REXML::Attribute.new("name", "<>") - a.inspect.should == "name='<>'" + it "accepts attributes with no value" do + a = REXML::Attribute.new("my_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 diff --git a/spec/ruby/library/rexml/attribute/namespace_spec.rb b/spec/ruby/library/rexml/attribute/namespace_spec.rb index 9d50770735..9b0ff1e9c2 100644 --- a/spec/ruby/library/rexml/attribute/namespace_spec.rb +++ b/spec/ruby/library/rexml/attribute/namespace_spec.rb @@ -1,24 +1,27 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#namespace" do - it "returns the namespace url" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri") - e.namespace("ns").should == "http://some_uri" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns nil if namespace is not defined" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("test", "value") - e.namespace("test").should == nil - e.namespace("ns").should == nil - end + describe "REXML::Attribute#namespace" do + it "returns the namespace url" do + 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 "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" + it "returns nil if namespace is not defined" do + e = REXML::Element.new("root") + e.add_attribute REXML::Attribute.new("test", "value") + e.namespace("test").should == nil + 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 diff --git a/spec/ruby/library/rexml/attribute/node_type_spec.rb b/spec/ruby/library/rexml/attribute/node_type_spec.rb index 664d7cfa03..f2ba0af839 100644 --- a/spec/ruby/library/rexml/attribute/node_type_spec.rb +++ b/spec/ruby/library/rexml/attribute/node_type_spec.rb @@ -1,10 +1,13 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#node_type" do - it "always returns :attribute" do - attr = REXML::Attribute.new("foo", "bar") - attr.node_type.should == :attribute - REXML::Attribute.new(attr).node_type.should == :attribute +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Attribute#node_type" do + 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 diff --git a/spec/ruby/library/rexml/attribute/prefix_spec.rb b/spec/ruby/library/rexml/attribute/prefix_spec.rb index 2a47f74ad1..0eee50de33 100644 --- a/spec/ruby/library/rexml/attribute/prefix_spec.rb +++ b/spec/ruby/library/rexml/attribute/prefix_spec.rb @@ -1,18 +1,21 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#prefix" do - it "returns the namespace of the Attribute" do - ans = REXML::Attribute.new("ns:someattr", "some_value") - out = REXML::Attribute.new("out:something", "some_other_value") +ruby_version_is ''...'2.8' do + require 'rexml/document' - ans.prefix.should == "ns" - out.prefix.should == "out" - end + describe "REXML::Attribute#prefix" do + it "returns the namespace of the Attribute" do + 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 - attr = REXML::Attribute.new("foo", "bar") + ans.prefix.should == "ns" + 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 diff --git a/spec/ruby/library/rexml/attribute/remove_spec.rb b/spec/ruby/library/rexml/attribute/remove_spec.rb index 08d22cb6ba..c7a9904eb8 100644 --- a/spec/ruby/library/rexml/attribute/remove_spec.rb +++ b/spec/ruby/library/rexml/attribute/remove_spec.rb @@ -1,20 +1,23 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#remove" do - before :each do - @e = REXML::Element.new "Root" - @attr = REXML::Attribute.new("foo", "bar") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "deletes this Attribute from parent" do - @e.add_attribute(@attr) - @e.attributes["foo"].should_not == nil - @attr.remove - @e.attributes["foo"].should == nil - end + describe "REXML::Attribute#remove" do + before :each do + @e = REXML::Element.new "Root" + @attr = REXML::Attribute.new("foo", "bar") + end - it "does not anything if element has no parent" do - -> {@attr.remove}.should_not raise_error(Exception) + it "deletes this Attribute from parent" do + @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 diff --git a/spec/ruby/library/rexml/attribute/to_s_spec.rb b/spec/ruby/library/rexml/attribute/to_s_spec.rb index e1ce48ec33..00e7e96648 100644 --- a/spec/ruby/library/rexml/attribute/to_s_spec.rb +++ b/spec/ruby/library/rexml/attribute/to_s_spec.rb @@ -1,14 +1,17 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#to_s" do - it "returns the value of the Attribute" do - REXML::Attribute.new("name", "some_value").to_s.should == "some_value" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - 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 == "<&>" + describe "REXML::Attribute#to_s" do + it "returns the value of the Attribute" do + REXML::Attribute.new("name", "some_value").to_s.should == "some_value" + 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 diff --git a/spec/ruby/library/rexml/attribute/to_string_spec.rb b/spec/ruby/library/rexml/attribute/to_string_spec.rb index 420913afeb..f26c5b85f0 100644 --- a/spec/ruby/library/rexml/attribute/to_string_spec.rb +++ b/spec/ruby/library/rexml/attribute/to_string_spec.rb @@ -1,14 +1,17 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#to_string" do - it "returns the attribute as XML" do - attr = REXML::Attribute.new("name", "value") - attr_empty = REXML::Attribute.new("name") - attr_ns = REXML::Attribute.new("xmlns:ns", "http://uri") +ruby_version_is ''...'2.8' do + require 'rexml/document' - attr.to_string.should == "name='value'" - attr_empty.to_string.should == "name=''" - attr_ns.to_string.should == "xmlns:ns='http://uri'" + describe "REXML::Attribute#to_string" do + it "returns the attribute as XML" do + 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 diff --git a/spec/ruby/library/rexml/attribute/value_spec.rb b/spec/ruby/library/rexml/attribute/value_spec.rb index 7763976881..cf6d1deef4 100644 --- a/spec/ruby/library/rexml/attribute/value_spec.rb +++ b/spec/ruby/library/rexml/attribute/value_spec.rb @@ -1,14 +1,17 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#value" do - it "returns the value of the Attribute unnormalized" do - attr = REXML::Attribute.new("name", "value") - attr_ents = REXML::Attribute.new("name", "<&>") - attr_empty = REXML::Attribute.new("name") +ruby_version_is ''...'2.8' do + require 'rexml/document' - attr.value.should == "value" - attr_ents.value.should == "<&>" - attr_empty.value.should == "" + describe "REXML::Attribute#value" do + it "returns the value of the Attribute unnormalized" do + 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 diff --git a/spec/ruby/library/rexml/attribute/write_spec.rb b/spec/ruby/library/rexml/attribute/write_spec.rb index 7ada7460f9..f69689e724 100644 --- a/spec/ruby/library/rexml/attribute/write_spec.rb +++ b/spec/ruby/library/rexml/attribute/write_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#write" do - before :each do - @attr = REXML::Attribute.new("name", "Charlotte") - @s = "" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "writes the name and value to output" do - @attr.write(@s) - @s.should == "name='Charlotte'" - end + describe "REXML::Attribute#write" do + before :each do + @attr = REXML::Attribute.new("name", "Charlotte") + @s = "" + end - it "currently ignores the second argument" do - @attr.write(@s, 3) - @s.should == "name='Charlotte'" + it "writes the name and value to output" do + @attr.write(@s) + @s.should == "name='Charlotte'" + end - @s = "" - @attr.write(@s, "foo") - @s.should == "name='Charlotte'" + it "currently ignores the second argument" do + @attr.write(@s, 3) + @s.should == "name='Charlotte'" + + @s = "" + @attr.write(@s, "foo") + @s.should == "name='Charlotte'" + end end end diff --git a/spec/ruby/library/rexml/attribute/xpath_spec.rb b/spec/ruby/library/rexml/attribute/xpath_spec.rb index 8335e0a8ef..945e76280f 100644 --- a/spec/ruby/library/rexml/attribute/xpath_spec.rb +++ b/spec/ruby/library/rexml/attribute/xpath_spec.rb @@ -1,19 +1,22 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attribute#xpath" do +ruby_version_is ''...'2.8' do + require 'rexml/document' - before :each do - @e = REXML::Element.new "root" - @attr = REXML::Attribute.new("year", "1989") - end + describe "REXML::Attribute#xpath" do - it "returns the path for Attribute" do - @e.add_attribute @attr - @attr.xpath.should == "root/@year" - end + before :each do + @e = REXML::Element.new "root" + @attr = REXML::Attribute.new("year", "1989") + end - it "raises an error if attribute has no parent" do - -> { @attr.xpath }.should raise_error(Exception) + it "returns the path for Attribute" do + @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 diff --git a/spec/ruby/library/rexml/attributes/add_spec.rb b/spec/ruby/library/rexml/attributes/add_spec.rb index 32a927e10b..fd23bd458c 100644 --- a/spec/ruby/library/rexml/attributes/add_spec.rb +++ b/spec/ruby/library/rexml/attributes/add_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require_relative 'shared/add' -require 'rexml/document' -describe "REXML::Attributes#add" do - it_behaves_like :rexml_attribute_add, :add +ruby_version_is ''...'2.8' do + require_relative 'shared/add' + require 'rexml/document' + + describe "REXML::Attributes#add" do + it_behaves_like :rexml_attribute_add, :add + end end diff --git a/spec/ruby/library/rexml/attributes/append_spec.rb b/spec/ruby/library/rexml/attributes/append_spec.rb index f1b08f7d6a..99585979f2 100644 --- a/spec/ruby/library/rexml/attributes/append_spec.rb +++ b/spec/ruby/library/rexml/attributes/append_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require_relative 'shared/add' -require 'rexml/document' -describe "REXML::Attributes#<<" do - it_behaves_like :rexml_attribute_add, :<< +ruby_version_is ''...'2.8' do + require_relative 'shared/add' + require 'rexml/document' + + describe "REXML::Attributes#<<" do + it_behaves_like :rexml_attribute_add, :<< + end end diff --git a/spec/ruby/library/rexml/attributes/delete_all_spec.rb b/spec/ruby/library/rexml/attributes/delete_all_spec.rb index 9340b5693b..f5e6a897c5 100644 --- a/spec/ruby/library/rexml/attributes/delete_all_spec.rb +++ b/spec/ruby/library/rexml/attributes/delete_all_spec.rb @@ -1,31 +1,34 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#delete_all" do - before :each do - @e = REXML::Element.new("root") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "deletes all attributes that match name" do - uri = REXML::Attribute.new("uri", "http://something") - @e.attributes << uri - @e.attributes.delete_all("uri") - @e.attributes.should be_empty - @e.attributes["uri"].should == nil - end + describe "REXML::Attributes#delete_all" do + before :each do + @e = REXML::Element.new("root") + end - it "deletes all attributes that match name with a namespace" do - ns_uri = REXML::Attribute.new("xmlns:uri", "http://something_here_too") - @e.attributes << ns_uri - @e.attributes.delete_all("xmlns:uri") - @e.attributes.should be_empty - @e.attributes["xmlns:uri"].should == nil - end + it "deletes all attributes that match name" do + uri = REXML::Attribute.new("uri", "http://something") + @e.attributes << uri + @e.attributes.delete_all("uri") + @e.attributes.should be_empty + @e.attributes["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 + it "deletes all attributes that match name with a namespace" do + ns_uri = REXML::Attribute.new("xmlns:uri", "http://something_here_too") + @e.attributes << ns_uri + @e.attributes.delete_all("xmlns: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 diff --git a/spec/ruby/library/rexml/attributes/delete_spec.rb b/spec/ruby/library/rexml/attributes/delete_spec.rb index 495e4085ef..59641e55db 100644 --- a/spec/ruby/library/rexml/attributes/delete_spec.rb +++ b/spec/ruby/library/rexml/attributes/delete_spec.rb @@ -1,27 +1,30 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#delete" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Pepe") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "takes an attribute name and deletes the attribute" do - @e.attributes.delete("name") - @e.attributes["name"].should be_nil - @e.attributes.should be_empty - end + describe "REXML::Attributes#delete" do + before :each do + @e = REXML::Element.new("root") + @name = REXML::Attribute.new("name", "Pepe") + end - it "takes an Attribute and deletes it" do - @e.attributes.delete(@name) - @e.attributes["name"].should be_nil - @e.attributes.should be_empty - end + it "takes an attribute name and deletes the attribute" do + @e.attributes.delete("name") + @e.attributes["name"].should be_nil + @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 + it "takes an Attribute and deletes it" do + @e.attributes.delete(@name) + @e.attributes["name"].should be_nil + @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 diff --git a/spec/ruby/library/rexml/attributes/each_attribute_spec.rb b/spec/ruby/library/rexml/attributes/each_attribute_spec.rb index e84c8dbf51..1e6b5c1c1f 100644 --- a/spec/ruby/library/rexml/attributes/each_attribute_spec.rb +++ b/spec/ruby/library/rexml/attributes/each_attribute_spec.rb @@ -1,22 +1,25 @@ require_relative '../../../spec_helper' -require 'rexml/document' -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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - 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 << attr + attributes = [] + + 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 - - attributes = attributes.sort_by {|a| a.name } - attributes.first.should == name - attributes.last.should == ns_uri end end diff --git a/spec/ruby/library/rexml/attributes/each_spec.rb b/spec/ruby/library/rexml/attributes/each_spec.rb index ed60634b90..4865114cf1 100644 --- a/spec/ruby/library/rexml/attributes/each_spec.rb +++ b/spec/ruby/library/rexml/attributes/each_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#each" do - before :each 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 - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "iterates over the attributes yielding expanded-name/value" do - attributes = [] - @e.attributes.each do |attr| - attr.should be_kind_of(Array) - attributes << attr + describe "REXML::Attributes#each" do + before :each 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 + 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 - attributes = attributes.sort_by {|a| a.first } - attributes.first.should == ["name", "Joe"] - attributes.last.should == ["xmlns:ns", "http://some_uri"] end end diff --git a/spec/ruby/library/rexml/attributes/element_reference_spec.rb b/spec/ruby/library/rexml/attributes/element_reference_spec.rb index dac7952669..86e0c57fc9 100644 --- a/spec/ruby/library/rexml/attributes/element_reference_spec.rb +++ b/spec/ruby/library/rexml/attributes/element_reference_spec.rb @@ -1,18 +1,21 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#[]" do - before :each do - @e = REXML::Element.new("root") - @lang = REXML::Attribute.new("language", "english") - @e.attributes << @lang - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the value of an attribute" do - @e.attributes["language"].should == "english" - end + describe "REXML::Attributes#[]" do + before :each do + @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 - @e.attributes["chunky bacon"].should == nil + it "returns the value of an attribute" do + @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 diff --git a/spec/ruby/library/rexml/attributes/element_set_spec.rb b/spec/ruby/library/rexml/attributes/element_set_spec.rb index 1ed94dd2a1..90096be82c 100644 --- a/spec/ruby/library/rexml/attributes/element_set_spec.rb +++ b/spec/ruby/library/rexml/attributes/element_set_spec.rb @@ -1,25 +1,28 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#[]=" do - before :each do - @e = REXML::Element.new("song") - @name = REXML::Attribute.new("name", "Holy Smoke!") - @e.attributes << @name - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "sets an attribute" do - @e.attributes["author"] = "_why's foxes" - @e.attributes["author"].should == "_why's foxes" - end + describe "REXML::Attributes#[]=" do + before :each do + @e = REXML::Element.new("song") + @name = REXML::Attribute.new("name", "Holy Smoke!") + @e.attributes << @name + end - it "overwrites an existing attribute" do - @e.attributes["name"] = "Chunky Bacon" - @e.attributes["name"].should == "Chunky Bacon" - end + it "sets an attribute" do + @e.attributes["author"] = "_why's foxes" + @e.attributes["author"].should == "_why's foxes" + end - it "deletes an attribute is value is nil" do - @e.attributes["name"] = nil - @e.attributes.length.should == 0 + it "overwrites an existing attribute" do + @e.attributes["name"] = "Chunky Bacon" + @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 diff --git a/spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb b/spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb index 1664d6e42a..56ed733d37 100644 --- a/spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb +++ b/spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb @@ -1,14 +1,17 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#get_attribute_ns" do - it "returns an attribute by name and namespace" do - e = REXML::Element.new("root") - attr = REXML::Attribute.new("xmlns:ns", "http://some_url") - e.attributes << attr - 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" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Attributes#get_attribute_ns" do + it "returns an attribute by name and namespace" do + e = REXML::Element.new("root") + attr = REXML::Attribute.new("xmlns:ns", "http://some_url") + e.attributes << attr + 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 diff --git a/spec/ruby/library/rexml/attributes/get_attribute_spec.rb b/spec/ruby/library/rexml/attributes/get_attribute_spec.rb index cfe58c1b9e..cf08446eaf 100644 --- a/spec/ruby/library/rexml/attributes/get_attribute_spec.rb +++ b/spec/ruby/library/rexml/attributes/get_attribute_spec.rb @@ -1,29 +1,32 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#get_attribute" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Dave") - @e.attributes << @name - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "fetches an attributes" do - @e.attributes.get_attribute("name").should == @name - end + describe "REXML::Attributes#get_attribute" do + before :each do + @e = REXML::Element.new("root") + @name = REXML::Attribute.new("name", "Dave") + @e.attributes << @name + end - it "fetches an namespaced attribute" do - ns_name = REXML::Attribute.new("im:name", "Murray") - @e.attributes << ns_name - @e.attributes.get_attribute("name").should == @name - @e.attributes.get_attribute("im:name").should == ns_name - end + it "fetches an attributes" do + @e.attributes.get_attribute("name").should == @name + end - it "returns an Attribute" do - @e.attributes.get_attribute("name").should be_kind_of(REXML::Attribute) - end + it "fetches an namespaced attribute" do + ns_name = REXML::Attribute.new("im:name", "Murray") + @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 - @e.attributes.get_attribute("fake").should be_nil + it "returns an Attribute" do + @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 diff --git a/spec/ruby/library/rexml/attributes/initialize_spec.rb b/spec/ruby/library/rexml/attributes/initialize_spec.rb index f18bd20c69..f7c9652171 100644 --- a/spec/ruby/library/rexml/attributes/initialize_spec.rb +++ b/spec/ruby/library/rexml/attributes/initialize_spec.rb @@ -1,18 +1,21 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#initialize" do - it "is auto initialized by Element" do - e = REXML::Element.new "root" - e.attributes.should be_kind_of(REXML::Attributes) +ruby_version_is ''...'2.8' do + require 'rexml/document' - e.attributes << REXML::Attribute.new("name", "Paul") - e.attributes["name"].should == "Paul" - end + describe "REXML::Attributes#initialize" do + it "is auto initialized by Element" do + e = REXML::Element.new "root" + e.attributes.should be_kind_of(REXML::Attributes) - it "receives a parent node" do - e = REXML::Element.new "root" - e.attributes << REXML::Attribute.new("name", "Vic") - e.attributes["name"].should == "Vic" + e.attributes << REXML::Attribute.new("name", "Paul") + e.attributes["name"].should == "Paul" + end + + 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 diff --git a/spec/ruby/library/rexml/attributes/length_spec.rb b/spec/ruby/library/rexml/attributes/length_spec.rb index 3a8361b8d7..60a348ef7b 100644 --- a/spec/ruby/library/rexml/attributes/length_spec.rb +++ b/spec/ruby/library/rexml/attributes/length_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require_relative 'shared/length' -require 'rexml/document' -describe "REXML::Attributes#length" do - it_behaves_like :rexml_attribute_length, :length +ruby_version_is ''...'2.8' do + require_relative 'shared/length' + require 'rexml/document' + + describe "REXML::Attributes#length" do + it_behaves_like :rexml_attribute_length, :length + end end diff --git a/spec/ruby/library/rexml/attributes/namespaces_spec.rb b/spec/ruby/library/rexml/attributes/namespaces_spec.rb index 9e329fef6f..80c40ccc90 100644 --- a/spec/ruby/library/rexml/attributes/namespaces_spec.rb +++ b/spec/ruby/library/rexml/attributes/namespaces_spec.rb @@ -1,6 +1,9 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#namespaces" do - it "needs to be reviewed for spec completeness" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Attributes#namespaces" do + it "needs to be reviewed for spec completeness" + end end diff --git a/spec/ruby/library/rexml/attributes/prefixes_spec.rb b/spec/ruby/library/rexml/attributes/prefixes_spec.rb index 4675095aad..2c1e3f8705 100644 --- a/spec/ruby/library/rexml/attributes/prefixes_spec.rb +++ b/spec/ruby/library/rexml/attributes/prefixes_spec.rb @@ -1,24 +1,27 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#prefixes" do - 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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - @e.attributes << REXML::Attribute.new("xmlns", "foo") - end + describe "REXML::Attributes#prefixes" do + 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.prefixes.sort.should == ["a", "b", "c"] - end + @e.attributes << REXML::Attribute.new("xmlns", "foo") + end - it "does not include the default namespace" do - @e.attributes.prefixes.include?("xmlns").should == false + it "returns an array with the prefixes of each attribute" do + @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 diff --git a/spec/ruby/library/rexml/attributes/size_spec.rb b/spec/ruby/library/rexml/attributes/size_spec.rb index 3b1df9510d..e7fad6bd11 100644 --- a/spec/ruby/library/rexml/attributes/size_spec.rb +++ b/spec/ruby/library/rexml/attributes/size_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require_relative 'shared/length' -require 'rexml/document' -describe "REXML::Attributes#size" do - it_behaves_like :rexml_attribute_length, :size +ruby_version_is ''...'2.8' do + require_relative 'shared/length' + require 'rexml/document' + + describe "REXML::Attributes#size" do + it_behaves_like :rexml_attribute_length, :size + end end diff --git a/spec/ruby/library/rexml/attributes/to_a_spec.rb b/spec/ruby/library/rexml/attributes/to_a_spec.rb index 1fbf71b683..cc98e4f0d9 100644 --- a/spec/ruby/library/rexml/attributes/to_a_spec.rb +++ b/spec/ruby/library/rexml/attributes/to_a_spec.rb @@ -1,19 +1,22 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Attributes#to_a" do - 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") +ruby_version_is ''...'2.8' do + require 'rexml/document' - e.attributes << name - e.attributes << last + describe "REXML::Attributes#to_a" do + 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] - end + e.attributes << name + e.attributes << last - it "returns an empty array if it has no attributes" do - REXML::Element.new("root").attributes.to_a.should == [] + e.attributes.to_a.sort{|a,b|a.to_s<=>b.to_s}.should == [name, last] + end + + it "returns an empty array if it has no attributes" do + REXML::Element.new("root").attributes.to_a.should == [] + end end end diff --git a/spec/ruby/library/rexml/cdata/clone_spec.rb b/spec/ruby/library/rexml/cdata/clone_spec.rb index 7d3cfda902..e8e322f9a5 100644 --- a/spec/ruby/library/rexml/cdata/clone_spec.rb +++ b/spec/ruby/library/rexml/cdata/clone_spec.rb @@ -1,10 +1,13 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::CData#clone" do - 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 +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::CData#clone" do + 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 diff --git a/spec/ruby/library/rexml/cdata/initialize_spec.rb b/spec/ruby/library/rexml/cdata/initialize_spec.rb index 0184440d87..2ef1cab2b3 100644 --- a/spec/ruby/library/rexml/cdata/initialize_spec.rb +++ b/spec/ruby/library/rexml/cdata/initialize_spec.rb @@ -1,24 +1,27 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::CData#initialize" do - it "creates a new CData object" do - c = REXML::CData.new("some text") - c.should be_kind_of(REXML::CData) - c.should be_kind_of(REXML::Text) - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "respects whitespace if whitespace is true" do - c = REXML::CData.new("whitespace test", true) - c1 = REXML::CData.new("whitespace test", false) + describe "REXML::CData#initialize" do + it "creates a new CData object" do + 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" - c1.to_s.should == "whitespace test" - end + it "respects whitespace if whitespace is true" do + c = REXML::CData.new("whitespace test", true) + c1 = REXML::CData.new("whitespace test", false) - it "receives parent as third argument" do - e = REXML::Element.new("root") - REXML::CData.new("test", true, e) - e.to_s.should == "" + c.to_s.should == "whitespace test" + c1.to_s.should == "whitespace test" + end + + it "receives parent as third argument" do + e = REXML::Element.new("root") + REXML::CData.new("test", true, e) + e.to_s.should == "" + end end end diff --git a/spec/ruby/library/rexml/cdata/to_s_spec.rb b/spec/ruby/library/rexml/cdata/to_s_spec.rb index ff3076e55e..e42d7491b8 100644 --- a/spec/ruby/library/rexml/cdata/to_s_spec.rb +++ b/spec/ruby/library/rexml/cdata/to_s_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require_relative 'shared/to_s' -require 'rexml/document' -describe "REXML::CData#to_s" do - it_behaves_like :rexml_cdata_to_s, :to_s +ruby_version_is ''...'2.8' do + 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 diff --git a/spec/ruby/library/rexml/cdata/value_spec.rb b/spec/ruby/library/rexml/cdata/value_spec.rb index 6e8f8587a1..1c25cb205e 100644 --- a/spec/ruby/library/rexml/cdata/value_spec.rb +++ b/spec/ruby/library/rexml/cdata/value_spec.rb @@ -1,7 +1,10 @@ require_relative '../../../spec_helper' -require_relative 'shared/to_s' -require 'rexml/document' -describe "REXML::CData#value" do - it_behaves_like :rexml_cdata_to_s, :value +ruby_version_is ''...'2.8' do + require_relative 'shared/to_s' + require 'rexml/document' + + describe "REXML::CData#value" do + it_behaves_like :rexml_cdata_to_s, :value + end end diff --git a/spec/ruby/library/rexml/document/add_element_spec.rb b/spec/ruby/library/rexml/document/add_element_spec.rb index 42981d6465..cc0617c061 100644 --- a/spec/ruby/library/rexml/document/add_element_spec.rb +++ b/spec/ruby/library/rexml/document/add_element_spec.rb @@ -1,31 +1,34 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#add_element" do - it "adds arg1 with attributes arg2 as root node" do - d = REXML::Document.new - e = REXML::Element.new("root") - d.add_element e - d.root.should == e - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "sets arg2 as arg1's attributes" do - d = REXML::Document.new - e = REXML::Element.new("root") - attr = {"foo" => "bar"} - d.add_element(e,attr) - d.root.attributes["foo"].should == attr["foo"] - end + describe "REXML::Document#add_element" do + it "adds arg1 with attributes arg2 as root node" do + d = REXML::Document.new + e = REXML::Element.new("root") + d.add_element e + d.root.should == e + end - it "accepts a node name as arg1 and adds it as root" do - d = REXML::Document.new - d.add_element "foo" - d.root.name.should == "foo" - end + it "sets arg2 as arg1's attributes" do + d = REXML::Document.new + e = REXML::Element.new("root") + attr = {"foo" => "bar"} + d.add_element(e,attr) + d.root.attributes["foo"].should == attr["foo"] + end - it "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 + it "accepts a node name as arg1 and adds it as root" do + d = REXML::Document.new + d.add_element "foo" + d.root.name.should == "foo" + end + + it "sets arg1's context to the root's context" do + d = REXML::Document.new("", {"foo" => "bar"}) + d.add_element "foo" + d.root.context.should == d.context + end end end diff --git a/spec/ruby/library/rexml/document/add_spec.rb b/spec/ruby/library/rexml/document/add_spec.rb index db95114e7e..10056ed1e7 100644 --- a/spec/ruby/library/rexml/document/add_spec.rb +++ b/spec/ruby/library/rexml/document/add_spec.rb @@ -1,57 +1,60 @@ -require 'rexml/document' 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 - before :each do - @doc = REXML::Document.new("") - @decl = REXML::XMLDecl.new("1.0") + # This spec defines Document#add and Document#<< + + describe :rexml_document_add, shared: true do + before :each do + @doc = REXML::Document.new("") + @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 - it "sets document's XML declaration" do - @doc.send(@method, @decl) - @doc.xml_decl.should == @decl + describe "REXML::Document#add" do + it_behaves_like :rexml_document_add, :add 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) + describe "REXML::Document#<<" do + it_behaves_like :rexml_document_add, :<< 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 diff --git a/spec/ruby/library/rexml/document/clone_spec.rb b/spec/ruby/library/rexml/document/clone_spec.rb index 4aebb6f156..2106c72888 100644 --- a/spec/ruby/library/rexml/document/clone_spec.rb +++ b/spec/ruby/library/rexml/document/clone_spec.rb @@ -1,20 +1,23 @@ -require 'rexml/document' require_relative '../../../spec_helper' -# According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html), -# clone's behavior "should be obvious". Apparently "obvious" means cloning -# only the attributes and the context of the document, not its children. -describe "REXML::Document#clone" do - it "clones document attributes" do - d = REXML::Document.new("foo") - d.attributes["foo"] = "bar" - e = d.clone - e.attributes.should == d.attributes - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "clones document context" do - d = REXML::Document.new("foo", {"foo" => "bar"}) - e = d.clone - e.context.should == d.context + # According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html), + # clone's behavior "should be obvious". Apparently "obvious" means cloning + # only the attributes and the context of the document, not its children. + describe "REXML::Document#clone" do + it "clones document attributes" do + d = REXML::Document.new("foo") + d.attributes["foo"] = "bar" + e = d.clone + e.attributes.should == d.attributes + end + + it "clones document context" do + d = REXML::Document.new("foo", {"foo" => "bar"}) + e = d.clone + e.context.should == d.context + end end end diff --git a/spec/ruby/library/rexml/document/doctype_spec.rb b/spec/ruby/library/rexml/document/doctype_spec.rb index b919b071e1..4d14460ef4 100644 --- a/spec/ruby/library/rexml/document/doctype_spec.rb +++ b/spec/ruby/library/rexml/document/doctype_spec.rb @@ -1,15 +1,18 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#doctype" do - it "returns the doctype" do - d = REXML::Document.new - dt = REXML::DocType.new("foo") - d.add dt - d.doctype.should == dt - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns nil if there's no doctype" do - REXML::Document.new.doctype.should == nil + describe "REXML::Document#doctype" do + it "returns the doctype" do + d = REXML::Document.new + dt = REXML::DocType.new("foo") + d.add dt + d.doctype.should == dt + end + + it "returns nil if there's no doctype" do + REXML::Document.new.doctype.should == nil + end end end diff --git a/spec/ruby/library/rexml/document/encoding_spec.rb b/spec/ruby/library/rexml/document/encoding_spec.rb index 343e0ee45f..aa140b0f6f 100644 --- a/spec/ruby/library/rexml/document/encoding_spec.rb +++ b/spec/ruby/library/rexml/document/encoding_spec.rb @@ -1,22 +1,25 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#encoding" do - before :each do - @doc = REXML::Document.new - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns encoding from XML declaration" do - @doc.add REXML::XMLDecl.new(nil, "UTF-16", nil) - @doc.encoding.should == "UTF-16" - end + describe "REXML::Document#encoding" do + before :each do + @doc = REXML::Document.new + end - it "returns encoding from XML declaration (for UTF-16 as well)" do - @doc.add REXML::XMLDecl.new("1.0", "UTF-8", nil) - @doc.encoding.should == "UTF-8" - end + it "returns encoding from XML declaration" do + @doc.add REXML::XMLDecl.new(nil, "UTF-16", nil) + @doc.encoding.should == "UTF-16" + end - it "uses UTF-8 as default encoding" do - @doc.encoding.should == "UTF-8" + it "returns encoding from XML declaration (for UTF-16 as well)" do + @doc.add REXML::XMLDecl.new("1.0", "UTF-8", nil) + @doc.encoding.should == "UTF-8" + end + + it "uses UTF-8 as default encoding" do + @doc.encoding.should == "UTF-8" + end end end diff --git a/spec/ruby/library/rexml/document/expanded_name_spec.rb b/spec/ruby/library/rexml/document/expanded_name_spec.rb index 1225d13fb0..4f53914326 100644 --- a/spec/ruby/library/rexml/document/expanded_name_spec.rb +++ b/spec/ruby/library/rexml/document/expanded_name_spec.rb @@ -1,16 +1,19 @@ -require 'rexml/document' require_relative '../../../spec_helper' -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 == "" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + 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 - -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 diff --git a/spec/ruby/library/rexml/document/new_spec.rb b/spec/ruby/library/rexml/document/new_spec.rb index 3ff5e99b25..52b20341f4 100644 --- a/spec/ruby/library/rexml/document/new_spec.rb +++ b/spec/ruby/library/rexml/document/new_spec.rb @@ -1,36 +1,39 @@ 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 - d = REXML::Document.new("") - d.context.should == {} - end + describe "REXML::Document#new" do - it "has empty attributes if source is nil" do - d = REXML::Document.new(nil) - d.elements.should be_empty - end + it "initializes context of {} unless specified" do + d = REXML::Document.new("") + d.context.should == {} + end - it "can use other document context" do - s = REXML::Document.new("") - d = REXML::Document.new(s) - d.context.should == s.context - end + it "has empty attributes if source is nil" do + d = REXML::Document.new(nil) + d.elements.should be_empty + end - it "clones source attributes" do - s = REXML::Document.new("") - s.attributes["some_attr"] = "some_val" - d = REXML::Document.new(s) - d.attributes.should == s.attributes - end + it "can use other document context" do + s = REXML::Document.new("") + d = REXML::Document.new(s) + d.context.should == s.context + end - it "raises an error if source is not a Document, String or IO" do - -> {REXML::Document.new(3)}.should raise_error(RuntimeError) - end + it "clones source attributes" do + s = REXML::Document.new("") + s.attributes["some_attr"] = "some_val" + d = REXML::Document.new(s) + d.attributes.should == s.attributes + end - it "does not perform XML validation" do - REXML::Document.new("Invalid document").should be_kind_of(REXML::Document) + it "raises an error if source is not a Document, String or IO" do + -> {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 diff --git a/spec/ruby/library/rexml/document/node_type_spec.rb b/spec/ruby/library/rexml/document/node_type_spec.rb index 85a4d507aa..13aa6a6eb5 100644 --- a/spec/ruby/library/rexml/document/node_type_spec.rb +++ b/spec/ruby/library/rexml/document/node_type_spec.rb @@ -1,8 +1,11 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#node_type" do - it "returns :document" do - REXML::Document.new.node_type.should == :document +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Document#node_type" do + it "returns :document" do + REXML::Document.new.node_type.should == :document + end end end diff --git a/spec/ruby/library/rexml/document/root_spec.rb b/spec/ruby/library/rexml/document/root_spec.rb index 3c24e79b2d..e01b0fa67c 100644 --- a/spec/ruby/library/rexml/document/root_spec.rb +++ b/spec/ruby/library/rexml/document/root_spec.rb @@ -1,12 +1,15 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#root" do - it "returns document root tag name" do - REXML::Document.new("").root.name.should == "foo" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns nil if there is not root" do - REXML::Document.new.root.should == nil + describe "REXML::Document#root" do + it "returns document root tag name" do + REXML::Document.new("").root.name.should == "foo" + end + + it "returns nil if there is not root" do + REXML::Document.new.root.should == nil + end end end diff --git a/spec/ruby/library/rexml/document/stand_alone_spec.rb b/spec/ruby/library/rexml/document/stand_alone_spec.rb index 4ac24329d6..667b2c0184 100644 --- a/spec/ruby/library/rexml/document/stand_alone_spec.rb +++ b/spec/ruby/library/rexml/document/stand_alone_spec.rb @@ -1,19 +1,22 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#stand_alone?" do - it "returns the XMLDecl standalone value" do - d = REXML::Document.new - decl = REXML::XMLDecl.new("1.0", "UTF-8", "yes") - d.add decl - d.stand_alone?.should == "yes" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - # 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 + describe "REXML::Document#stand_alone?" do + it "returns the XMLDecl standalone value" do + d = REXML::Document.new + decl = REXML::XMLDecl.new("1.0", "UTF-8", "yes") + d.add decl + d.stand_alone?.should == "yes" + end + # According to the docs this should return the default XMLDecl but that + # will carry some more problems when printing the document. Currently, it + # returns nil. See http://www.ruby-forum.com/topic/146812#650061 + it "returns the default value when no XML declaration present" do + REXML::Document.new.stand_alone?.should == nil + end + + end end diff --git a/spec/ruby/library/rexml/document/version_spec.rb b/spec/ruby/library/rexml/document/version_spec.rb index 983b4b9af0..8e0f66cb07 100644 --- a/spec/ruby/library/rexml/document/version_spec.rb +++ b/spec/ruby/library/rexml/document/version_spec.rb @@ -1,14 +1,17 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#version" do - it "returns XML version from declaration" do - d = REXML::Document.new - d.add REXML::XMLDecl.new("1.1") - d.version.should == "1.1" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the default version when declaration is not present" do - REXML::Document.new.version.should == REXML::XMLDecl::DEFAULT_VERSION + describe "REXML::Document#version" do + it "returns XML version from declaration" do + d = REXML::Document.new + d.add REXML::XMLDecl.new("1.1") + d.version.should == "1.1" + end + + it "returns the default version when declaration is not present" do + REXML::Document.new.version.should == REXML::XMLDecl::DEFAULT_VERSION + end end end diff --git a/spec/ruby/library/rexml/document/write_spec.rb b/spec/ruby/library/rexml/document/write_spec.rb index efa94b7117..774c12982c 100644 --- a/spec/ruby/library/rexml/document/write_spec.rb +++ b/spec/ruby/library/rexml/document/write_spec.rb @@ -1,35 +1,38 @@ -require 'rexml/document' -require 'rexml/formatters/transitive' require_relative '../../../spec_helper' -# Maybe this can be cleaned -describe "REXML::Document#write" do - before :each do - @d = REXML::Document.new - city = REXML::Element.new "Springfield" - street = REXML::Element.new "EvergreenTerrace" - address = REXML::Element.new "House742" - @d << city << street << address - @str = "" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' + require 'rexml/formatters/transitive' - it "returns document source as string" do - @d.write(@str) - @str.should == "" - end + # Maybe this can be cleaned + describe "REXML::Document#write" do + before :each do + @d = REXML::Document.new + city = REXML::Element.new "Springfield" + street = REXML::Element.new "EvergreenTerrace" + address = REXML::Element.new "House742" + @d << city << street << address + @str = "" + end - it "returns document indented" do - @d.write(@str, 2) - @str.should =~ /\s*\s*\s*\s*<\/EvergreenTerrace>\s*<\/Springfield>/ - end + it "returns document source as string" do + @d.write(@str) + @str.should == "" + end - it "returns document with transitive support" do - @d.write(@str, 2, true) - @str.should =~ /\s*<\/EvergreenTerrace\s*><\/Springfield\s*>/ - end + it "returns document indented" do + @d.write(@str, 2) + @str.should =~ /\s*\s*\s*\s*<\/EvergreenTerrace>\s*<\/Springfield>/ + end - it "returns document with support for IE" do - @d.write(@str, -1, false, true) - @str.should == "" + it "returns document with transitive support" do + @d.write(@str, 2, true) + @str.should =~ /\s*<\/EvergreenTerrace\s*><\/Springfield\s*>/ + end + + it "returns document with support for IE" do + @d.write(@str, -1, false, true) + @str.should == "" + end end end diff --git a/spec/ruby/library/rexml/document/xml_decl_spec.rb b/spec/ruby/library/rexml/document/xml_decl_spec.rb index 30288a150b..6862c7bb6b 100644 --- a/spec/ruby/library/rexml/document/xml_decl_spec.rb +++ b/spec/ruby/library/rexml/document/xml_decl_spec.rb @@ -1,15 +1,18 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Document#xml_decl" do - it "returns XML declaration of the document" do - d = REXML::Document.new - decl = REXML::XMLDecl.new("1.0", "UTF-16", "yes") - d.add decl - d.xml_decl.should == decl - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns default XML declaration unless present" do - REXML::Document.new.xml_decl.should == REXML::XMLDecl.new + describe "REXML::Document#xml_decl" do + it "returns XML declaration of the document" do + d = REXML::Document.new + decl = REXML::XMLDecl.new("1.0", "UTF-16", "yes") + d.add decl + d.xml_decl.should == decl + end + + it "returns default XML declaration unless present" do + REXML::Document.new.xml_decl.should == REXML::XMLDecl.new + end end end diff --git a/spec/ruby/library/rexml/element/add_attribute_spec.rb b/spec/ruby/library/rexml/element/add_attribute_spec.rb index d15fb81ef1..b688f1db65 100644 --- a/spec/ruby/library/rexml/element/add_attribute_spec.rb +++ b/spec/ruby/library/rexml/element/add_attribute_spec.rb @@ -1,41 +1,44 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#add_attribute" do - before :each do - @person = REXML::Element.new "person" - @person.attributes["name"] = "Bill" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "adds a new attribute" do - @person.add_attribute("age", "17") - @person.attributes["age"].should == "17" - end + describe "REXML::Element#add_attribute" do + before :each do + @person = REXML::Element.new "person" + @person.attributes["name"] = "Bill" + end - it "overwrites an existing attribute" do - @person.add_attribute("name", "Bill") - @person.attributes["name"].should == "Bill" - end + it "adds a new attribute" do + @person.add_attribute("age", "17") + @person.attributes["age"].should == "17" + end - it "accepts a pair of strings" do - @person.add_attribute("male", "true") - @person.attributes["male"].should == "true" - end + it "overwrites an existing attribute" do + @person.add_attribute("name", "Bill") + @person.attributes["name"].should == "Bill" + end - it "accepts an Attribute for key" do - attr = REXML::Attribute.new("male", "true") - @person.add_attribute attr - @person.attributes["male"].should == "true" - end + it "accepts a pair of strings" do + @person.add_attribute("male", "true") + @person.attributes["male"].should == "true" + end - it "ignores value if key is an Attribute" do - attr = REXML::Attribute.new("male", "true") - @person.add_attribute(attr, "false") - @person.attributes["male"].should == "true" - end + it "accepts an Attribute for key" do + attr = REXML::Attribute.new("male", "true") + @person.add_attribute attr + @person.attributes["male"].should == "true" + end - it "returns the attribute added" do - attr = REXML::Attribute.new("name", "Tony") - @person.add_attribute(attr).should == attr + it "ignores value if key is an Attribute" do + attr = REXML::Attribute.new("male", "true") + @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 diff --git a/spec/ruby/library/rexml/element/add_attributes_spec.rb b/spec/ruby/library/rexml/element/add_attributes_spec.rb index b462fdf5fe..8e7e991f11 100644 --- a/spec/ruby/library/rexml/element/add_attributes_spec.rb +++ b/spec/ruby/library/rexml/element/add_attributes_spec.rb @@ -1,22 +1,25 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#add_attributes" do - before :each do - @person = REXML::Element.new "person" - @person.attributes["name"] = "Bill" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "adds multiple attributes from a hash" do - @person.add_attributes({"name" => "Joe", "age" => "27"}) - @person.attributes["name"].should == "Joe" - @person.attributes["age"].should == "27" - end + describe "REXML::Element#add_attributes" do + before :each do + @person = REXML::Element.new "person" + @person.attributes["name"] = "Bill" + 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" + it "adds multiple attributes from a hash" do + @person.add_attributes({"name" => "Joe", "age" => "27"}) + @person.attributes["name"].should == "Joe" + @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 diff --git a/spec/ruby/library/rexml/element/add_element_spec.rb b/spec/ruby/library/rexml/element/add_element_spec.rb index 8e2ffe3148..90fb36f8e3 100644 --- a/spec/ruby/library/rexml/element/add_element_spec.rb +++ b/spec/ruby/library/rexml/element/add_element_spec.rb @@ -1,39 +1,41 @@ -require 'rexml/document' require_relative '../../../spec_helper' +ruby_version_is ''...'2.8' do + require 'rexml/document' -describe "REXML::Element#add_element" do - before :each do - @root = REXML::Element.new("root") - end + describe "REXML::Element#add_element" do + before :each do + @root = REXML::Element.new("root") + end - it "adds a child without attributes" do - name = REXML::Element.new("name") - @root.add_element name - @root.elements["name"].name.should == name.name - @root.elements["name"].attributes.should == name.attributes - @root.elements["name"].context.should == name.context - end + it "adds a child without attributes" do + name = REXML::Element.new("name") + @root.add_element name + @root.elements["name"].name.should == name.name + @root.elements["name"].attributes.should == name.attributes + @root.elements["name"].context.should == name.context + end - it "adds a child with attributes" do - person = REXML::Element.new("person") - @root.add_element(person, {"name" => "Madonna"}) - @root.elements["person"].name.should == person.name - @root.elements["person"].attributes.should == person.attributes - @root.elements["person"].context.should == person.context - end + it "adds a child with attributes" do + person = REXML::Element.new("person") + @root.add_element(person, {"name" => "Madonna"}) + @root.elements["person"].name.should == person.name + @root.elements["person"].attributes.should == person.attributes + @root.elements["person"].context.should == person.context + end - it "adds a child with name" do - @root.add_element "name" - @root.elements["name"].name.should == "name" - @root.elements["name"].attributes.should == {} - @root.elements["name"].context.should == nil - end + it "adds a child with name" do + @root.add_element "name" + @root.elements["name"].name.should == "name" + @root.elements["name"].attributes.should == {} + @root.elements["name"].context.should == nil + end - it "returns the added child" do - name = @root.add_element "name" - @root.elements["name"].name.should == name.name - @root.elements["name"].attributes.should == name.attributes - @root.elements["name"].context.should == name.context + it "returns the added child" do + name = @root.add_element "name" + @root.elements["name"].name.should == name.name + @root.elements["name"].attributes.should == name.attributes + @root.elements["name"].context.should == name.context + end end end diff --git a/spec/ruby/library/rexml/element/add_namespace_spec.rb b/spec/ruby/library/rexml/element/add_namespace_spec.rb index 77c00eec46..5e601dcf28 100644 --- a/spec/ruby/library/rexml/element/add_namespace_spec.rb +++ b/spec/ruby/library/rexml/element/add_namespace_spec.rb @@ -1,23 +1,26 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#add_namespace" do - before :each do - @elem = REXML::Element.new("person") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "adds a namespace to element" do - @elem.add_namespace("foo", "bar") - @elem.namespace("foo").should == "bar" - end + describe "REXML::Element#add_namespace" do + before :each do + @elem = REXML::Element.new("person") + end - it "accepts a prefix string as prefix" do - @elem.add_namespace("xmlns:foo", "bar") - @elem.namespace("foo").should == "bar" - end + it "adds a namespace to element" do + @elem.add_namespace("foo", "bar") + @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" + it "accepts a prefix string as prefix" do + @elem.add_namespace("xmlns:foo", "bar") + @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 diff --git a/spec/ruby/library/rexml/element/add_text_spec.rb b/spec/ruby/library/rexml/element/add_text_spec.rb index 54e127bf4b..200d748e61 100644 --- a/spec/ruby/library/rexml/element/add_text_spec.rb +++ b/spec/ruby/library/rexml/element/add_text_spec.rb @@ -1,24 +1,27 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#add_text" do - before :each do - @name = REXML::Element.new "Name" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "adds text to an element" do - @name.add_text "Ringo" - @name.to_s.should == "Ringo" - end + describe "REXML::Element#add_text" do + before :each do + @name = REXML::Element.new "Name" + end - it "accepts a Text" do - @name.add_text(REXML::Text.new("Ringo")) - @name.to_s.should == "Ringo" - end + it "adds text to an element" do + @name.add_text "Ringo" + @name.to_s.should == "Ringo" + end - it "joins the new text with the old one" do - @name.add_text "Ringo" - @name.add_text " Starr" - @name.to_s.should == "Ringo Starr" + it "accepts a Text" do + @name.add_text(REXML::Text.new("Ringo")) + @name.to_s.should == "Ringo" + end + + it "joins the new text with the old one" do + @name.add_text "Ringo" + @name.add_text " Starr" + @name.to_s.should == "Ringo Starr" + end end end diff --git a/spec/ruby/library/rexml/element/attribute_spec.rb b/spec/ruby/library/rexml/element/attribute_spec.rb index e40d612ef3..7b2c26658a 100644 --- a/spec/ruby/library/rexml/element/attribute_spec.rb +++ b/spec/ruby/library/rexml/element/attribute_spec.rb @@ -1,17 +1,20 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#attribute" do - it "returns an attribute by name" do - person = REXML::Element.new "Person" - attribute = REXML::Attribute.new("drink", "coffee") - person.add_attribute(attribute) - person.attribute("drink").should == attribute - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - 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" + describe "REXML::Element#attribute" do + it "returns an attribute by name" do + 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 + 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 diff --git a/spec/ruby/library/rexml/element/attributes_spec.rb b/spec/ruby/library/rexml/element/attributes_spec.rb index 8959b769a8..79a3368a9e 100644 --- a/spec/ruby/library/rexml/element/attributes_spec.rb +++ b/spec/ruby/library/rexml/element/attributes_spec.rb @@ -1,19 +1,22 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#attributes" do - it "returns element's Attributes" do - p = REXML::Element.new "Person" +ruby_version_is ''...'2.8' do + require 'rexml/document' - name = REXML::Attribute.new("name", "John") - attrs = REXML::Attributes.new(p) - attrs.add name + describe "REXML::Element#attributes" do + it "returns element's Attributes" do + p = REXML::Element.new "Person" - p.add_attribute name - p.attributes.should == attrs - end + name = REXML::Attribute.new("name", "John") + attrs = REXML::Attributes.new(p) + attrs.add name - it "returns an empty hash if element has no attributes" do - REXML::Element.new("Person").attributes.should == {} + p.add_attribute name + 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 diff --git a/spec/ruby/library/rexml/element/cdatas_spec.rb b/spec/ruby/library/rexml/element/cdatas_spec.rb index a371a5734b..4cc592aae3 100644 --- a/spec/ruby/library/rexml/element/cdatas_spec.rb +++ b/spec/ruby/library/rexml/element/cdatas_spec.rb @@ -1,24 +1,27 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#cdatas" do - before :each do - @e = REXML::Element.new("Root") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the array of children cdatas" do - c = REXML::CData.new("Primary") - d = REXML::CData.new("Secondary") - @e << c - @e << d - @e.cdatas.should == [c, d] - end + describe "REXML::Element#cdatas" do + before :each do + @e = REXML::Element.new("Root") + end - it "freezes the returned array" do - @e.cdatas.frozen?.should == true - end + it "returns the array of children cdatas" do + c = REXML::CData.new("Primary") + 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 - @e.cdatas.should == [] + it "freezes the returned array" do + @e.cdatas.frozen?.should == true + end + + it "returns an empty array if element has no cdata" do + @e.cdatas.should == [] + end end end diff --git a/spec/ruby/library/rexml/element/clone_spec.rb b/spec/ruby/library/rexml/element/clone_spec.rb index d26392db41..06948585a4 100644 --- a/spec/ruby/library/rexml/element/clone_spec.rb +++ b/spec/ruby/library/rexml/element/clone_spec.rb @@ -1,29 +1,32 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#clone" do - before :each do - @e = REXML::Element.new "a" - end - it "creates a copy of element" do - @e.clone.to_s.should == @e.to_s - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "copies the attributes" do - @e.add_attribute("foo", "bar") - @e.clone.to_s.should == @e.to_s - end + describe "REXML::Element#clone" do + before :each do + @e = REXML::Element.new "a" + end + it "creates a copy of element" do + @e.clone.to_s.should == @e.to_s + end - it "does not copy the text" do - @e.add_text "some text..." - @e.clone.to_s.should_not == @e - @e.clone.to_s.should == "" - end + it "copies the attributes" do + @e.add_attribute("foo", "bar") + @e.clone.to_s.should == @e.to_s + 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 == "" + it "does not copy the text" do + @e.add_text "some text..." + @e.clone.to_s.should_not == @e + @e.clone.to_s.should == "" + 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 == "" + end end end diff --git a/spec/ruby/library/rexml/element/comments_spec.rb b/spec/ruby/library/rexml/element/comments_spec.rb index 9dac2cc5b8..59a0b3e4fb 100644 --- a/spec/ruby/library/rexml/element/comments_spec.rb +++ b/spec/ruby/library/rexml/element/comments_spec.rb @@ -1,20 +1,23 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#comments" do - before :each do - @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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the array of comments" do - @e.comments.should == [@c1, @c2] - end + describe "REXML::Element#comments" do + before :each do + @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 - @e.comments.frozen?.should == true + it "returns the array of comments" do + @e.comments.should == [@c1, @c2] + end + + it "returns a frozen object" do + @e.comments.frozen?.should == true + end end end diff --git a/spec/ruby/library/rexml/element/delete_attribute_spec.rb b/spec/ruby/library/rexml/element/delete_attribute_spec.rb index 5c55c5efda..9d8669e405 100644 --- a/spec/ruby/library/rexml/element/delete_attribute_spec.rb +++ b/spec/ruby/library/rexml/element/delete_attribute_spec.rb @@ -1,39 +1,43 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#delete_attribute" do - before :each do - @e = REXML::Element.new("Person") - @attr = REXML::Attribute.new("name", "Sean") - @e.add_attribute(@attr) - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "deletes an attribute from the element" do - @e.delete_attribute("name") - @e.attributes["name"].should be_nil - end - -# Bug was filled with a patch in Ruby's tracker #20298 - quarantine! do - it "receives an Attribute" do + describe "REXML::Element#delete_attribute" do + before :each do + @e = REXML::Element.new("Person") + @attr = REXML::Attribute.new("name", "Sean") @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 end - end - # Docs say that it returns the removed attribute but then examples - # show it returns the element with the attribute removed. - # Also fixed in #20298 - it "returns the element with the attribute removed" do - elem = @e.delete_attribute("name") - elem.attributes.should be_empty - elem.to_s.should eql("") - end + # Bug was filled with a patch in Ruby's tracker #20298 + quarantine! do + it "receives an Attribute" do + @e.add_attribute(@attr) + @e.delete_attribute(@attr) + @e.attributes["name"].should be_nil + end + end - it "returns nil if the attribute does not exist" do - @e.delete_attribute("name") - at = @e.delete_attribute("name") - at.should be_nil + # Docs say that it returns the removed attribute but then examples + # show it returns the element with the attribute removed. + # Also fixed in #20298 + it "returns the element with the attribute removed" do + elem = @e.delete_attribute("name") + elem.attributes.should be_empty + elem.to_s.should eql("") + 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 + diff --git a/spec/ruby/library/rexml/element/delete_element_spec.rb b/spec/ruby/library/rexml/element/delete_element_spec.rb index 9417229bd4..f2c50eb95e 100644 --- a/spec/ruby/library/rexml/element/delete_element_spec.rb +++ b/spec/ruby/library/rexml/element/delete_element_spec.rb @@ -1,49 +1,52 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#delete_element" do - before :each do - @root = REXML::Element.new("root") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "deletes the child element" do - node = REXML::Element.new("some_node") - @root.add_element node - @root.delete_element node - @root.elements.size.should == 0 - end + describe "REXML::Element#delete_element" do + before :each do + @root = REXML::Element.new("root") + end - it "deletes a child via XPath" do - @root.add_element "some_node" - @root.delete_element "some_node" - @root.elements.size.should == 0 - end + it "deletes the child element" do + node = REXML::Element.new("some_node") + @root.add_element node + @root.delete_element node + @root.elements.size.should == 0 + end - it "deletes the child at index" do - @root.add_element "some_node" - @root.delete_element 1 - @root.elements.size.should == 0 - end + it "deletes a child via XPath" do + @root.add_element "some_node" + @root.delete_element "some_node" + @root.elements.size.should == 0 + end - # According to the docs this should return the deleted element - # but it won't if it's an Element. - it "deletes Element and returns it" do - node = REXML::Element.new("some_node") - @root.add_element node - del_node = @root.delete_element node - del_node.should == node - end + it "deletes the child at index" do + @root.add_element "some_node" + @root.delete_element 1 + @root.elements.size.should == 0 + end - # Note how passing the string will return the removed element - # 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 + # According to the docs this should return the deleted element + # but it won't if it's an Element. + it "deletes Element and returns it" do + node = REXML::Element.new("some_node") + @root.add_element node + del_node = @root.delete_element node + del_node.should == node + end - it "returns nil unless element exists" do - @root.delete_element("something").should == nil + # Note how passing the string will return the removed element + # 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 diff --git a/spec/ruby/library/rexml/element/delete_namespace_spec.rb b/spec/ruby/library/rexml/element/delete_namespace_spec.rb index 8683a40cab..4b37c2c41c 100644 --- a/spec/ruby/library/rexml/element/delete_namespace_spec.rb +++ b/spec/ruby/library/rexml/element/delete_namespace_spec.rb @@ -1,25 +1,28 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#delete_namespace" do +ruby_version_is ''...'2.8' do + require 'rexml/document' - before :each do - @doc = REXML::Document.new "" - end + describe "REXML::Element#delete_namespace" do - it "deletes a namespace from the element" do - @doc.root.delete_namespace 'foo' - @doc.root.namespace("foo").should be_nil - @doc.root.to_s.should == "" - end + before :each do + @doc = REXML::Document.new "" + end - it "deletes default namespace when called with no args" do - @doc.root.delete_namespace - @doc.root.namespace.should be_empty - @doc.root.to_s.should == "" - end + it "deletes a namespace from the element" do + @doc.root.delete_namespace 'foo' + @doc.root.namespace("foo").should be_nil + @doc.root.to_s.should == "" + end - it "returns the element" do - @doc.root.delete_namespace.should == @doc.root + it "deletes default namespace when called with no args" do + @doc.root.delete_namespace + @doc.root.namespace.should be_empty + @doc.root.to_s.should == "" + end + + it "returns the element" do + @doc.root.delete_namespace.should == @doc.root + end end end diff --git a/spec/ruby/library/rexml/element/document_spec.rb b/spec/ruby/library/rexml/element/document_spec.rb index 24773580f2..c9f74c4056 100644 --- a/spec/ruby/library/rexml/element/document_spec.rb +++ b/spec/ruby/library/rexml/element/document_spec.rb @@ -1,16 +1,19 @@ -require 'rexml/document' 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 - d = REXML::Document.new("") - d << REXML::XMLDecl.new - d.root.document.should == d - d.root.document.to_s.should == d.to_s - end + describe "REXML::Element#document" do - it "returns nil if it belongs to no document" do - REXML::Element.new("standalone").document.should be_nil + it "returns the element's document" do + d = REXML::Document.new("") + 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 diff --git a/spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb b/spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb index 3c5da3f015..5d6f4b371a 100644 --- a/spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb +++ b/spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb @@ -1,35 +1,38 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#each_element_with_attributes" do - before :each do - @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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns childs with attribute" do - @document.each_element_with_attribute("name") { |elem| @childs << elem } - @childs[0].should == @father - @childs[1].should == @son - end + describe "REXML::Element#each_element_with_attributes" do + before :each do + @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 "takes attribute value as second argument" do - @document.each_element_with_attribute("name", "Fred"){ |elem| elem.should == @son } - end + it "returns childs with attribute" do + @document.each_element_with_attribute("name") { |elem| @childs << elem } + @childs[0].should == @father + @childs[1].should == @son + end - it "takes max number of childs as third argument" do - @document.each_element_with_attribute("name", nil, 1) { |elem| @childs << elem } - @childs.size.should == 1 - @childs[0].should == @father - end + it "takes attribute value as second argument" do + @document.each_element_with_attribute("name", "Fred"){ |elem| elem.should == @son } + end - it "takes XPath filter as fourth argument" do - @document.each_element_with_attribute("name", nil, 0, "Child"){ |elem| elem.should == @son} + it "takes max number of childs as third argument" do + @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 diff --git a/spec/ruby/library/rexml/element/each_element_with_text_spec.rb b/spec/ruby/library/rexml/element/each_element_with_text_spec.rb index 5f9e5b85dc..65f5ea5f11 100644 --- a/spec/ruby/library/rexml/element/each_element_with_text_spec.rb +++ b/spec/ruby/library/rexml/element/each_element_with_text_spec.rb @@ -1,31 +1,34 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#each_element_with_text" do - before :each do - @document = REXML::Element.new("people") +ruby_version_is ''...'2.8' do + require 'rexml/document' - @joe = REXML::Element.new("Person") - @joe.text = "Joe" - @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 + describe "REXML::Element#each_element_with_text" do + before :each do + @document = REXML::Element.new("people") - it "returns childs with text" do - @document.each_element_with_text("Joe"){|c| c.should == @joe} - end + @joe = REXML::Element.new("Person") + @joe.text = "Joe" + @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 - @document.each_element_with_text("Fred", 1){ |c| c.should == @fred} - end + it "returns childs with text" do + @document.each_element_with_text("Joe"){|c| c.should == @joe} + end - it "takes XPath filter as third argument" do - @document.each_element_with_text("Fred", 0, "Person"){ |c| c.should == @fred} + it "takes max as second argument" do + @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 diff --git a/spec/ruby/library/rexml/element/element_reference_spec.rb b/spec/ruby/library/rexml/element/element_reference_spec.rb index 9660ff7507..0deaf990eb 100644 --- a/spec/ruby/library/rexml/element/element_reference_spec.rb +++ b/spec/ruby/library/rexml/element/element_reference_spec.rb @@ -1,20 +1,23 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#[]" do +ruby_version_is ''...'2.8' do + require 'rexml/document' - before :each do - @doc = REXML::Document.new("") - @child = REXML::Element.new("child") - @doc.root.add_element @child - end + describe "REXML::Element#[]" do - it "return attribute value if argument is string or symbol" do - @doc.root[:foo].should == 'bar' - @doc.root['foo'].should == 'bar' - end + before :each do + @doc = REXML::Document.new("") + @child = REXML::Element.new("child") + @doc.root.add_element @child + end - it "return nth element if argument is int" do - @doc.root[0].should == @child + it "return attribute value if argument is string or symbol" do + @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 diff --git a/spec/ruby/library/rexml/element/get_text_spec.rb b/spec/ruby/library/rexml/element/get_text_spec.rb index 8ee9ea0824..cfdc758acd 100644 --- a/spec/ruby/library/rexml/element/get_text_spec.rb +++ b/spec/ruby/library/rexml/element/get_text_spec.rb @@ -1,18 +1,21 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#get_text" do - before :each do - @doc = REXML::Document.new "

some textthis is bold! more text

" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the first text child node" do - @doc.root.get_text.value.should == "some text" - @doc.root.get_text.should be_kind_of(REXML::Text) - end + describe "REXML::Element#get_text" do + before :each do + @doc = REXML::Document.new "

some textthis is bold! more 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) + it "returns the first text child node" do + @doc.root.get_text.value.should == "some 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 diff --git a/spec/ruby/library/rexml/element/has_attributes_spec.rb b/spec/ruby/library/rexml/element/has_attributes_spec.rb index f89ec675f5..83d71396c4 100644 --- a/spec/ruby/library/rexml/element/has_attributes_spec.rb +++ b/spec/ruby/library/rexml/element/has_attributes_spec.rb @@ -1,17 +1,20 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#has_attributes?" do - before :each do - @e = REXML::Element.new("test_elem") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns true when element has any attributes" do - @e.add_attribute("name", "Joe") - @e.has_attributes?.should be_true - end + describe "REXML::Element#has_attributes?" do + before :each do + @e = REXML::Element.new("test_elem") + end - it "returns false if element has no attributes" do - @e.has_attributes?.should be_false + it "returns true when element has any attributes" do + @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 diff --git a/spec/ruby/library/rexml/element/has_elements_spec.rb b/spec/ruby/library/rexml/element/has_elements_spec.rb index dc5fc9c25b..815a987ca0 100644 --- a/spec/ruby/library/rexml/element/has_elements_spec.rb +++ b/spec/ruby/library/rexml/element/has_elements_spec.rb @@ -1,18 +1,21 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#has_elements?" do - before :each do - @e = REXML::Element.new("root") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns true if element has child elements" do - child = REXML::Element.new("child") - @e << child - @e.has_elements?.should be_true - end + describe "REXML::Element#has_elements?" do + before :each do + @e = REXML::Element.new("root") + end - it "returns false if element doesn't have child elements" do - @e.has_elements?.should be_false + it "returns true if element has child elements" do + 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 diff --git a/spec/ruby/library/rexml/element/has_text_spec.rb b/spec/ruby/library/rexml/element/has_text_spec.rb index e9d5a176cb..f2c5bc4ffa 100644 --- a/spec/ruby/library/rexml/element/has_text_spec.rb +++ b/spec/ruby/library/rexml/element/has_text_spec.rb @@ -1,16 +1,19 @@ -require 'rexml/document' 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 - e = REXML::Element.new("Person") - e.text = "My text" - e.has_text?.should be_true - end + describe "REXML::Element#has_text?" do - it "returns false if it has no Text childs" do - e = REXML::Element.new("Person") - e.has_text?.should be_false + it "returns true if element has a Text child" 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 + e = REXML::Element.new("Person") + e.has_text?.should be_false + end end end diff --git a/spec/ruby/library/rexml/element/inspect_spec.rb b/spec/ruby/library/rexml/element/inspect_spec.rb index f45edd0b1f..5eb8ef2265 100644 --- a/spec/ruby/library/rexml/element/inspect_spec.rb +++ b/spec/ruby/library/rexml/element/inspect_spec.rb @@ -1,27 +1,30 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#inspect" do +ruby_version_is ''...'2.8' do + require 'rexml/document' - before :each do - @name = REXML::Element.new "name" - end + describe "REXML::Element#inspect" do - it "returns the node as a string" do - @name.inspect.should == "" - end + before :each do + @name = REXML::Element.new "name" + end - it "inserts '...' if the node has children" do - e = REXML::Element.new "last_name" - @name << e - @name.inspect.should == " ... " - # This might make more sense but differs from MRI's default behavior - # @name.inspect.should == " ... " - end + it "returns the node as a string" do + @name.inspect.should == "" + end - it "inserts the attributes in the string" do - @name.add_attribute "language" - @name.attributes["language"] = "english" - @name.inspect.should == "" + it "inserts '...' if the node has children" do + e = REXML::Element.new "last_name" + @name << e + @name.inspect.should == " ... " + # This might make more sense but differs from MRI's default behavior + # @name.inspect.should == " ... " + end + + it "inserts the attributes in the string" do + @name.add_attribute "language" + @name.attributes["language"] = "english" + @name.inspect.should == "" + end end end diff --git a/spec/ruby/library/rexml/element/instructions_spec.rb b/spec/ruby/library/rexml/element/instructions_spec.rb index aa2d192e7c..bd9dfcef50 100644 --- a/spec/ruby/library/rexml/element/instructions_spec.rb +++ b/spec/ruby/library/rexml/element/instructions_spec.rb @@ -1,21 +1,24 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#instructions" do - before :each do - @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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns an empty array if it has no Instruction children" do - @elem.instructions.should be_empty - end + describe "REXML::Element#instructions" do + before :each do + @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 - @elem.instructions.frozen?.should be_true + it "returns an empty array if it has no Instruction children" do + @elem.instructions.should be_empty + end + + it "freezes the returned array" do + @elem.instructions.frozen?.should be_true + end end end diff --git a/spec/ruby/library/rexml/element/namespace_spec.rb b/spec/ruby/library/rexml/element/namespace_spec.rb index 89662f3599..a359887826 100644 --- a/spec/ruby/library/rexml/element/namespace_spec.rb +++ b/spec/ruby/library/rexml/element/namespace_spec.rb @@ -1,27 +1,30 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#namespace" do - before :each do - @doc = REXML::Document.new("
") - @elem = @doc.elements["//b"] - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the default namespace" do - @elem.namespace.should == "1" - end + describe "REXML::Element#namespace" do + before :each do + @doc = REXML::Document.new("") + @elem = @doc.elements["//b"] + end - it "accepts a namespace prefix" do - @elem.namespace("y").should == "2" - @doc.elements["//c"].namespace("z").should == "3" - end + it "returns the default namespace" do + @elem.namespace.should == "1" + end - it "returns an empty String if default namespace is not defined" do - e = REXML::Document.new("") - e.root.namespace.should be_empty - end + it "accepts a namespace prefix" do + @elem.namespace("y").should == "2" + @doc.elements["//c"].namespace("z").should == "3" + end - it "returns nil if namespace is not defined" do - @elem.namespace("z").should be_nil + it "returns an empty String if default namespace is not defined" do + e = REXML::Document.new("") + 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 diff --git a/spec/ruby/library/rexml/element/namespaces_spec.rb b/spec/ruby/library/rexml/element/namespaces_spec.rb index a84c1d1dab..7bf8ec6421 100644 --- a/spec/ruby/library/rexml/element/namespaces_spec.rb +++ b/spec/ruby/library/rexml/element/namespaces_spec.rb @@ -1,32 +1,35 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#namespaces" do - before :each do - doc = REXML::Document.new("") - @elem = doc.elements["//c"] - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns a hash of the namespaces" do - ns = {"y"=>"2", "z"=>"3", "xmlns"=>"1"} - @elem.namespaces.keys.sort.should == ns.keys.sort - @elem.namespaces.values.sort.should == ns.values.sort - end + describe "REXML::Element#namespaces" do + before :each do + doc = REXML::Document.new("") + @elem = doc.elements["//c"] + end - it "returns an empty hash if no namespaces exist" do - e = REXML::Element.new "element" - e.namespaces.kind_of?(Hash).should == true - e.namespaces.should be_empty - end + it "returns a hash of the namespaces" do + ns = {"y"=>"2", "z"=>"3", "xmlns"=>"1"} + @elem.namespaces.keys.sort.should == ns.keys.sort + @elem.namespaces.values.sort.should == ns.values.sort + end - it "uses namespace prefixes as keys" do - prefixes = ["y", "z", "xmlns"] - @elem.namespaces.keys.sort.should == prefixes.sort - end + it "returns an empty hash if no namespaces exist" do + e = REXML::Element.new "element" + e.namespaces.kind_of?(Hash).should == true + e.namespaces.should be_empty + end - it "uses namespace values as the hash values" do - values = ["2", "3", "1"] - @elem.namespaces.values.sort.should == values.sort - end + it "uses namespace prefixes as keys" do + prefixes = ["y", "z", "xmlns"] + @elem.namespaces.keys.sort.should == prefixes.sort + end + it "uses namespace values as the hash values" do + values = ["2", "3", "1"] + @elem.namespaces.values.sort.should == values.sort + end + + end end diff --git a/spec/ruby/library/rexml/element/new_spec.rb b/spec/ruby/library/rexml/element/new_spec.rb index 4ffdf4dabe..35a8438495 100644 --- a/spec/ruby/library/rexml/element/new_spec.rb +++ b/spec/ruby/library/rexml/element/new_spec.rb @@ -1,35 +1,38 @@ -require 'rexml/document' 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 - REXML::Element.new("foo").name.should == "foo" - end + describe "REXML::Element#new" do - it "creates element with default attributes" do - e = REXML::Element.new - e.name.should == REXML::Element::UNDEFINED - e.context.should == nil - e.parent.should == nil - end + it "creates element from tag name" do + REXML::Element.new("foo").name.should == "foo" + end - it "creates element from another element" do - e = REXML::Element.new "foo" - f = REXML::Element.new e - e.name.should == f.name - e.context.should == f.context - e.parent.should == f.parent - end + it "creates element with default attributes" do + e = REXML::Element.new + e.name.should == REXML::Element::UNDEFINED + e.context.should == nil + e.parent.should == nil + end - it "takes parent as second argument" do - parent = REXML::Element.new "foo" - child = REXML::Element.new "bar", parent - child.parent.should == parent - end + it "creates element from another element" do + e = REXML::Element.new "foo" + f = REXML::Element.new e + e.name.should == f.name + e.context.should == f.context + e.parent.should == f.parent + end - it "takes context as third argument" do - context = {"some_key" => "some_value"} - REXML::Element.new("foo", nil, context).context.should == context + it "takes parent as second argument" do + parent = REXML::Element.new "foo" + 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 diff --git a/spec/ruby/library/rexml/element/next_element_spec.rb b/spec/ruby/library/rexml/element/next_element_spec.rb index 5b6d6cad9b..2c7875a248 100644 --- a/spec/ruby/library/rexml/element/next_element_spec.rb +++ b/spec/ruby/library/rexml/element/next_element_spec.rb @@ -1,19 +1,22 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#next_element" do - 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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns nil on last element" do - @a.elements["c"].next_element.should == nil + describe "REXML::Element#next_element" do + 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 diff --git a/spec/ruby/library/rexml/element/node_type_spec.rb b/spec/ruby/library/rexml/element/node_type_spec.rb index bcab9e126d..d641dd89d3 100644 --- a/spec/ruby/library/rexml/element/node_type_spec.rb +++ b/spec/ruby/library/rexml/element/node_type_spec.rb @@ -1,8 +1,11 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#node_type" do - it "returns :element" do - REXML::Element.new("MyElem").node_type.should == :element +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Element#node_type" do + it "returns :element" do + REXML::Element.new("MyElem").node_type.should == :element + end end end diff --git a/spec/ruby/library/rexml/element/prefixes_spec.rb b/spec/ruby/library/rexml/element/prefixes_spec.rb index b6edf9a847..77557e165a 100644 --- a/spec/ruby/library/rexml/element/prefixes_spec.rb +++ b/spec/ruby/library/rexml/element/prefixes_spec.rb @@ -1,23 +1,26 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#prefixes" do - before :each do - doc = REXML::Document.new("") - @elem = doc.elements["//c"] - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns an array of the prefixes of the namespaces" do - @elem.prefixes.should == ["y", "z"] - end + describe "REXML::Element#prefixes" do + before :each do + doc = REXML::Document.new("") + @elem = doc.elements["//c"] + end - it "does not include the default namespace" do - @elem.prefixes.include?("xmlns").should == false - end + it "returns an array of the prefixes of the namespaces" do + @elem.prefixes.should == ["y", "z"] + end - it "returns an empty array if no namespace was defined" do - doc = REXML::Document.new "" - root = doc.elements["//root"] - root.prefixes.should == [] + it "does not include the default namespace" do + @elem.prefixes.include?("xmlns").should == false + end + + it "returns an empty array if no namespace was defined" do + doc = REXML::Document.new "" + root = doc.elements["//root"] + root.prefixes.should == [] + end end end diff --git a/spec/ruby/library/rexml/element/previous_element_spec.rb b/spec/ruby/library/rexml/element/previous_element_spec.rb index 2fe79d955f..aa19c187be 100644 --- a/spec/ruby/library/rexml/element/previous_element_spec.rb +++ b/spec/ruby/library/rexml/element/previous_element_spec.rb @@ -1,20 +1,23 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#previous_element" do - 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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns previous element" do - @a.elements["c"].previous_element.should == @b - end + describe "REXML::Element#previous_element" do + 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 nil on first element" do - @a.elements["b"].previous_element.should == nil + it "returns previous element" do + @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 diff --git a/spec/ruby/library/rexml/element/raw_spec.rb b/spec/ruby/library/rexml/element/raw_spec.rb index 404ccce5f4..2a913e1ac7 100644 --- a/spec/ruby/library/rexml/element/raw_spec.rb +++ b/spec/ruby/library/rexml/element/raw_spec.rb @@ -1,24 +1,27 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#raw" do - it "returns true if raw mode is set to all" do - REXML::Element.new("MyElem", nil, {raw: :all}).raw.should == true - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns true if raw mode is set to expanded_name" do - REXML::Element.new("MyElem", nil, {raw: "MyElem"}).raw.should == true - end + describe "REXML::Element#raw" do + it "returns true if raw mode is set to all" do + REXML::Element.new("MyElem", nil, {raw: :all}).raw.should == true + end - it "returns false if raw mode is not set" do - REXML::Element.new("MyElem", nil, {raw: ""}).raw.should == false - end + it "returns true if raw mode is set to expanded_name" do + REXML::Element.new("MyElem", nil, {raw: "MyElem"}).raw.should == true + end - it "returns false if raw is not :all or expanded_name" do - REXML::Element.new("MyElem", nil, {raw: "Something"}).raw.should == false - end + it "returns false if raw mode is not set" do + REXML::Element.new("MyElem", nil, {raw: ""}).raw.should == false + end - it "returns nil if context is not set" do - REXML::Element.new("MyElem").raw.should == nil + it "returns false if raw is not :all or expanded_name" do + 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 diff --git a/spec/ruby/library/rexml/element/root_spec.rb b/spec/ruby/library/rexml/element/root_spec.rb index 1e0669033e..4e88446ac2 100644 --- a/spec/ruby/library/rexml/element/root_spec.rb +++ b/spec/ruby/library/rexml/element/root_spec.rb @@ -1,28 +1,31 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Element#root" do - before :each do - @doc = REXML::Document.new - @root = REXML::Element.new "root" - @node = REXML::Element.new "node" - @doc << @root << @node - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns first child on documents" do - @doc.root.should == @root - end + describe "REXML::Element#root" do + before :each do + @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 - @root.root.should == @root - end + it "returns first child on documents" do + @doc.root.should == @root + end - it "returns parent's root on child nodes" do - @node.root.should == @root - end + it "returns self on root nodes" do + @root.root.should == @root + 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 + it "returns parent's root on child nodes" do + @node.root.should == @root + 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 diff --git a/spec/ruby/library/rexml/element/text_spec.rb b/spec/ruby/library/rexml/element/text_spec.rb index 7c290c4cda..b7d493589e 100644 --- a/spec/ruby/library/rexml/element/text_spec.rb +++ b/spec/ruby/library/rexml/element/text_spec.rb @@ -1,46 +1,49 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#text" do - before :each do - @e = REXML::Element.new "name" - @e.text = "John" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + 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 - it "returns the text node of element" do - @e.text.should == "John" - end + describe "REXML::Element#text=" do + before :each do + @e = REXML::Element.new "name" + @e.text = "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 "sets the text node" do + @e.to_s.should == "John" + end - it "returns nil if no text is attached" do - elem = REXML::Element.new "name" - elem.text.should == nil - end -end - -describe "REXML::Element#text=" do - before :each do - @e = REXML::Element.new "name" - @e.text = "John" - end - - it "sets the text node" do - @e.to_s.should == "John" - end - - it "replaces existing text" do - @e.text = "Joe" - @e.to_s.should == "Joe" - end - - it "receives nil as an argument" do - @e.text = nil - @e.to_s.should == "" + it "replaces existing text" do + @e.text = "Joe" + @e.to_s.should == "Joe" + end + + it "receives nil as an argument" do + @e.text = nil + @e.to_s.should == "" + end end end diff --git a/spec/ruby/library/rexml/element/texts_spec.rb b/spec/ruby/library/rexml/element/texts_spec.rb index 7975833c89..7f610ba31b 100644 --- a/spec/ruby/library/rexml/element/texts_spec.rb +++ b/spec/ruby/library/rexml/element/texts_spec.rb @@ -1,16 +1,19 @@ -require 'rexml/document' 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 - e = REXML::Element.new("root") - e.add_text "First" - e.add_text "Second" - e.texts.should == ["FirstSecond"] - end + describe "REXML::Element#texts" do - it "returns an empty array if it has no Text children" do - REXML::Element.new("root").texts.should == [] + it "returns an array of the Text children" 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 + REXML::Element.new("root").texts.should == [] + end end end diff --git a/spec/ruby/library/rexml/element/whitespace_spec.rb b/spec/ruby/library/rexml/element/whitespace_spec.rb index dc785ae5ce..8cd2e5b5e8 100644 --- a/spec/ruby/library/rexml/element/whitespace_spec.rb +++ b/spec/ruby/library/rexml/element/whitespace_spec.rb @@ -1,23 +1,26 @@ -require 'rexml/document' require_relative '../../../spec_helper' -describe "REXML::Element#whitespace" do - it "returns true if whitespace is respected in the element" do - e = REXML::Element.new("root") - e.whitespace.should be_true +ruby_version_is ''...'2.8' do + require 'rexml/document' - e = REXML::Element.new("root", nil, respect_whitespace: :all) - e.whitespace.should be_true + describe "REXML::Element#whitespace" do + 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.whitespace.should be_true - end + e = REXML::Element.new("root", nil, respect_whitespace: :all) + e.whitespace.should be_true - it "returns false if whitespace is ignored inside element" do - e = REXML::Element.new("root", nil, compress_whitespace: :all) - e.whitespace.should be_false + e = REXML::Element.new("root", nil, respect_whitespace: ["root"]) + e.whitespace.should be_true + end - e = REXML::Element.new("root", nil, compress_whitespace: ["root"]) - e.whitespace.should be_false + it "returns false if whitespace is ignored inside element" do + 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 diff --git a/spec/ruby/library/rexml/node/each_recursive_spec.rb b/spec/ruby/library/rexml/node/each_recursive_spec.rb index dd4aa9a2f2..4a669a399d 100644 --- a/spec/ruby/library/rexml/node/each_recursive_spec.rb +++ b/spec/ruby/library/rexml/node/each_recursive_spec.rb @@ -1,21 +1,24 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Node#each_recursive" do - before :each do - @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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "visits all subnodes of self" do - nodes = [] - @doc.each_recursive { |node| nodes << node} - nodes.should == [@root, @child1, @child2] + describe "REXML::Node#each_recursive" do + before :each do + @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 + nodes = [] + @doc.each_recursive { |node| nodes << node} + nodes.should == [@root, @child1, @child2] + end end end diff --git a/spec/ruby/library/rexml/node/find_first_recursive_spec.rb b/spec/ruby/library/rexml/node/find_first_recursive_spec.rb index ba46f2ca35..ab7900a3ac 100644 --- a/spec/ruby/library/rexml/node/find_first_recursive_spec.rb +++ b/spec/ruby/library/rexml/node/find_first_recursive_spec.rb @@ -1,25 +1,28 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Node#find_first_recursive" do - before :each do - @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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "finds the first element that matches block" do - found = @e.find_first_recursive { |n| n.to_s == ""} - found.should == @node1 - end + describe "REXML::Node#find_first_recursive" do + before :each do + @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 "visits the nodes in preorder" do - found = @e.find_first_recursive { |n| n.to_s == ""} - found.should == @subnode - found.should_not == @node2 + it "finds the first element that matches block" do + found = @e.find_first_recursive { |n| n.to_s == ""} + found.should == @node1 + end + + it "visits the nodes in preorder" do + found = @e.find_first_recursive { |n| n.to_s == ""} + found.should == @subnode + found.should_not == @node2 + end end end diff --git a/spec/ruby/library/rexml/node/index_in_parent_spec.rb b/spec/ruby/library/rexml/node/index_in_parent_spec.rb index 092851e3e7..1c75c8cd54 100644 --- a/spec/ruby/library/rexml/node/index_in_parent_spec.rb +++ b/spec/ruby/library/rexml/node/index_in_parent_spec.rb @@ -1,15 +1,18 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Node#index_in_parent" do - 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 +ruby_version_is ''...'2.8' do + require 'rexml/document' - node1.index_in_parent.should == 1 - node2.index_in_parent.should == 2 + describe "REXML::Node#index_in_parent" do + 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 diff --git a/spec/ruby/library/rexml/node/next_sibling_node_spec.rb b/spec/ruby/library/rexml/node/next_sibling_node_spec.rb index 2e8601627d..0aac3fee0f 100644 --- a/spec/ruby/library/rexml/node/next_sibling_node_spec.rb +++ b/spec/ruby/library/rexml/node/next_sibling_node_spec.rb @@ -1,21 +1,24 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Node#next_sibling_node" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @e << @node1 - @e << @node2 - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the next child node in parent" do - @node1.next_sibling_node.should == @node2 - end + describe "REXML::Node#next_sibling_node" do + before :each do + @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 - @node2.next_sibling_node.should == nil - @e.next_sibling_node.should == nil + it "returns the next child node in parent" do + @node1.next_sibling_node.should == @node2 + 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 diff --git a/spec/ruby/library/rexml/node/parent_spec.rb b/spec/ruby/library/rexml/node/parent_spec.rb index d88ba69657..693ee9d5c2 100644 --- a/spec/ruby/library/rexml/node/parent_spec.rb +++ b/spec/ruby/library/rexml/node/parent_spec.rb @@ -1,20 +1,23 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Node#parent?" do - it "returns true for Elements" do - e = REXML::Element.new("foo") - e.parent?.should == true - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns true for Documents" do - e = REXML::Document.new - e.parent?.should == true - end + describe "REXML::Node#parent?" do + it "returns true for Elements" do + e = REXML::Element.new("foo") + e.parent?.should == true + end - # This includes attributes, CDatas and declarations. - it "returns false for Texts" do - e = REXML::Text.new("foo") - e.parent?.should == false + it "returns true for Documents" do + e = REXML::Document.new + e.parent?.should == true + 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 diff --git a/spec/ruby/library/rexml/node/previous_sibling_node_spec.rb b/spec/ruby/library/rexml/node/previous_sibling_node_spec.rb index 8b96f1565a..ca07e1e1f9 100644 --- a/spec/ruby/library/rexml/node/previous_sibling_node_spec.rb +++ b/spec/ruby/library/rexml/node/previous_sibling_node_spec.rb @@ -1,21 +1,24 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Node#previous_sibling_node" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @e << @node1 - @e << @node2 - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns the previous child node in parent" do - @node2.previous_sibling_node.should == @node1 - end + describe "REXML::Node#previous_sibling_node" do + before :each do + @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 - @node1.previous_sibling_node.should == nil - @e.previous_sibling_node.should == nil + it "returns the previous child node in parent" do + @node2.previous_sibling_node.should == @node1 + 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 diff --git a/spec/ruby/library/rexml/text/append_spec.rb b/spec/ruby/library/rexml/text/append_spec.rb index de281fb0b0..be5636e84d 100644 --- a/spec/ruby/library/rexml/text/append_spec.rb +++ b/spec/ruby/library/rexml/text/append_spec.rb @@ -1,10 +1,13 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#<<" do - it "appends a string to this text node" do - text = REXML::Text.new("foo") - text << "bar" - text.should == "foobar" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Text#<<" do + it "appends a string to this text node" do + text = REXML::Text.new("foo") + text << "bar" + text.should == "foobar" + end end end diff --git a/spec/ruby/library/rexml/text/clone_spec.rb b/spec/ruby/library/rexml/text/clone_spec.rb index 8031e140c7..28feef40e9 100644 --- a/spec/ruby/library/rexml/text/clone_spec.rb +++ b/spec/ruby/library/rexml/text/clone_spec.rb @@ -1,10 +1,13 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#clone" do - it "creates a copy of this node" do - text = REXML::Text.new("foo") - text.clone.should == "foo" - text.clone.should == text +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Text#clone" do + it "creates a copy of this node" do + text = REXML::Text.new("foo") + text.clone.should == "foo" + text.clone.should == text + end end end diff --git a/spec/ruby/library/rexml/text/comparison_spec.rb b/spec/ruby/library/rexml/text/comparison_spec.rb index 8bc5d66a03..ebd95683c6 100644 --- a/spec/ruby/library/rexml/text/comparison_spec.rb +++ b/spec/ruby/library/rexml/text/comparison_spec.rb @@ -1,25 +1,28 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#<=>" do - before :each do - @first = REXML::Text.new("abc") - @last = REXML::Text.new("def") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns -1 if lvalue is less than rvalue" do - val = @first <=> @last - val.should == -1 - end + describe "REXML::Text#<=>" do + before :each do + @first = REXML::Text.new("abc") + @last = REXML::Text.new("def") + end - it "returns -1 if lvalue is greater than rvalue" do - val = @last <=> @first - val.should == 1 - end + it "returns -1 if lvalue is less than rvalue" do + val = @first <=> @last + val.should == -1 + end - it "returns 0 if both values are equal" do - tmp = REXML::Text.new("tmp") - val = tmp <=> tmp - val.should == 0 + it "returns -1 if lvalue is greater than rvalue" do + val = @last <=> @first + val.should == 1 + end + + it "returns 0 if both values are equal" do + tmp = REXML::Text.new("tmp") + val = tmp <=> tmp + val.should == 0 + end end end diff --git a/spec/ruby/library/rexml/text/empty_spec.rb b/spec/ruby/library/rexml/text/empty_spec.rb index d0b66b7a2a..392b536a4c 100644 --- a/spec/ruby/library/rexml/text/empty_spec.rb +++ b/spec/ruby/library/rexml/text/empty_spec.rb @@ -1,12 +1,15 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#empty?" do - it "returns true if the text is empty" do - REXML::Text.new("").empty?.should == true - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "returns false if the text is not empty" do - REXML::Text.new("some_text").empty?.should == false + describe "REXML::Text#empty?" do + 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 diff --git a/spec/ruby/library/rexml/text/indent_text_spec.rb b/spec/ruby/library/rexml/text/indent_text_spec.rb index 1b0ee5ab16..16cba7faf6 100644 --- a/spec/ruby/library/rexml/text/indent_text_spec.rb +++ b/spec/ruby/library/rexml/text/indent_text_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#indent_text" do - before :each do - @t = REXML::Text.new("") - end - it "indents a string with default parameters" do - @t.indent_text("foo").should == "\tfoo" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "accepts a custom indentation level as second argument" do - @t.indent_text("foo", 2, "\t", true).should == "\t\tfoo" - end + describe "REXML::Text#indent_text" do + before :each do + @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 - @t.indent_text("foo", 1, "\n", true).should == "\nfoo" - end + it "accepts a custom indentation level as second argument" do + @t.indent_text("foo", 2, "\t", true).should == "\t\tfoo" + end - it "accepts a fourth parameter to skip the first line" do - @t.indent_text("foo", 1, "\t", false).should == "foo" + it "accepts a custom separator as third argument" do + @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 diff --git a/spec/ruby/library/rexml/text/inspect_spec.rb b/spec/ruby/library/rexml/text/inspect_spec.rb index 0d66088a64..87203b246c 100644 --- a/spec/ruby/library/rexml/text/inspect_spec.rb +++ b/spec/ruby/library/rexml/text/inspect_spec.rb @@ -1,8 +1,11 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#inspect" do - it "inspects the string attribute as a string" do - REXML::Text.new("a text").inspect.should == "a text".inspect +ruby_version_is ''...'2.8' do + require 'rexml/document' + + 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 diff --git a/spec/ruby/library/rexml/text/new_spec.rb b/spec/ruby/library/rexml/text/new_spec.rb index 3c081dec30..7a39f11fa6 100644 --- a/spec/ruby/library/rexml/text/new_spec.rb +++ b/spec/ruby/library/rexml/text/new_spec.rb @@ -1,48 +1,51 @@ 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 - t = REXML::Text.new("test") - t.should be_kind_of(REXML::Child) - t.should == "test" - t.parent.should == nil - end + describe "REXML::Text.new" do - it "respects whitespace if second argument is true" do - t = REXML::Text.new("testing whitespace", true) - t.should == "testing whitespace" - t = REXML::Text.new(" ", true) - t.should == " " - end + it "creates a Text child node with no parent" do + t = REXML::Text.new("test") + t.should be_kind_of(REXML::Child) + t.should == "test" + t.parent.should == nil + end - it "receives a parent as third argument" do - e = REXML::Element.new("root") - t = REXML::Text.new("test", false, e) - t.parent.should == e - e.to_s.should == "test" - end + it "respects whitespace if second argument is true" do + t = REXML::Text.new("testing whitespace", true) + t.should == "testing whitespace" + t = REXML::Text.new(" ", true) + t.should == " " + end - it "expects escaped text if raw is true" do - t = REXML::Text.new("<&>", false, nil, true) - t.should == "<&>" + it "receives a parent as third argument" do + e = REXML::Element.new("root") + t = REXML::Text.new("test", false, e) + t.parent.should == e + e.to_s.should == "test" + end - ->{ REXML::Text.new("<&>", false, nil, true)}.should raise_error(Exception) - end + it "expects escaped text if raw is true" do + t = REXML::Text.new("<&>", false, nil, true) + t.should == "<&>" - it "uses raw value of the parent if raw is nil" do - e1 = REXML::Element.new("root", nil, { raw: :all}) - -> {REXML::Text.new("<&>", false, e1)}.should raise_error(Exception) + ->{ REXML::Text.new("<&>", false, nil, true)}.should raise_error(Exception) + end - e2 = REXML::Element.new("root", nil, { raw: []}) - e2.raw.should be_false - t1 = REXML::Text.new("<&>", false, e2) - t1.should == "<&>" - end + it "uses raw value of the parent if raw is nil" do + e1 = REXML::Element.new("root", nil, { raw: :all}) + -> {REXML::Text.new("<&>", false, e1)}.should raise_error(Exception) - it "escapes the values if raw is false" do - t = REXML::Text.new("<&>", false, nil, false) - t.should == "<&>" + e2 = REXML::Element.new("root", nil, { raw: []}) + e2.raw.should be_false + 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 diff --git a/spec/ruby/library/rexml/text/node_type_spec.rb b/spec/ruby/library/rexml/text/node_type_spec.rb index 1c25a74dad..17fefb87f1 100644 --- a/spec/ruby/library/rexml/text/node_type_spec.rb +++ b/spec/ruby/library/rexml/text/node_type_spec.rb @@ -1,8 +1,11 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#node_type" do - it "returns :text" do - REXML::Text.new("test").node_type.should == :text +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Text#node_type" do + it "returns :text" do + REXML::Text.new("test").node_type.should == :text + end end end diff --git a/spec/ruby/library/rexml/text/normalize_spec.rb b/spec/ruby/library/rexml/text/normalize_spec.rb index ce3b2b3b5f..10ce92615a 100644 --- a/spec/ruby/library/rexml/text/normalize_spec.rb +++ b/spec/ruby/library/rexml/text/normalize_spec.rb @@ -1,8 +1,11 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text.normalize" do - it "escapes a string with <, >, &, ' and \" " do - REXML::Text.normalize("< > & \" '").should == "< > & " '" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Text.normalize" do + it "escapes a string with <, >, &, ' and \" " do + REXML::Text.normalize("< > & \" '").should == "< > & " '" + end end end diff --git a/spec/ruby/library/rexml/text/read_with_substitution_spec.rb b/spec/ruby/library/rexml/text/read_with_substitution_spec.rb index 83b42f6d6b..4bf54c1b31 100644 --- a/spec/ruby/library/rexml/text/read_with_substitution_spec.rb +++ b/spec/ruby/library/rexml/text/read_with_substitution_spec.rb @@ -1,12 +1,15 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text.read_with_substitution" do - it "reads a text and escapes entities" do - REXML::Text.read_with_substitution("< > & " '").should == "< > & \" '" - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - 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) + describe "REXML::Text.read_with_substitution" do + 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 diff --git a/spec/ruby/library/rexml/text/to_s_spec.rb b/spec/ruby/library/rexml/text/to_s_spec.rb index 14d7399a60..f7e0e0b284 100644 --- a/spec/ruby/library/rexml/text/to_s_spec.rb +++ b/spec/ruby/library/rexml/text/to_s_spec.rb @@ -1,17 +1,20 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#to_s" do - it "returns the string of this Text node" do - u = REXML::Text.new("sean russell", false, nil, true) - u.to_s.should == "sean russell" +ruby_version_is ''...'2.8' do + require 'rexml/document' - t = REXML::Text.new("some test text") - t.to_s.should == "some test text" - end + describe "REXML::Text#to_s" do + it "returns the string of this Text node" do + u = REXML::Text.new("sean russell", false, nil, true) + u.to_s.should == "sean russell" - it "escapes the text" do - t = REXML::Text.new("& < >") - t.to_s.should == "& < >" + t = REXML::Text.new("some test text") + t.to_s.should == "some test text" + end + + it "escapes the text" do + t = REXML::Text.new("& < >") + t.to_s.should == "& < >" + end end end diff --git a/spec/ruby/library/rexml/text/unnormalize_spec.rb b/spec/ruby/library/rexml/text/unnormalize_spec.rb index 3072809c13..0f173710fa 100644 --- a/spec/ruby/library/rexml/text/unnormalize_spec.rb +++ b/spec/ruby/library/rexml/text/unnormalize_spec.rb @@ -1,8 +1,11 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text.unnormalize" do - it "unescapes a string with the values defined in SETUTITSBUS" do - REXML::Text.unnormalize("< > & " '").should == "< > & \" '" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Text.unnormalize" do + it "unescapes a string with the values defined in SETUTITSBUS" do + REXML::Text.unnormalize("< > & " '").should == "< > & \" '" + end end end diff --git a/spec/ruby/library/rexml/text/value_spec.rb b/spec/ruby/library/rexml/text/value_spec.rb index b0545b3cbd..f566412128 100644 --- a/spec/ruby/library/rexml/text/value_spec.rb +++ b/spec/ruby/library/rexml/text/value_spec.rb @@ -1,37 +1,40 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#value" do - it "returns the text value of this node" do - REXML::Text.new("test").value.should == "test" +ruby_version_is ''...'2.8' do + require 'rexml/document' + + describe "REXML::Text#value" do + it "returns the text value of this node" do + REXML::Text.new("test").value.should == "test" + end + + it "does not escape entities" do + REXML::Text.new("& \"").value.should == "& \"" + end + + it "follows the respect_whitespace attribute" do + REXML::Text.new("test bar", false).value.should == "test bar" + REXML::Text.new("test bar", true).value.should == "test bar" + end + + it "ignores the raw attribute" do + REXML::Text.new("sean russell", false, nil, true).value.should == "sean russell" + end end - it "does not escape entities" do - REXML::Text.new("& \"").value.should == "& \"" - end + describe "REXML::Text#value=" do + before :each do + @t = REXML::Text.new("new") + end - it "follows the respect_whitespace attribute" do - REXML::Text.new("test bar", false).value.should == "test bar" - REXML::Text.new("test bar", true).value.should == "test bar" - end + it "sets the text of the node" do + @t.value = "another text" + @t.to_s.should == "another text" + end - it "ignores the raw attribute" do - REXML::Text.new("sean russell", false, nil, true).value.should == "sean russell" - end -end - -describe "REXML::Text#value=" do - before :each do - @t = REXML::Text.new("new") - end - - it "sets the text of the node" do - @t.value = "another text" - @t.to_s.should == "another text" - end - - it "escapes entities" do - @t.value = "" - @t.to_s.should == "<a>" + it "escapes entities" do + @t.value = "" + @t.to_s.should == "<a>" + end end end diff --git a/spec/ruby/library/rexml/text/wrap_spec.rb b/spec/ruby/library/rexml/text/wrap_spec.rb index 0b60fd4151..415775dd47 100644 --- a/spec/ruby/library/rexml/text/wrap_spec.rb +++ b/spec/ruby/library/rexml/text/wrap_spec.rb @@ -1,20 +1,23 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#wrap" do - before :each do - @t = REXML::Text.new("abc def") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - it "wraps the text at width" do - @t.wrap("abc def", 3, false).should == "abc\ndef" - end + describe "REXML::Text#wrap" do + before :each do + @t = REXML::Text.new("abc def") + end - it "returns the string if width is greater than the size of the string" do - @t.wrap("abc def", 10, false).should == "abc def" - end + it "wraps the text at width" do + @t.wrap("abc def", 3, false).should == "abc\ndef" + end - it "takes a newline at the beginning option as the third parameter" do - @t.wrap("abc def", 3, true).should == "\nabc\ndef" + it "returns the string if width is greater than the size of the string" do + @t.wrap("abc def", 10, false).should == "abc def" + end + + it "takes a newline at the beginning option as the third parameter" do + @t.wrap("abc def", 3, true).should == "\nabc\ndef" + end end end diff --git a/spec/ruby/library/rexml/text/write_with_substitution_spec.rb b/spec/ruby/library/rexml/text/write_with_substitution_spec.rb index ee79489d86..1737b443d7 100644 --- a/spec/ruby/library/rexml/text/write_with_substitution_spec.rb +++ b/spec/ruby/library/rexml/text/write_with_substitution_spec.rb @@ -1,33 +1,36 @@ require_relative '../../../spec_helper' -require 'rexml/document' -describe "REXML::Text#write_with_substitution" do - before :each do - @t = REXML::Text.new("test") - @f = tmp("rexml_spec") - @file = File.open(@f, "w+") - end +ruby_version_is ''...'2.8' do + require 'rexml/document' - after :each do - @file.close - rm_r @f - end + describe "REXML::Text#write_with_substitution" do + before :each do + @t = REXML::Text.new("test") + @f = tmp("rexml_spec") + @file = File.open(@f, "w+") + end - it "writes out the input to a String" do - s = "" - @t.write_with_substitution(s, "some text") - s.should == "some text" - end + after :each do + @file.close + rm_r @f + end - it "writes out the input to an IO" do - @t.write_with_substitution(@file, "some text") - @file.rewind - @file.gets.should == "some text" - end + it "writes out the input to a String" do + s = "" + @t.write_with_substitution(s, "some text") + s.should == "some text" + end - it "escapes characters" do - @t.write_with_substitution(@file, "& < >") - @file.rewind - @file.gets.should == "& < >" + it "writes out the input to an IO" do + @t.write_with_substitution(@file, "some text") + @file.rewind + @file.gets.should == "some text" + end + + it "escapes characters" do + @t.write_with_substitution(@file, "& < >") + @file.rewind + @file.gets.should == "& < >" + end end end