activeldap 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,246 +0,0 @@
1
- # -*- rd -*-
2
-
3
- = README.ja
4
-
5
- == 名前
6
-
7
- TestUnitExt
8
-
9
- == なにこれ?
10
-
11
- TestUnitExtはRuby標準のTest::Unitを拡張します。
12
-
13
- TestUnitExtはいくつかの有用な機能を提供します。
14
-
15
- * Emacsにやさしいバックトレースフォーマット
16
- * 優先度に応じたテストの実行
17
- * 各テストへの属性の付加
18
- * テストを途中終了(Ctrl+C)しても結果を表示
19
- * 色付き出力
20
- * テスト結果のdiff出力
21
- * テスト結果のXMLでの出力
22
- * 保留(pending)・省略(omission)・通知(notification)用メソッドの追加
23
-
24
- == 作者
25
-
26
- Kouhei Sutou <kou@cozmixng.org>
27
-
28
- == ライセンス
29
-
30
- Ruby's.
31
-
32
- # == メーリングリスト
33
- #
34
- # なし。必要?
35
-
36
- == リファレンスマニュアル
37
-
38
- ((<URL:http://test-unit-ext.rubyforge.org/doc/>))
39
-
40
- == 依存ライブラリ
41
-
42
- なし
43
-
44
- == 使用法
45
-
46
- require 'test-unit-ext'
47
-
48
- == リファレンス
49
-
50
- === 属性
51
-
52
- テストに属性を加えて、テスト失敗時により有益な情報を利用する
53
- ことができます。例えば、以下のようにテストにBug IDの情報を付
54
- 加することができます。
55
-
56
- class MyTest < Test::Unit::TestCase
57
- bug 123
58
- def test_invalid_input
59
- assert_equal("OK", input)
60
- end
61
- end
62
-
63
- この例では、test_invalid_inputテストがBug #123のテストである
64
- という情報を付加しています。
65
-
66
- これは以下のように書くこともできます。
67
-
68
- class MyTest < Test::Unit::TestCase
69
- attribute :bug, 123
70
- def test_invalid_input
71
- assert_equal("OK", input)
72
- end
73
- end
74
-
75
- つまり、bugメソッドは便利のために用意されたメソッドです。
76
- attributeメソッドを使うことで任意の属性を付加することができ
77
- ます。
78
-
79
- === 優先度
80
-
81
- テストが多くなるとテスト時間が長くなり、テストと開発をリズム
82
- 良く繰り返すことが難しくなります。それを軽減するために、開発
83
- 時のテストでは毎回全てのテストを実行するのではなく、一部のテ
84
- ストのみ実行して1回のテスト時間を短くすることができます。問題
85
- は各テストでどのテストを実行するかです。
86
-
87
- TestUnitExtでは属性としてテストに優先度を付け、それに従って毎
88
- 回実行するテストを確率的に選択します。コマンドラインオプショ
89
- ンで--priorityを指定するとこの機能が有効になります。
90
-
91
- 優先度が高いテスト程高い確率で実行され、そうではないテストは
92
- 低い頻度で実行されます。各テストでは全てのテストは実行しない
93
- が、各テストで実行するテストがその都度変わるため、何度も走ら
94
- せることにより結果的にテスト全体を実行することになります。
95
-
96
- また、前回成功しなかったテストは確実に実行するため、明示的に
97
- 優先度を上げなくても失敗している(現在注目すべき重要な)テス
98
- トは毎回必ず実行します。これにより、プログラマの負荷をあげる
99
- ことなくテストのメリットを受けたまま、テストと開発のリズムを
100
- 保つことができます。
101
-
102
- 優先度は以下のように指定します。優先度指定はpublicやprivateの
103
- ように、以降のメソッド定義に影響します。
104
-
105
- class MyTest < Test::Unit::TestCase
106
- priority :must
107
- def test_must
108
- # 必ず実行
109
- end
110
-
111
- def test_must2
112
- # これも必ず実行
113
- end
114
-
115
- priority :import
116
- def test_import
117
- # 高い確率で実行
118
- end
119
-
120
- priority :high
121
- def test_high
122
- # やや高い確率で実行
123
- end
124
-
125
- priority :normal
126
- def test_normal
127
- # 半々の確率で実行
128
- # 優先度を指定していないときはnormal
129
- end
130
-
131
- priority :low
132
- def test_low
133
- # たまに実行
134
- end
135
-
136
- priority :never
137
- def test_never
138
- # 実行しない
139
- end
140
- end
141
-
142
- === 保留
143
-
144
- 現在はまだ実装していない機能をテストとして書く場合もあります。
145
- その場合、まだ実装していない機能のテストは失敗します。たしか
146
- にテストは失敗なのですが、そのテストは「実装が間違っている」
147
- ではなく、「まだ実装していない」を意図しています。これを明示
148
- 的に表現するために新しくpendというメソッドを用意しています。
149
-
150
- 「現在はまだ実装していない」という場合はこのメソッドを使って、
151
- その意図をコードで表現してください。
152
-
153
- class MyTest < Test::Unit::TestCase
154
- def test_minor_function
155
- pend("Should implement")
156
- assert_equal("Good!", MyModule.minor_function)
157
- end
158
- end
159
-
160
- === 省略
161
-
162
- 特定の環境でしか動作しないテストを書く場合もあります。その場
163
- 合、特定の環境以外ではそのテストは失敗します。この場合はその
164
- テストは特定の環境以外では失敗することがわかっています。その
165
- ため、特定の環境以外ではそのテストは省略します。これを明示的
166
- に表現するために新しくomitというメソッドを用意しています。
167
-
168
- 「このテストは省略する」という場合はこのメソッドを使って、そ
169
- の意図をコードで表現してください。
170
-
171
- class MyTest < Test::Unit::TestCase
172
- def test_special_function
173
- omit("Only for special environment") unless MyModule.special_environment?
174
- assert_equal("Good!", MyModule.special_function)
175
- end
176
- end
177
-
178
- === 通知
179
-
180
- テスト中で何らかのメッセージを残したいことがあります。例えば、
181
- 「この環境では○○モジュールがないからこのテストは省略しま
182
- す」、という場合です。
183
-
184
- それらのメッセージをputsで表示することもできますが、テスト結
185
- 果の表示が乱れてしまいます。これを防ぐために、新しくnotifyメ
186
- ソッドを用意しています。notifyを使うとメッセージはその場では
187
- 表示されず、テスト終了後に他の「失敗」や「エラー」などと同じ
188
- ように表示されます。これにより、テスト結果の表示を乱さずにメッ
189
- セージを残すことができます。
190
-
191
- class MyTest < Test::Unit::TestCase
192
- def test_with_other_module
193
- unless MyModule.have_XXX?
194
- notify("XXX module isn't found. skip this test.")
195
- return
196
- end
197
- assert_equal("XXX Module!!!", MyModule.use_XXX)
198
- end
199
- end
200
-
201
- === XML出力
202
-
203
- --xml-reportオプションを指定することでテスト結果をXML形式で出
204
- 力することができます。出力されるXMLは以下のような構造になって
205
- います。
206
-
207
- <report>
208
- <result>
209
- <test-case>
210
- <name>テストケース名</name>
211
- <description>テストケースの説明(もしあれば)</description>
212
- </test-case>
213
- <test>
214
- <name>テスト名</name>
215
- <description>テストの説明(もしあれば)</description>
216
- <option><!-- 属性情報(もしあれば) -->
217
- <name>属性名(例: bug)</name>
218
- <value>属性値(例: 1234)</value>
219
- </option>
220
- <option>
221
- ...
222
- </option>
223
- </test>
224
- <status>テスト結果([success|failure|error|pending|notification])</status>
225
- <detail>テスト結果の詳細(もしあれば)</detail>
226
- <backtrace><!-- バックトレース(もしあれば) -->
227
- <entry>
228
- <file>ファイル名</file>
229
- <line>行</line>
230
- <info>付加情報</info>
231
- </entry>
232
- <entry>
233
- ...
234
- </entry>
235
- </backtrace>
236
- <elapsed>実行時間(例: 0.000010)</elapsed>
237
- </result>
238
- <result>
239
- ...
240
- </result>
241
- ...
242
- </report>
243
-
244
- == 感謝
245
-
246
- * ...
@@ -1,111 +0,0 @@
1
- # -*- mode: ruby; coding: utf-8 -*-
2
-
3
- require 'English'
4
-
5
- require 'find'
6
- require 'fileutils'
7
- require 'rubygems'
8
- require 'hoe'
9
-
10
- base_dir = File.join(File.dirname(__FILE__))
11
- truncate_base_dir = Proc.new do |x|
12
- x.gsub(/^#{Regexp.escape(base_dir + File::SEPARATOR)}/, '')
13
- end
14
-
15
- lib_dir = File.join(base_dir, 'lib')
16
- $LOAD_PATH.unshift(lib_dir)
17
-
18
- require 'test-unit-ext'
19
-
20
- Test::Unit.run = true
21
-
22
- manifest = File.join(base_dir, "Manifest.txt")
23
- manifest_contents = []
24
- base_dir_included_components = %w(NEWS.en NEWS.ja README.en README.ja Rakefile)
25
- excluded_components = %w(.svn .test-result pkg)
26
- excluded_suffixes = %w(.png .ps .pdf .o .so .txt)
27
- Find.find(base_dir) do |target|
28
- target = truncate_base_dir[target]
29
- components = target.split(File::SEPARATOR)
30
- if components.size == 1 and !File.directory?(target)
31
- next unless base_dir_included_components.include?(components[0])
32
- end
33
- Find.prune if (excluded_components - components) != excluded_components
34
- next if excluded_suffixes.include?(File.extname(target))
35
- manifest_contents << target if File.file?(target)
36
- end
37
-
38
- dummy_files = %w(History.txt README.txt)
39
- FileUtils.touch("History.txt")
40
- FileUtils.cp("README.en", "README.txt")
41
-
42
- File.open(manifest, "w") do |f|
43
- f.puts manifest_contents.sort.join("\n")
44
- end
45
- at_exit do
46
- FileUtils.rm_f(manifest)
47
- FileUtils.rm_f(dummy_files)
48
- end
49
-
50
- def cleanup_white_space(entry)
51
- entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
52
- end
53
-
54
- version = TestUnitExt::VERSION
55
- ENV["VERSION"] = version
56
- project = Hoe.new('test-unit-ext', version) do |project|
57
- project.rubyforge_name = 'test-unit-ext'
58
- project.remote_rdoc_dir = "doc"
59
- project.author = ["Kouhei Sutou"]
60
- project.email = ['kou@cozmixng.org']
61
- project.summary = 'Ruby bindings for cairo'
62
- project.url = 'http://test-unit-ext.rubyforge.org/'
63
-
64
- news_of_current_release = File.read("NEWS.en").split(/^==\s.*$/)[1]
65
- project.changes = cleanup_white_space(news_of_current_release)
66
-
67
- entries = File.read("README.en").split(/^==\s(.*)$/)
68
- whats_this = cleanup_white_space(entries[entries.index("What\'s this?") + 1])
69
- project.summary, project.description, = whats_this.split(/\n\n+/, 3)
70
- end
71
-
72
- spec = project.spec
73
- spec.rdoc_options = spec.rdoc_options.collect do |option|
74
- option == "README.txt" ? "README.en" : option
75
- end
76
- spec.extra_rdoc_files += spec.files.grep(/(:?README|NEWS)\.(:?ja|en)\z/)
77
- spec.dependencies.delete_if {|dependency| dependency.name == "hoe"}
78
-
79
- rdoc_task = nil
80
- if ObjectSpace.each_object(Rake::RDocTask) {|rdoc_task|} != 1
81
- puts "hoe may be changed"
82
- end
83
- rdoc_task.main = "README.en"
84
- rdoc_task.options.delete("-d")
85
- rdoc_task.options << "--charset=UTF-8"
86
- rdoc_task.template = "kilmer"
87
- rdoc_task.rdoc_files += ["README.en", "NEWS.en"]
88
-
89
- desc 'Tag the repository for release.'
90
- task :tag do
91
- message = "Released TestUnitExt #{version}!"
92
- base = "svn+ssh://#{ENV['USER']}@rubyforge.org/var/svn/test-unit-ext/"
93
- sh 'svn', 'copy', '-m', message, "#{base}trunk", "#{base}tags/#{version}"
94
- end
95
-
96
- desc "Publish static HTML files"
97
- task :publish_html do
98
- ruby "misc/rd2html.rb"
99
- Dir.glob("html/*.html.en") do |html_en|
100
- FileUtils.cp(html_en, html_en.sub(/\.en$/, ''))
101
- end
102
- config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
103
- host = "#{config["username"]}@rubyforge.org"
104
- remote_dir = "/var/www/gforge-projects/#{project.rubyforge_name}"
105
- local_dir = "html"
106
- sh "rsync #{project.rsync_args} #{local_dir}/*.html* #{host}:#{remote_dir}"
107
- end
108
- task :publish_docs => :publish_html
109
-
110
- desc "Distribute new release."
111
- task :dist => [:publish_docs, :release, :tag, :announce]
@@ -1,16 +0,0 @@
1
- require "test/unit"
2
-
3
- require "test-unit-ext/version"
4
- require "test-unit-ext/color"
5
- require "test-unit-ext/colorized-runner"
6
- require "test-unit-ext/diff"
7
- require "test-unit-ext/always-show-result"
8
- require "test-unit-ext/attributes"
9
- require "test-unit-ext/priority"
10
- require "test-unit-ext/backtrace-filter"
11
- require "test-unit-ext/long-display-for-emacs"
12
- require "test-unit-ext/xml-report"
13
- require "test-unit-ext/assertions"
14
- require "test-unit-ext/pending"
15
- require "test-unit-ext/omission"
16
- require "test-unit-ext/notification"
@@ -1,28 +0,0 @@
1
- require "test/unit/ui/testrunnermediator"
2
-
3
- module Test
4
- module Unit
5
- module UI
6
- class TestRunnerMediator
7
- alias_method :original_run_suite, :run_suite
8
- def run_suite
9
- @notified_finished = false
10
- begin_time = Time.now
11
- original_run_suite
12
- rescue Interrupt
13
- unless @notified_finished
14
- end_time = Time.now
15
- elapsed_time = end_time - begin_time
16
- notify_listeners(FINISHED, elapsed_time)
17
- end
18
- raise
19
- end
20
-
21
- def notify_listeners(channel_name, *arguments)
22
- @notified_finished = true if channel_name == FINISHED
23
- super
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,40 +0,0 @@
1
- require "test/unit/testcase"
2
-
3
- module Test
4
- module Unit
5
- module AssertionsWithDiff
6
- def assert_equal(expected, actual, message=nil)
7
- super
8
- rescue AssertionFailedError
9
- expected = PP.pp(expected, "") unless expected.is_a?(String)
10
- actual = PP.pp(actual, "") unless actual.is_a?(String)
11
- diff = Diff.readable(expected, actual)
12
- if /^[\?\-\+].{79}/ =~ diff
13
- folded_diff = Diff.readable(fold(expected), fold(actual))
14
- diff = "#{diff}\n\nfolded diff:\n#{folded_diff}"
15
- end
16
- raise $!, "#{$!.message}\n\ndiff:\n#{diff}", $@
17
- end
18
-
19
- def fold(string)
20
- string.split(/\n/).collect do |line|
21
- line.gsub(/(.{78})/, "\\1\n")
22
- end.join("\n")
23
- end
24
- end
25
-
26
- module AdditionalAssertions
27
- def assert_boolean(expected)
28
- assert([true, false].include?(expected),
29
- build_message(nil,
30
- "<true or false> expected but was\n<?>",
31
- expected))
32
- end
33
- end
34
-
35
- class TestCase
36
- include AssertionsWithDiff
37
- include AdditionalAssertions
38
- end
39
- end
40
- end
@@ -1,129 +0,0 @@
1
- require "test/unit"
2
-
3
- module Test
4
- module Unit
5
- class TestCase
6
- class << self
7
- alias_method :method_added_without_attributes, :method_added
8
- def method_added(name)
9
- method_added_without_attributes(name)
10
- if defined?(@current_attributes)
11
- attributes = {}
12
- kept_attributes = {}
13
- @current_attributes.each do |attribute_name, attribute|
14
- attributes[attribute_name] = attribute[:value]
15
- kept_attributes[attribute_name] = attribute if attribute[:keep]
16
- end
17
- set_attributes(name, attributes)
18
- @current_attributes = kept_attributes
19
- end
20
- end
21
-
22
- def attribute(name, value, options={}, *tests)
23
- unless options.is_a?(Hash)
24
- tests << options
25
- options = {}
26
- end
27
- @current_attributes ||= {}
28
- if tests.empty?
29
- @current_attributes[name] = options.merge(:value => value)
30
- else
31
- tests.each do |test|
32
- set_attribute(test, {name => value})
33
- end
34
- end
35
- end
36
-
37
- def bug(value, *tests)
38
- attribute(:bug, value, *tests)
39
- end
40
-
41
- def set_attributes(test_name, attributes)
42
- return if attributes.empty?
43
- test_name = normalize_test_name(test_name)
44
- @attributes ||= {}
45
- @attributes[test_name] ||= {}
46
- @attributes[test_name] = @attributes[test_name].merge(attributes)
47
- end
48
-
49
- def attributes(test_name)
50
- test_name = normalize_test_name(test_name)
51
- @attributes ||= {}
52
- @attributes[test_name]
53
- end
54
-
55
- private
56
- def normalize_test_name(test_name)
57
- "test_#{test_name.to_s.sub(/^test_/, '')}"
58
- end
59
- end
60
-
61
- alias_method :run_without_attributes, :run
62
- def run(result, &block)
63
- run_without_attributes(TestResultAttributesSupport.new(result, self),
64
- &block)
65
- end
66
-
67
- def attributes
68
- self.class.attributes(@method_name) || {}
69
- end
70
- end
71
-
72
- class TestResultAttributesSupport
73
- def initialize(result, test)
74
- @result = result
75
- @test = test
76
- end
77
-
78
- def add_failure(failure)
79
- failure.attributes = @test.attributes
80
- method_missing(:add_failure, failure)
81
- end
82
-
83
- def add_error(error)
84
- error.attributes = @test.attributes
85
- method_missing(:add_error, error)
86
- end
87
-
88
- def method_missing(name, *args, &block)
89
- @result.send(name, *args, &block)
90
- end
91
- end
92
-
93
- module AttributesFormatter
94
- private
95
- def format_attributes
96
- return '' if attributes.empty?
97
- attributes.collect do |key, value|
98
- " #{key}: #{value}"
99
- end.join("\n") + "\n"
100
- end
101
- end
102
-
103
- class Failure
104
- include AttributesFormatter
105
-
106
- attr_accessor :attributes
107
-
108
- alias_method :long_display_without_attributes, :long_display
109
- def long_display
110
- test_name_re = Regexp.escape(@test_name)
111
- long_display_without_attributes.sub(/(^#{test_name_re}.*\n)/,
112
- "\\1#{format_attributes}")
113
- end
114
- end
115
-
116
- class Error
117
- include AttributesFormatter
118
-
119
- attr_accessor :attributes
120
-
121
- alias_method :long_display_without_attributes, :long_display
122
- def long_display
123
- test_name_re = Regexp.escape(@test_name)
124
- long_display_without_attributes.sub(/(^#{test_name_re}:\n)/,
125
- "\\1#{format_attributes}")
126
- end
127
- end
128
- end
129
- end