Sha256: 4bd2ee414c6169765e2fb85adc31658688a7133d8aa1051516651a3c985f03a4

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

require File.expand_path(::File.dirname(__FILE__) + '/../lib/xml/smart')
require File.expand_path(::File.dirname(__FILE__) + '/smartrunner.rb')

class TestCreate < Minitest::Test
  def test_create
    # When a string as second paramter is provided, then a empty
    # xml file is created if it not exists. A block has to be supplied
    #
    # XML::Smart.modify(FILE,STRING) {}             ... create file if !exists?
    # XML::Smart.modify(FILE) {}                    ... just open file change and write back (LOCKTIMEOUT defaults to 7)

    File.unlink ::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml" rescue nil
    t1 = Thread.new do
      XML::Smart.modify(::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml","<elements/>") { |doc|
        doc.root.add("element","Thread 1")
        sleep 1
      }
    end
    t2 = Thread.new do
      sleep 0.5
      XML::Smart.modify(::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml","<elements/>") { |doc|
        doc.root.add("element","Thread 2")
      }
    end
    t1.join
    t2.join

    assert(XML::Smart.open(::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml").root.to_s == XML::Smart.open(::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml.test").root.to_s)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
xml-smart-0.5.1 test/tc_create.rb
xml-smart-0.5.0 test/tc_create.rb
xml-smart-0.4.4 test/tc_create.rb
xml-smart-0.4.3 test/tc_create.rb
xml-smart-0.4.2 test/tc_create.rb
xml-smart-0.4.1 test/tc_create.rb
xml-smart-0.4.0 test/tc_create.rb
xml-smart-0.3.22 test/tc_create.rb
xml-smart-0.3.21 test/tc_create.rb
xml-smart-0.3.20 test/tc_create.rb
xml-smart-0.3.19 test/tc_create.rb