Class: Juniter::File

Inherits:
Object
  • Object
show all
Defined in:
lib/juniter/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ File

Returns a new instance of File.

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
# File 'lib/juniter/file.rb', line 25

def initialize(xml)
  @parsed_xml = xml
  root = xml.respond_to?(:root) ? xml.root : xml
  raise ArgumentError, "Invalid JUnit file. Expected <testsuites> or <testsuite> as the root node but got <#{root.value}>" unless %w{testsuites testsuite}.include?(root.value)
  @test_suites = TestSuites.from_xml(root) if root.value == "testsuites"
  @test_suites ||= TestSuites.new.tap do |test_suites|
    test_suites.test_suites = [ TestSuite.from_xml(root) ]
  end
end

Instance Attribute Details

#parsed_xmlObject (readonly)

Returns the value of attribute parsed_xml.



23
24
25
# File 'lib/juniter/file.rb', line 23

def parsed_xml
  @parsed_xml
end

#test_suitesObject (readonly)

Returns the value of attribute test_suites.



23
24
25
# File 'lib/juniter/file.rb', line 23

def test_suites
  @test_suites
end

Class Method Details

.from_file(filename) ⇒ Object



12
13
14
15
16
# File 'lib/juniter/file.rb', line 12

def from_file(filename)
  ::File.open(filename, "r") do |f|
    read f
  end
end

.parse(xml_string) ⇒ Object



18
19
20
# File 'lib/juniter/file.rb', line 18

def parse(xml_string)
  new(Ox.parse(xml_string))
end

.read(io) ⇒ Object



8
9
10
# File 'lib/juniter/file.rb', line 8

def read(io)
  parse io.read
end

Instance Method Details

#to_xmlObject



35
36
37
# File 'lib/juniter/file.rb', line 35

def to_xml
  Ox.dump(test_suites.to_xml)
end