Class: Test::Unit::Collector::XML::Listener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/test/unit/collector/xml.rb,
lib/test/unit/collector/xml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListener

Returns a new instance of Listener



28
29
30
31
32
33
34
35
# File 'lib/test/unit/collector/xml.rb', line 28

def initialize
  @ns_stack = [{"xml" => :xml}]
  @tag_stack = [["", :root]]
  @text_stack = ['']
  @state_stack = [:root]
  @values = {}
  @test_suites = []
end

Instance Attribute Details

#test_suitesObject (readonly)

Returns the value of attribute test_suites



27
28
29
# File 'lib/test/unit/collector/xml.rb', line 27

def test_suites
  @test_suites
end

Instance Method Details

#tag_end(name) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/test/unit/collector/xml.rb', line 70

def tag_end(name)
  state = @state_stack.pop
  text = @text_stack.pop
  uri, local = @tag_stack.pop
  no_action_states = [:root, :stream]
  case state
  when *no_action_states    # do nothing

  when :test_suite
    test_suite_end
  when :complete_test_case
    @test_suites.last << @test_case.suite
  when :test_case
    test_case_end
  when :result
    @result = @values
  when :test
    test_end
  when :pass_assertion
    @n_pass_assertions += 1
  when :backtrace
    @values = @values_backup
    @values["backtrace"] = @backtrace
  when :entry
    file = @values['file']
    line = @values['line']
    info = @values['info']
    @backtrace << "#{file}:#{line}: #{info}"
    @values = {}
  else
    local = normalize_local(local)
    @values[local] = text
  end
  @ns_stack.pop
end

#tag_start(name, attributes) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/test/unit/collector/xml.rb', line 37

def tag_start(name, attributes)
  @text_stack.push('')

  ns = @ns_stack.last.dup
  attrs = {}
  attributes.each do |n, v|
    if /\Axmlns(?:\z|:)/ =~ n
      ns[$POSTMATCH] = v
    else
      attrs[n] = v
    end
  end
  @ns_stack.push(ns)

  _parent_tag = parent_tag
  prefix, local = split_name(name)
  uri = _ns(ns, prefix)
  @tag_stack.push([uri, local])

  state = next_state(@state_stack.last, uri, local)
  @state_stack.push(state)
  @values = {}
  case state
  when :test_suite, :test_case    # do nothing

  when :test
    @n_pass_assertions = 0 if _parent_tag == "start-test"
  when :backtrace
    @backtrace = []
    @values_backup = @values
  end
end

#text(data) ⇒ Object



106
107
108
# File 'lib/test/unit/collector/xml.rb', line 106

def text(data)
  @text_stack.last << data
end