Sha256: f1e384dd56369197016d71374c0576d7c351041af3438784403f6de1f15d439f

Contents?: true

Size: 1.39 KB

Versions: 49

Compression:

Stored size: 1.39 KB

Contents

require 'rexml/document'
require File.expand_path('../../../../spec_helper', __FILE__)

describe "REXML::Element#delete_element" do
  before :each do
    @root = REXML::Element.new("root")
  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 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 at index" do
    @root.add_element "some_node"
    @root.delete_element 1
    @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.
  ruby_bug "REXMLTracker#161", "1.8" do
    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
  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

  it "returns nil unless element exists" do
    @root.delete_element("something").should == nil
  end
end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/library/rexml/element/delete_element_spec.rb