activeldap 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/CHANGES +10 -0
  2. data/README +3 -2
  3. data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
  4. data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
  5. data/examples/al-admin/po/en/al-admin.po +1 -1
  6. data/examples/al-admin/po/ja/al-admin.po +1 -1
  7. data/examples/al-admin/po/nl/al-admin.po +1 -1
  8. data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb +7 -8
  9. data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb +2 -1
  10. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml +1 -1
  11. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml +2 -1
  12. data/lib/active_ldap.rb +9 -3
  13. data/lib/active_ldap/action_controller/ldap_benchmarking.rb +36 -0
  14. data/lib/active_ldap/adapter/jndi.rb +1 -1
  15. data/lib/active_ldap/adapter/jndi_connection.rb +2 -1
  16. data/lib/active_ldap/association/belongs_to_many.rb +10 -2
  17. data/lib/active_ldap/association/collection.rb +10 -0
  18. data/lib/active_ldap/association/has_many_utils.rb +13 -9
  19. data/lib/active_ldap/association/has_many_wrap.rb +10 -2
  20. data/lib/active_ldap/associations.rb +3 -3
  21. data/lib/active_ldap/base.rb +95 -32
  22. data/lib/active_ldap/connection.rb +1 -1
  23. data/lib/active_ldap/distinguished_name.rb +3 -0
  24. data/lib/active_ldap/entry_attribute.rb +2 -2
  25. data/lib/active_ldap/ldif.rb +2 -2
  26. data/lib/active_ldap/operations.rb +7 -3
  27. data/lib/active_ldap/user_password.rb +0 -1
  28. data/lib/active_ldap/validations.rb +2 -0
  29. data/po/en/active-ldap.po +1 -1
  30. data/po/ja/active-ldap.po +1 -1
  31. data/rails/plugin/active_ldap/init.rb +3 -34
  32. data/test-unit/History.txt +32 -0
  33. data/test-unit/Manifest.txt +70 -0
  34. data/test-unit/README.txt +32 -0
  35. data/test-unit/Rakefile +22 -0
  36. data/test-unit/bin/testrb +5 -0
  37. data/test-unit/lib/test/unit.rb +280 -0
  38. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  39. data/test-unit/lib/test/unit/assertions.rb +722 -0
  40. data/test-unit/lib/test/unit/attribute.rb +125 -0
  41. data/test-unit/lib/test/unit/autorunner.rb +250 -0
  42. data/test-unit/lib/test/unit/collector.rb +43 -0
  43. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  44. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  45. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  46. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  47. data/test-unit/lib/test/unit/color.rb +61 -0
  48. data/test-unit/lib/test/unit/diff.rb +524 -0
  49. data/test-unit/lib/test/unit/error.rb +124 -0
  50. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  51. data/test-unit/lib/test/unit/failure.rb +110 -0
  52. data/test-unit/lib/test/unit/fixture.rb +185 -0
  53. data/test-unit/lib/test/unit/notification.rb +116 -0
  54. data/test-unit/lib/test/unit/omission.rb +129 -0
  55. data/test-unit/lib/test/unit/pending.rb +130 -0
  56. data/test-unit/lib/test/unit/priority.rb +146 -0
  57. data/test-unit/lib/test/unit/runner/console.rb +46 -0
  58. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  59. data/test-unit/lib/test/unit/testcase.rb +174 -0
  60. data/test-unit/lib/test/unit/testresult.rb +89 -0
  61. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  62. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  63. data/test-unit/lib/test/unit/ui/console/testrunner.rb +195 -0
  64. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  65. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  66. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  67. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  68. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  69. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  70. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  71. data/test-unit/lib/test/unit/version.rb +7 -0
  72. data/test-unit/sample/adder.rb +13 -0
  73. data/test-unit/sample/subtracter.rb +12 -0
  74. data/test-unit/sample/tc_adder.rb +18 -0
  75. data/test-unit/sample/tc_subtracter.rb +18 -0
  76. data/test-unit/sample/ts_examples.rb +7 -0
  77. data/test-unit/test/collector/test_descendant.rb +135 -0
  78. data/test-unit/test/collector/test_dir.rb +406 -0
  79. data/test-unit/test/collector/test_load.rb +333 -0
  80. data/test-unit/test/collector/test_objectspace.rb +98 -0
  81. data/test-unit/test/run-test.rb +13 -0
  82. data/test-unit/test/test_assertions.rb +693 -0
  83. data/test-unit/test/test_attribute.rb +86 -0
  84. data/{test-unit-ext → test-unit}/test/test_color.rb +3 -5
  85. data/{test-unit-ext → test-unit}/test/test_diff.rb +18 -16
  86. data/test-unit/test/test_emacs_runner.rb +60 -0
  87. data/test-unit/test/test_error.rb +26 -0
  88. data/test-unit/test/test_failure.rb +33 -0
  89. data/test-unit/test/test_fixture.rb +275 -0
  90. data/{test-unit-ext → test-unit}/test/test_notification.rb +7 -6
  91. data/test-unit/test/test_omission.rb +81 -0
  92. data/{test-unit-ext → test-unit}/test/test_pending.rb +15 -15
  93. data/{test-unit-ext → test-unit}/test/test_priority.rb +4 -3
  94. data/test-unit/test/test_testcase.rb +411 -0
  95. data/test-unit/test/test_testresult.rb +113 -0
  96. data/test-unit/test/test_testsuite.rb +129 -0
  97. data/test-unit/test/testunit_test_util.rb +12 -0
  98. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  99. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  100. data/test-unit/test/util/test_observable.rb +102 -0
  101. data/test-unit/test/util/test_procwrapper.rb +36 -0
  102. data/test/al-test-utils.rb +4 -4
  103. data/test/command.rb +1 -1
  104. data/test/run-test.rb +5 -4
  105. data/test/test_associations.rb +143 -9
  106. data/test/test_base.rb +25 -1
  107. data/test/test_dn.rb +2 -0
  108. data/test/test_find.rb +8 -1
  109. data/test/test_ldif.rb +51 -114
  110. data/test/test_reflection.rb +4 -8
  111. data/test/test_usermod-lang-add.rb +2 -1
  112. data/test/test_validation.rb +4 -3
  113. metadata +76 -31
  114. data/test-unit-ext/NEWS.en +0 -28
  115. data/test-unit-ext/NEWS.ja +0 -28
  116. data/test-unit-ext/README.en +0 -247
  117. data/test-unit-ext/README.ja +0 -246
  118. data/test-unit-ext/Rakefile +0 -111
  119. data/test-unit-ext/lib/test-unit-ext.rb +0 -16
  120. data/test-unit-ext/lib/test-unit-ext/always-show-result.rb +0 -28
  121. data/test-unit-ext/lib/test-unit-ext/assertions.rb +0 -40
  122. data/test-unit-ext/lib/test-unit-ext/attributes.rb +0 -129
  123. data/test-unit-ext/lib/test-unit-ext/backtrace-filter.rb +0 -17
  124. data/test-unit-ext/lib/test-unit-ext/color.rb +0 -59
  125. data/test-unit-ext/lib/test-unit-ext/colorized-runner.rb +0 -111
  126. data/test-unit-ext/lib/test-unit-ext/diff.rb +0 -516
  127. data/test-unit-ext/lib/test-unit-ext/long-display-for-emacs.rb +0 -25
  128. data/test-unit-ext/lib/test-unit-ext/notification.rb +0 -79
  129. data/test-unit-ext/lib/test-unit-ext/omission.rb +0 -96
  130. data/test-unit-ext/lib/test-unit-ext/pending.rb +0 -97
  131. data/test-unit-ext/lib/test-unit-ext/priority.rb +0 -158
  132. data/test-unit-ext/lib/test-unit-ext/version.rb +0 -3
  133. data/test-unit-ext/lib/test-unit-ext/xml-report.rb +0 -224
  134. data/test-unit-ext/test/run-test.rb +0 -14
  135. data/test-unit-ext/test/test_attributes.rb +0 -139
  136. data/test-unit-ext/test/test_omission.rb +0 -64
  137. data/test-unit-ext/test/test_xml_report.rb +0 -161
@@ -1,3 +0,0 @@
1
- module TestUnitExt
2
- VERSION = "0.6.0"
3
- end
@@ -1,224 +0,0 @@
1
- require "erb"
2
- require "test/unit/failure"
3
- require "test/unit/error"
4
- require "test/unit/testresult"
5
- require "test/unit/testsuite"
6
- require "test/unit/autorunner"
7
-
8
- module Test
9
- module Unit
10
- module XMLReportable
11
- include ERB::Util
12
-
13
- def to_xml
14
- <<-XML.gsub(/\s*(\n <\/test>|\n<\/result>)/m, "\\1")
15
- <result>
16
- <test_case>
17
- <name>#{h(@test.class.name)}</name>
18
- <description/>
19
- </test_case>
20
- <test>
21
- <name>#{h(@test.method_name)}</name>
22
- <description/>
23
- #{options_xml}
24
- </test>
25
- <status>#{h(status_name)}</status>
26
- <detail>#{h(message)}</detail>
27
- <elapsed>#{h(elapsed_time)}</elapsed>
28
- #{backtrace_xml}
29
- </result>
30
- XML
31
- end
32
-
33
- private
34
- def options_xml
35
- @test.attributes.collect do |key, value|
36
- <<-XML
37
- <option>
38
- <name>#{h(key)}</name>
39
- <value>#{h(value)}</value>
40
- </option>
41
- XML
42
- end.join
43
- end
44
-
45
- def backtrace_xml
46
- entries = backtrace_entries_xml
47
- if entries.empty?
48
- ""
49
- else
50
- <<-XML
51
- <backtrace>
52
- #{entries.join.rstrip}
53
- </backtrace>
54
- XML
55
- end
56
- end
57
-
58
- def backtrace_entries_xml
59
- location.collect do |location|
60
- file, line, info = location.split(/:(\d+):/)
61
- <<-XML
62
- <entry>
63
- <file>#{h(file)}</file>
64
- <line>#{h(line)}</line>
65
- <info>#{h(info.to_s.strip)}</info>
66
- </entry>
67
- XML
68
- end
69
- end
70
- end
71
-
72
- class Success
73
- include XMLReportable
74
-
75
- attr_reader :test, :elapsed_time
76
- def initialize(test, elapsed_time)
77
- @test = test
78
- @elapsed_time = elapsed_time
79
- end
80
-
81
- def message
82
- nil
83
- end
84
-
85
- def location
86
- []
87
- end
88
-
89
- def test_name
90
- @test.name
91
- end
92
-
93
- def test_case_name
94
- /\((.*)\)\z/ =~ test_name
95
- $1
96
- end
97
-
98
- def status_name
99
- "success"
100
- end
101
- end
102
-
103
- class Failure
104
- include XMLReportable
105
-
106
- attr_accessor :test, :elapsed_time
107
-
108
- def status_name
109
- "failure"
110
- end
111
- end
112
-
113
- class Error
114
- include XMLReportable
115
-
116
- attr_accessor :test, :elapsed_time
117
-
118
- def status_name
119
- "error"
120
- end
121
-
122
- def location
123
- filter_backtrace(@exception.backtrace)
124
- end
125
- end
126
-
127
- class TestCase
128
- alias_method(:run_without_success_notify, :run)
129
- def run(result, &block)
130
- @_start_time = Time.now
131
- run_result = run_without_success_notify(result, &block)
132
- result.add_success(Success.new(self, Time.now - @_start_time)) if passed?
133
- run_result
134
- end
135
-
136
- alias_method(:add_failure_without_test_case_set, :add_failure)
137
- def add_failure(*args)
138
- add_failure_without_test_case_set(*args)
139
- failure = @_result.failures.last
140
- failure.test = self
141
- failure.elapsed_time = Time.now - @_start_time
142
- end
143
-
144
- alias_method(:add_error_without_test_case_set, :add_error)
145
- def add_error(*args)
146
- add_error_without_test_case_set(*args)
147
- error = @_result.errors.last
148
- error.test = self
149
- error.elapsed_time = Time.now - @_start_time
150
- end
151
- end
152
-
153
- class TestResult
154
- attr_reader :failures, :errors
155
-
156
- alias_method(:initialize_without_successes, :initialize)
157
- def initialize
158
- initialize_without_successes
159
- @successes = []
160
- @logs = []
161
- end
162
-
163
- def add_success(success)
164
- @logs << success
165
- @successes << success
166
- end
167
-
168
- alias_method(:add_failure_without_logs_store, :add_failure)
169
- def add_failure(failure)
170
- @logs << failure
171
- add_failure_without_logs_store(failure)
172
- end
173
-
174
- alias_method(:add_error_without_logs_store, :add_error)
175
- def add_error(error)
176
- @logs << error
177
- add_error_without_logs_store(error)
178
- end
179
-
180
- def to_xml
181
- return "<report/>" if @logs.empty?
182
- xml = @logs.collect {|log| log.to_xml.gsub(/^/, " ")}.join
183
- "<report>\n#{xml}</report>\n"
184
- end
185
- end
186
-
187
- class TestSuite
188
- attr_reader :result
189
-
190
- alias_method(:run_without_keep_result, :run)
191
- def run(result, &block)
192
- @result = result
193
- run_without_keep_result(result, &block)
194
- end
195
- end
196
-
197
- class AutoRunner
198
- alias_method(:options_without_xml_report_support, :options)
199
- def options
200
- opt = options_without_xml_report_support
201
- @xml_report_support_option_added ||= false
202
- unless @xml_report_support_option_added
203
- @xml_report_file = nil
204
- opt.on('--xml-report=FILE',
205
- "Output test report in XML to FILE.") do |file|
206
- @xml_report_file = file
207
- end
208
- end
209
- opt
210
- end
211
-
212
- alias_method(:run_without_xml_report_support, :run)
213
- def run
214
- passed = run_without_xml_report_support
215
- if @xml_report_file
216
- File.open(@xml_report_file, "w") do |f|
217
- f.print(@suite.result.to_xml)
218
- end
219
- end
220
- passed
221
- end
222
- end
223
- end
224
- end
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift("./lib")
4
- $LOAD_PATH.unshift("./test")
5
-
6
- require "test-unit-ext"
7
-
8
- Dir.glob("test/**/test_*.rb") do |test|
9
- begin
10
- require test
11
- rescue LoadError
12
- puts "Can't load: #{test}: #{$!.message}"
13
- end
14
- end
@@ -1,139 +0,0 @@
1
- require 'test-unit-ext'
2
-
3
- class TestAttributes < Test::Unit::TestCase
4
- class TestStack < Test::Unit::TestCase
5
- class << self
6
- def suite
7
- Test::Unit::TestSuite.new(name)
8
- end
9
- end
10
-
11
- class Stack
12
- def initialize
13
- @data = []
14
- end
15
-
16
- def push(data)
17
- @data.push(data)
18
- end
19
-
20
- def peek
21
- @data[-2]
22
- end
23
-
24
- def empty?
25
- @data.empty?
26
- end
27
-
28
- def size
29
- @data.size + 11
30
- end
31
- end
32
-
33
- def setup
34
- @stack = Stack.new
35
- end
36
-
37
- attribute :category, :accessor
38
- def test_peek
39
- @stack.push(1)
40
- @stack.push(2)
41
- assert_equal(2, @stack.peek)
42
- end
43
-
44
- attribute :bug, 1234
45
- def test_bug_1234
46
- assert_equal(0, @stack.size)
47
- end
48
-
49
- def test_no_attributes
50
- assert(@stack.empty?)
51
- @stack.push(1)
52
- assert(!@stack.empty?)
53
- assert_equal(1, @stack.size)
54
- end
55
- end
56
-
57
- def test_set_attributes
58
- test_for_bug_1234 = TestStack.new("test_bug_1234")
59
- assert_equal({:bug => 1234}, test_for_bug_1234.attributes)
60
-
61
- test_no_attributes = TestStack.new("test_no_attributes")
62
- assert_equal({}, test_no_attributes.attributes)
63
- end
64
-
65
- def test_show_attributes
66
- assert_stack_size_line = search_line('assert_equal(0, @stack.size)')
67
- assert_peek_line = search_line('assert_equal(2, @stack.peek)')
68
- first_arg_end_line = search_line("\"+ 11\"],")
69
- method_name = "test_show_attributes"
70
- assert_result(["Failure:\n" \
71
- "test_peek(TestAttributes::TestStack)\n" \
72
- " category: accessor\n" \
73
- "#{__FILE__}:#{assert_peek_line}:in `test_peek'\n" \
74
- "#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
75
- "<2> expected but was\n" \
76
- "<1>.\n" \
77
- "\n" \
78
- "diff:\n" \
79
- "- 2\n" \
80
- "+ 1",
81
- "Failure:\n" \
82
- "test_bug_1234(TestAttributes::TestStack)\n" \
83
- " bug: 1234\n" \
84
- "#{__FILE__}:#{assert_stack_size_line}:in `test_bug_1234'\n" \
85
- "#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
86
- "<0> expected but was\n" \
87
- "<11>.\n" \
88
- "\n" \
89
- "diff:\n" \
90
- "- 0\n" \
91
- "+ 11"],
92
- [],
93
- ["test_peek", "test_bug_1234"])
94
- end
95
-
96
- def test_not_show_attributes
97
- assert_line = search_line('assert_equal(1, @stack.size')
98
- first_arg_end_line = search_line("\"+ 12\"],")
99
- method_name = "test_not_show_attributes"
100
- assert_result(["Failure:\n" \
101
- "test_no_attributes(TestAttributes::TestStack)\n" \
102
- "#{__FILE__}:#{assert_line}:in `test_no_attributes'\n" \
103
- "#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
104
- "<1> expected but was\n" \
105
- "<12>.\n" \
106
- "\n" \
107
- "diff:\n" \
108
- "- 1\n" \
109
- "+ 12"],
110
- [],
111
- ["test_no_attributes"])
112
- end
113
-
114
- private
115
- def search_line(pattern)
116
- if pattern.is_a?(String)
117
- pattern = /#{Regexp.escape(pattern)}/
118
- end
119
- File.open(__FILE__) do |file|
120
- while line = file.gets
121
- return file.lineno if pattern =~ line
122
- end
123
- end
124
- nil
125
- end
126
-
127
- def assert_result(failure_results, error_results, names)
128
- tests = names.collect {|name| TestStack.new(name)}
129
- result = Test::Unit::TestResult.new
130
- mark = /\A#{Regexp.escape(__FILE__)}:#{__LINE__ + 1}/
131
- tests.each {|test| test.run(result) {}}
132
- failures = result.instance_variable_get("@failures")
133
- errors = result.instance_variable_get("@errors")
134
- failures.each {|f| f.location.reject! {|l| mark =~ l}}
135
- assert_equal([failure_results, error_results],
136
- [failures.collect {|failure| failure.long_display},
137
- errors.collect {|error| error.long_display}])
138
- end
139
- end
@@ -1,64 +0,0 @@
1
- require 'test-unit-ext'
2
-
3
- class TestOmission < Test::Unit::TestCase
4
- class TestCase < Test::Unit::TestCase
5
- class << self
6
- def suite
7
- Test::Unit::TestSuite.new(name)
8
- end
9
- end
10
-
11
- def test_omit
12
- omit("1st omit")
13
- omit("2nd omit. Not reached here.")
14
- end
15
-
16
- def test_omit_with_failure_in_block
17
- omit("Wait a minute") do
18
- raise "Not implemented yet"
19
- end
20
- assert(true, "Not reached here.")
21
- end
22
-
23
- def test_omit_with_no_failure_in_block
24
- omit("Wait a minute") do
25
- "Nothing raised"
26
- end
27
- assert(true, "Reached here.")
28
- end
29
- end
30
-
31
- def test_omit
32
- result = run_test("test_omit")
33
- assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
34
- "1 omissions, 0 notifications",
35
- result.to_s)
36
- assert_equal(["1st omit"],
37
- result.omissions.collect {|omission| omission.message})
38
- end
39
-
40
- def test_omit_with_failure_in_block
41
- result = run_test("test_omit_with_failure_in_block")
42
- assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
43
- "1 omissions, 0 notifications",
44
- result.to_s)
45
- assert_equal(["Wait a minute"],
46
- result.omissions.collect {|omission| omission.message})
47
- end
48
-
49
- def test_omit_with_no_failure_in_block
50
- result = run_test("test_omit_with_no_failure_in_block")
51
- assert_equal("1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, " \
52
- "0 omissions, 0 notifications",
53
- result.to_s)
54
- assert_equal(["Omission block should not be passed: Wait a minute."],
55
- result.failures.collect {|failure| failure.message})
56
- end
57
-
58
- private
59
- def run_test(name)
60
- result = Test::Unit::TestResult.new
61
- TestCase.new(name).run(result) {}
62
- result
63
- end
64
- end
@@ -1,161 +0,0 @@
1
- require 'test-unit-ext'
2
-
3
- class TestXMLReport < Test::Unit::TestCase
4
- class TestCase < Test::Unit::TestCase
5
- def default_test
6
- end
7
-
8
- def _test_success
9
- assert(true)
10
- end
11
-
12
- TEST_FAILURE_LINE = __LINE__ + 3
13
- bug 1234
14
- def _test_failure
15
- assert(false)
16
- end
17
-
18
- TEST_ERROR_LINE = __LINE__ + 2
19
- def _test_error
20
- non_existence_method()
21
- end
22
-
23
- def inspect
24
- "TEST-CASE"
25
- end
26
- end
27
-
28
- include ERB::Util
29
-
30
- def test_empty_test
31
- assert_xml("<report/>", suite)
32
- end
33
-
34
- def test_success_result
35
- elapsed = "0.001"
36
- assert_xml(<<-XML, suite([TestCase.new("_test_success")]), elapsed)
37
- <report>
38
- <result>
39
- <test_case>
40
- <name>TestXMLReport::TestCase</name>
41
- <description/>
42
- </test_case>
43
- <test>
44
- <name>_test_success</name>
45
- <description/>
46
- </test>
47
- <status>success</status>
48
- <detail></detail>
49
- <elapsed>#{elapsed}</elapsed>
50
- </result>
51
- </report>
52
- XML
53
- end
54
-
55
- def test_failure_result
56
- elapsed = "0.001"
57
- backtrace_line = __LINE__ + 1
58
- assert_xml(<<-XML, suite([TestCase.new("_test_failure")]), elapsed)
59
- <report>
60
- <result>
61
- <test_case>
62
- <name>TestXMLReport::TestCase</name>
63
- <description/>
64
- </test_case>
65
- <test>
66
- <name>_test_failure</name>
67
- <description/>
68
- <option>
69
- <name>bug</name>
70
- <value>1234</value>
71
- </option>
72
- </test>
73
- <status>failure</status>
74
- <detail>&lt;false&gt; is not true.</detail>
75
- <elapsed>#{elapsed}</elapsed>
76
- <backtrace>
77
- <entry>
78
- <file>#{__FILE__}</file>
79
- <line>#{TestCase::TEST_FAILURE_LINE}</line>
80
- <info>in `_test_failure'</info>
81
- </entry>
82
- <entry>
83
- <file>#{__FILE__}</file>
84
- <line>#{TEST_RUN_LINE}</line>
85
- <info>in `assert_xml'</info>
86
- </entry>
87
- <entry>
88
- <file>#{__FILE__}</file>
89
- <line>#{backtrace_line}</line>
90
- <info>in `test_failure_result'</info>
91
- </entry>
92
- </backtrace>
93
- </result>
94
- </report>
95
- XML
96
- end
97
-
98
- def test_error_result
99
- test = TestCase.new("_test_error")
100
- detail = "NoMethodError: undefined method `non_existence_method' " +
101
- "for TEST-CASE:#{test.class.name}"
102
- elapsed = "0.001"
103
- backtrace_line = __LINE__ + 1
104
- assert_xml(<<-XML, suite([test]), elapsed)
105
- <report>
106
- <result>
107
- <test_case>
108
- <name>TestXMLReport::TestCase</name>
109
- <description/>
110
- </test_case>
111
- <test>
112
- <name>_test_error</name>
113
- <description/>
114
- </test>
115
- <status>error</status>
116
- <detail>#{h(detail)}</detail>
117
- <elapsed>#{elapsed}</elapsed>
118
- <backtrace>
119
- <entry>
120
- <file>#{__FILE__}</file>
121
- <line>#{TestCase::TEST_ERROR_LINE}</line>
122
- <info>in `_test_error'</info>
123
- </entry>
124
- <entry>
125
- <file>#{__FILE__}</file>
126
- <line>#{TEST_RUN_LINE}</line>
127
- <info>in `assert_xml'</info>
128
- </entry>
129
- <entry>
130
- <file>#{__FILE__}</file>
131
- <line>#{backtrace_line}</line>
132
- <info>in `test_error_result'</info>
133
- </entry>
134
- </backtrace>
135
- </result>
136
- </report>
137
- XML
138
- end
139
-
140
- private
141
- def suite(tests=[], name="Unnamed TestSuite")
142
- test_suite = Test::Unit::TestSuite.new(name)
143
- tests.each do |test|
144
- test_suite << test
145
- end
146
- test_suite
147
- end
148
-
149
- TEST_RUN_LINE = __LINE__ + 2
150
- def assert_xml(expected, suite, normalized_elapsed=nil)
151
- result = Test::Unit::UI::Console::TestRunner.run(suite,
152
- Test::Unit::UI::SILENT)
153
- xml = result.to_xml
154
- if xml and normalized_elapsed
155
- xml = xml.gsub(/<elapsed>[\d.]+<\/elapsed>/) do
156
- "<elapsed>#{normalized_elapsed}</elapsed>"
157
- end
158
- end
159
- assert_equal(expected, xml)
160
- end
161
- end