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
@@ -191,7 +191,7 @@ module ActiveLdap
191
191
  end
192
192
 
193
193
  def guess_available_adapter
194
- defined?(java) ? "jndi" : "ldap"
194
+ Object.respond_to?(:java) ? "jndi" : "ldap"
195
195
  end
196
196
  end
197
197
 
@@ -11,6 +11,9 @@ module ActiveLdap
11
11
  def initialize(source)
12
12
  @dn = nil
13
13
  source = source.to_s if source.is_a?(DN)
14
+ unless source.is_a?(String)
15
+ raise DistinguishedNameInputInvalid.new(source)
16
+ end
14
17
  @source = source
15
18
  end
16
19
 
@@ -45,7 +45,7 @@ module ActiveLdap
45
45
  return nil if @names.empty? and @aliases.empty?
46
46
  name = name.to_s
47
47
  real_name = @names[name]
48
- real_name ||= @aliases[Inflector.underscore(name)]
48
+ real_name ||= @aliases[name.underscore]
49
49
  if real_name
50
50
  real_name
51
51
  elsif allow_normalized_name
@@ -70,7 +70,7 @@ module ActiveLdap
70
70
  @schemata[real_name] = attribute
71
71
  ([real_name] + attribute.aliases).each do |name|
72
72
  @names[name] = real_name
73
- @aliases[Inflector.underscore(name)] = real_name
73
+ @aliases[name.underscore] = real_name
74
74
  @normalized_names[normalize_attribute_name(name)] = real_name
75
75
  end
76
76
  end
@@ -1,5 +1,4 @@
1
1
  require "strscan"
2
- require "base64"
3
2
  require "uri"
4
3
  require "open-uri"
5
4
 
@@ -117,7 +116,7 @@ module ActiveLdap
117
116
  def read_base64_value
118
117
  value = @scanner.scan(/[a-zA-Z0-9\+\/=]+/u)
119
118
  return nil if value.nil?
120
- Base64.decode64(value).chomp
119
+ value.unpack("m")[0].chomp
121
120
  end
122
121
 
123
122
  def read_external_file
@@ -480,6 +479,7 @@ module ActiveLdap
480
479
  def initialize(source)
481
480
  @source = source
482
481
  @scanner = StringScanner.new(@source)
482
+ @sub_scanner = nil
483
483
  @sub_scanner = next_segment || StringScanner.new("")
484
484
  end
485
485
 
@@ -161,13 +161,14 @@ module ActiveLdap
161
161
 
162
162
  def split_search_value(value)
163
163
  attr = prefix = nil
164
- return [attr, value, prefix] unless value.is_a?(String)
165
164
 
166
165
  begin
167
166
  dn = DN.parse(value)
168
167
  attr, value = dn.rdns.first.to_a.first
169
168
  rest = dn.rdns[1..-1]
170
169
  prefix = DN.new(*rest).to_s unless rest.empty?
170
+ rescue DistinguishedNameInputInvalid
171
+ return [attr, value, prefix]
171
172
  rescue DistinguishedNameInvalid
172
173
  begin
173
174
  dn = DN.parse("DUMMY=#{value}")
@@ -332,9 +333,12 @@ module ActiveLdap
332
333
  ldif.to_s
333
334
  end
334
335
 
336
+ def to_ldif_record(dn, attributes)
337
+ Ldif::Record.new(dn, attributes)
338
+ end
339
+
335
340
  def to_ldif(dn, attributes)
336
- record = Ldif::Record.new(dn, attributes)
337
- Ldif.new([record]).to_s
341
+ Ldif.new([to_ldif_record(dn, attributes)]).to_s
338
342
  end
339
343
 
340
344
  def load(ldif, options={})
@@ -1,5 +1,4 @@
1
1
  require 'English'
2
- require 'base64'
3
2
  require 'md5'
4
3
  require 'sha1'
5
4
 
@@ -13,6 +13,8 @@ module ActiveLdap
13
13
  end
14
14
  include ActiveRecord::Validations
15
15
  class << self
16
+ alias_method :human_attribute_name_active_record,
17
+ :human_attribute_name
16
18
  alias_method :human_attribute_name,
17
19
  :human_attribute_name_active_ldap
18
20
  unless method_defined?(:human_attribute_name_with_gettext)
@@ -5,7 +5,7 @@
5
5
  #
6
6
  msgid ""
7
7
  msgstr ""
8
- "Project-Id-Version: Ruby/ActiveLdap 1.0.0\n"
8
+ "Project-Id-Version: Ruby/ActiveLdap 1.0.1\n"
9
9
  "POT-Creation-Date: 2008-02-10 22:36+0900\n"
10
10
  "PO-Revision-Date: 2007-08-19 09:49+0900\n"
11
11
  "Last-Translator: Kouhei Sutou <kou@cozmixng.org>\n"
@@ -5,7 +5,7 @@
5
5
  #
6
6
  msgid ""
7
7
  msgstr ""
8
- "Project-Id-Version: Ruby/ActiveLdap 1.0.0\n"
8
+ "Project-Id-Version: Ruby/ActiveLdap 1.0.1\n"
9
9
  "POT-Creation-Date: 2008-02-10 22:36+0900\n"
10
10
  "PO-Revision-Date: 2008-02-10 22:37+0900\n"
11
11
  "Last-Translator: Kouhei Sutou <kou@cozmixng.org>\n"
@@ -1,7 +1,7 @@
1
1
  require_library_or_gem 'active_ldap'
2
2
  ActiveLdap::Base.logger ||= RAILS_DEFAULT_LOGGER
3
3
 
4
- required_version = ["0", "10", "0"]
4
+ required_version = ["1", "0", "0"]
5
5
  if (ActiveLdap::VERSION.split(".") <=> required_version) < 0
6
6
  ActiveLdap::Base.class_eval do
7
7
  format = _("You need ActiveLdap %s or later")
@@ -25,40 +25,9 @@ class ::ActionView::Base
25
25
  include ActiveLdap::Helper
26
26
  end
27
27
 
28
+ require 'active_ldap/action_controller/ldap_benchmarking'
28
29
  module ::ActionController
29
- module LdapBenchmarking
30
- def self.included(base)
31
- base.class_eval do
32
- alias_method_chain :render, :active_ldap_benchmark
33
- alias_method_chain :rendering_runtime, :active_ldap
34
- end
35
- end
36
-
37
- protected
38
- def render_with_active_ldap_benchmark(*args, &block)
39
- if logger
40
- @ldap_runtime_before_render = ActiveLdap::Base.reset_runtime
41
- result = render_without_active_ldap_benchmark(*args, &block)
42
- @ldap_runtime_after_render = ActiveLdap::Base.reset_runtime
43
- @rendering_runtime -= @ldap_runtime_after_render
44
- result
45
- else
46
- render_without_active_ldap_benchmark(*args, &block)
47
- end
48
- end
49
-
50
- private
51
- def rendering_runtime_with_active_ldap(runtime)
52
- result = rendering_runtime_without_active_ldap(runtime)
53
- ldap_runtime = ActiveLdap::Base.reset_runtime
54
- ldap_runtime += @ldap_runtime_before_render || 0
55
- ldap_runtime += @ldap_runtime_after_render || 0
56
- ldap_percentage = ldap_runtime * 100 / runtime
57
- result + (" | LDAP: %.5f (%d%%)" % [ldap_runtime, ldap_percentage])
58
- end
59
- end
60
-
61
30
  class Base
62
- include LdapBenchmarking
31
+ include ActiveLdap::ActionController::LdapBenchmarking
63
32
  end
64
33
  end
@@ -0,0 +1,32 @@
1
+ === 2.0.0 / 2008-06-15
2
+
3
+ * 15 major enhancements
4
+
5
+ * support startup/shutdown. (test case level setup/teardown)
6
+ * support multiple setup/teardown.
7
+ * support pending.
8
+ * support omission.
9
+ * support notification.
10
+ * support colorize.
11
+ * support diff.
12
+ * support test attribute.
13
+ * add assert_boolean.
14
+ * add assert_true.
15
+ * add assert_false.
16
+ * add --priority-mode option.
17
+ * don't use ObjectSpace to collect test cases.
18
+ * make more customizable. (additional options, exception handling and so on)
19
+ * improve Emacs integration.
20
+
21
+ * 4 major changes
22
+
23
+ * remove GTK+1 support.
24
+ * split GTK+ runner as another gem.
25
+ * split FOX runner as another gem.
26
+ * split Tk runner as another gem.
27
+
28
+ === 1.2.3 / 2008-02-25
29
+
30
+ * 1 major enhancement
31
+
32
+ * Birthday (as a gem)!
@@ -0,0 +1,70 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/testrb
6
+ lib/test/unit.rb
7
+ lib/test/unit/assertionfailederror.rb
8
+ lib/test/unit/assertions.rb
9
+ lib/test/unit/attribute.rb
10
+ lib/test/unit/autorunner.rb
11
+ lib/test/unit/collector.rb
12
+ lib/test/unit/collector/descendant.rb
13
+ lib/test/unit/collector/dir.rb
14
+ lib/test/unit/collector/load.rb
15
+ lib/test/unit/collector/objectspace.rb
16
+ lib/test/unit/color.rb
17
+ lib/test/unit/diff.rb
18
+ lib/test/unit/error.rb
19
+ lib/test/unit/exceptionhandler.rb
20
+ lib/test/unit/failure.rb
21
+ lib/test/unit/fixture.rb
22
+ lib/test/unit/notification.rb
23
+ lib/test/unit/omission.rb
24
+ lib/test/unit/pending.rb
25
+ lib/test/unit/priority.rb
26
+ lib/test/unit/runner/console.rb
27
+ lib/test/unit/runner/emacs.rb
28
+ lib/test/unit/testcase.rb
29
+ lib/test/unit/testresult.rb
30
+ lib/test/unit/testsuite.rb
31
+ lib/test/unit/ui/console/outputlevel.rb
32
+ lib/test/unit/ui/console/testrunner.rb
33
+ lib/test/unit/ui/emacs/testrunner.rb
34
+ lib/test/unit/ui/testrunner.rb
35
+ lib/test/unit/ui/testrunnermediator.rb
36
+ lib/test/unit/ui/testrunnerutilities.rb
37
+ lib/test/unit/util/backtracefilter.rb
38
+ lib/test/unit/util/observable.rb
39
+ lib/test/unit/util/procwrapper.rb
40
+ lib/test/unit/version.rb
41
+ sample/adder.rb
42
+ sample/subtracter.rb
43
+ sample/tc_adder.rb
44
+ sample/tc_subtracter.rb
45
+ sample/ts_examples.rb
46
+ test/collector/test_descendant.rb
47
+ test/collector/test_dir.rb
48
+ test/collector/test_load.rb
49
+ test/collector/test_objectspace.rb
50
+ test/run-test.rb
51
+ test/test_assertions.rb
52
+ test/test_attribute.rb
53
+ test/test_color.rb
54
+ test/test_diff.rb
55
+ test/test_emacs_runner.rb
56
+ test/test_error.rb
57
+ test/test_failure.rb
58
+ test/test_fixture.rb
59
+ test/test_notification.rb
60
+ test/test_omission.rb
61
+ test/test_pending.rb
62
+ test/test_priority.rb
63
+ test/test_testcase.rb
64
+ test/test_testresult.rb
65
+ test/test_testsuite.rb
66
+ test/testunit_test_util.rb
67
+ test/ui/test_testrunmediator.rb
68
+ test/util/test_backtracefilter.rb
69
+ test/util/test_observable.rb
70
+ test/util/test_procwrapper.rb
@@ -0,0 +1,32 @@
1
+ = Test::Unit (Classic)
2
+
3
+ * http://rubyforge.org/projects/test-unit/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Test::Unit (Classic) - Nathaniel Talbott's originial test-unit,
8
+ externalized from the ruby project as a gem (for tool developers).
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Test::Unit 1.2.3 is the original Test::Unit, taken
13
+ straight from the ruby distribution. It is being
14
+ distributed as a gem to allow tool builders to use it as a
15
+ stand-alone package. (The test framework in ruby is going
16
+ to radically change very soon).
17
+
18
+ * DO NOT INSTALL THIS GEM unless you're active state or some other
19
+ development tool provider! You don't need it.
20
+
21
+ * Test::Unit 2.0.0 or later are extended versions of the
22
+ original Test::Unit (== Tset::Unit 1.2.3).
23
+
24
+ == INSTALL:
25
+
26
+ * sudo gem install test-unit
27
+
28
+ == LICENSE:
29
+
30
+ (The Ruby License)
31
+
32
+ This software is distributed under the same terms as ruby.
@@ -0,0 +1,22 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/test/unit/version.rb'
6
+
7
+ Hoe.new('test-unit', Test::Unit::VERSION) do |p|
8
+ p.developer('Kouhei Sutou', 'kou@cozmixng.org')
9
+ p.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
10
+
11
+ # Ex-Parrot:
12
+ # p.developer('Nathaniel Talbott', 'nathaniel@talbott.ws')
13
+ end
14
+
15
+ task :check_manifest => :clean_test_result
16
+
17
+ task :clean_test_result do
18
+ test_results = Dir.glob("**/.test-result")
19
+ sh("rm", "-rf", *test_results) unless test_results.empty?
20
+ end
21
+
22
+ # vim: syntax=Ruby
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ (r = Test::Unit::AutoRunner.new(true)).process_args(ARGV) or
4
+ abort r.options.banner + " tests..."
5
+ exit r.run
@@ -0,0 +1,280 @@
1
+ require 'test/unit/testcase'
2
+ require 'test/unit/autorunner'
3
+
4
+ module Test # :nodoc:
5
+ #
6
+ # = Test::Unit - Ruby Unit Testing Framework
7
+ #
8
+ # == Introduction
9
+ #
10
+ # Unit testing is making waves all over the place, largely due to the
11
+ # fact that it is a core practice of XP. While XP is great, unit testing
12
+ # has been around for a long time and has always been a good idea. One
13
+ # of the keys to good unit testing, though, is not just writing tests,
14
+ # but having tests. What's the difference? Well, if you just _write_ a
15
+ # test and throw it away, you have no guarantee that something won't
16
+ # change later which breaks your code. If, on the other hand, you _have_
17
+ # tests (obviously you have to write them first), and run them as often
18
+ # as possible, you slowly build up a wall of things that cannot break
19
+ # without you immediately knowing about it. This is when unit testing
20
+ # hits its peak usefulness.
21
+ #
22
+ # Enter Test::Unit, a framework for unit testing in Ruby, helping you to
23
+ # design, debug and evaluate your code by making it easy to write and
24
+ # have tests for it.
25
+ #
26
+ #
27
+ # == Notes
28
+ #
29
+ # Test::Unit has grown out of and superceded Lapidary.
30
+ #
31
+ #
32
+ # == Feedback
33
+ #
34
+ # I like (and do my best to practice) XP, so I value early releases,
35
+ # user feedback, and clean, simple, expressive code. There is always
36
+ # room for improvement in everything I do, and Test::Unit is no
37
+ # exception. Please, let me know what you think of Test::Unit as it
38
+ # stands, and what you'd like to see expanded/changed/improved/etc. If
39
+ # you find a bug, let me know ASAP; one good way to let me know what the
40
+ # bug is is to submit a new test that catches it :-) Also, I'd love to
41
+ # hear about any successes you have with Test::Unit, and any
42
+ # documentation you might add will be greatly appreciated. My contact
43
+ # info is below.
44
+ #
45
+ #
46
+ # == Contact Information
47
+ #
48
+ # A lot of discussion happens about Ruby in general on the ruby-talk
49
+ # mailing list (http://www.ruby-lang.org/en/ml.html), and you can ask
50
+ # any questions you might have there. I monitor the list, as do many
51
+ # other helpful Rubyists, and you're sure to get a quick answer. Of
52
+ # course, you're also welcome to email me (Nathaniel Talbott) directly
53
+ # at mailto:testunit@talbott.ws, and I'll do my best to help you out.
54
+ #
55
+ #
56
+ # == Credits
57
+ #
58
+ # I'd like to thank...
59
+ #
60
+ # Matz, for a great language!
61
+ #
62
+ # Masaki Suketa, for his work on RubyUnit, which filled a vital need in
63
+ # the Ruby world for a very long time. I'm also grateful for his help in
64
+ # polishing Test::Unit and getting the RubyUnit compatibility layer
65
+ # right. His graciousness in allowing Test::Unit to supercede RubyUnit
66
+ # continues to be a challenge to me to be more willing to defer my own
67
+ # rights.
68
+ #
69
+ # Ken McKinlay, for his interest and work on unit testing, and for his
70
+ # willingness to dialog about it. He was also a great help in pointing
71
+ # out some of the holes in the RubyUnit compatibility layer.
72
+ #
73
+ # Dave Thomas, for the original idea that led to the extremely simple
74
+ # "require 'test/unit'", plus his code to improve it even more by
75
+ # allowing the selection of tests from the command-line. Also, without
76
+ # RDoc, the documentation for Test::Unit would stink a lot more than it
77
+ # does now.
78
+ #
79
+ # Everyone who's helped out with bug reports, feature ideas,
80
+ # encouragement to continue, etc. It's a real privilege to be a part of
81
+ # the Ruby community.
82
+ #
83
+ # The guys at RoleModel Software, for putting up with me repeating, "But
84
+ # this would be so much easier in Ruby!" whenever we're coding in Java.
85
+ #
86
+ # My Creator, for giving me life, and giving it more abundantly.
87
+ #
88
+ #
89
+ # == License
90
+ #
91
+ # Test::Unit is copyright (c) 2000-2003 Nathaniel Talbott. It is free
92
+ # software, and is distributed under the Ruby license. See the COPYING
93
+ # file in the standard Ruby distribution for details.
94
+ #
95
+ #
96
+ # == Warranty
97
+ #
98
+ # This software is provided "as is" and without any express or
99
+ # implied warranties, including, without limitation, the implied
100
+ # warranties of merchantibility and fitness for a particular
101
+ # purpose.
102
+ #
103
+ #
104
+ # == Author
105
+ #
106
+ # Nathaniel Talbott.
107
+ # Copyright (c) 2000-2003, Nathaniel Talbott
108
+ #
109
+ # ----
110
+ #
111
+ # = Usage
112
+ #
113
+ # The general idea behind unit testing is that you write a _test_
114
+ # _method_ that makes certain _assertions_ about your code, working
115
+ # against a _test_ _fixture_. A bunch of these _test_ _methods_ are
116
+ # bundled up into a _test_ _suite_ and can be run any time the
117
+ # developer wants. The results of a run are gathered in a _test_
118
+ # _result_ and displayed to the user through some UI. So, lets break
119
+ # this down and see how Test::Unit provides each of these necessary
120
+ # pieces.
121
+ #
122
+ #
123
+ # == Assertions
124
+ #
125
+ # These are the heart of the framework. Think of an assertion as a
126
+ # statement of expected outcome, i.e. "I assert that x should be equal
127
+ # to y". If, when the assertion is executed, it turns out to be
128
+ # correct, nothing happens, and life is good. If, on the other hand,
129
+ # your assertion turns out to be false, an error is propagated with
130
+ # pertinent information so that you can go back and make your
131
+ # assertion succeed, and, once again, life is good. For an explanation
132
+ # of the current assertions, see Test::Unit::Assertions.
133
+ #
134
+ #
135
+ # == Test Method & Test Fixture
136
+ #
137
+ # Obviously, these assertions have to be called within a context that
138
+ # knows about them and can do something meaningful with their
139
+ # pass/fail value. Also, it's handy to collect a bunch of related
140
+ # tests, each test represented by a method, into a common test class
141
+ # that knows how to run them. The tests will be in a separate class
142
+ # from the code they're testing for a couple of reasons. First of all,
143
+ # it allows your code to stay uncluttered with test code, making it
144
+ # easier to maintain. Second, it allows the tests to be stripped out
145
+ # for deployment, since they're really there for you, the developer,
146
+ # and your users don't need them. Third, and most importantly, it
147
+ # allows you to set up a common test fixture for your tests to run
148
+ # against.
149
+ #
150
+ # What's a test fixture? Well, tests do not live in a vacuum; rather,
151
+ # they're run against the code they are testing. Often, a collection
152
+ # of tests will run against a common set of data, also called a
153
+ # fixture. If they're all bundled into the same test class, they can
154
+ # all share the setting up and tearing down of that data, eliminating
155
+ # unnecessary duplication and making it much easier to add related
156
+ # tests.
157
+ #
158
+ # Test::Unit::TestCase wraps up a collection of test methods together
159
+ # and allows you to easily set up and tear down the same test fixture
160
+ # for each test. This is done by overriding #setup and/or #teardown,
161
+ # which will be called before and after each test method that is
162
+ # run. The TestCase also knows how to collect the results of your
163
+ # assertions into a Test::Unit::TestResult, which can then be reported
164
+ # back to you... but I'm getting ahead of myself. To write a test,
165
+ # follow these steps:
166
+ #
167
+ # * Make sure Test::Unit is in your library path.
168
+ # * require 'test/unit' in your test script.
169
+ # * Create a class that subclasses Test::Unit::TestCase.
170
+ # * Add a method that begins with "test" to your class.
171
+ # * Make assertions in your test method.
172
+ # * Optionally define #setup and/or #teardown to set up and/or tear
173
+ # down your common test fixture.
174
+ # * You can now run your test as you would any other Ruby
175
+ # script... try it and see!
176
+ #
177
+ # A really simple test might look like this (#setup and #teardown are
178
+ # commented out to indicate that they are completely optional):
179
+ #
180
+ # require 'test/unit'
181
+ #
182
+ # class TC_MyTest < Test::Unit::TestCase
183
+ # # def setup
184
+ # # end
185
+ #
186
+ # # def teardown
187
+ # # end
188
+ #
189
+ # def test_fail
190
+ # assert(false, 'Assertion was false.')
191
+ # end
192
+ # end
193
+ #
194
+ #
195
+ # == Test Runners
196
+ #
197
+ # So, now you have this great test class, but you still need a way to
198
+ # run it and view any failures that occur during the run. This is
199
+ # where Test::Unit::UI::Console::TestRunner (and others, such as
200
+ # Test::Unit::UI::GTK::TestRunner) comes into play. The console test
201
+ # runner is automatically invoked for you if you require 'test/unit'
202
+ # and simply run the file. To use another runner, or to manually
203
+ # invoke a runner, simply call its run class method and pass in an
204
+ # object that responds to the suite message with a
205
+ # Test::Unit::TestSuite. This can be as simple as passing in your
206
+ # TestCase class (which has a class suite method). It might look
207
+ # something like this:
208
+ #
209
+ # require 'test/unit/ui/console/testrunner'
210
+ # Test::Unit::UI::Console::TestRunner.run(TC_MyTest)
211
+ #
212
+ #
213
+ # == Test Suite
214
+ #
215
+ # As more and more unit tests accumulate for a given project, it
216
+ # becomes a real drag running them one at a time, and it also
217
+ # introduces the potential to overlook a failing test because you
218
+ # forget to run it. Suddenly it becomes very handy that the
219
+ # TestRunners can take any object that returns a Test::Unit::TestSuite
220
+ # in response to a suite method. The TestSuite can, in turn, contain
221
+ # other TestSuites or individual tests (typically created by a
222
+ # TestCase). In other words, you can easily wrap up a group of
223
+ # TestCases and TestSuites like this:
224
+ #
225
+ # require 'test/unit/testsuite'
226
+ # require 'tc_myfirsttests'
227
+ # require 'tc_moretestsbyme'
228
+ # require 'ts_anothersetoftests'
229
+ #
230
+ # class TS_MyTests
231
+ # def self.suite
232
+ # suite = Test::Unit::TestSuite.new
233
+ # suite << TC_MyFirstTests.suite
234
+ # suite << TC_MoreTestsByMe.suite
235
+ # suite << TS_AnotherSetOfTests.suite
236
+ # return suite
237
+ # end
238
+ # end
239
+ # Test::Unit::UI::Console::TestRunner.run(TS_MyTests)
240
+ #
241
+ # Now, this is a bit cumbersome, so Test::Unit does a little bit more
242
+ # for you, by wrapping these up automatically when you require
243
+ # 'test/unit'. What does this mean? It means you could write the above
244
+ # test case like this instead:
245
+ #
246
+ # require 'test/unit'
247
+ # require 'tc_myfirsttests'
248
+ # require 'tc_moretestsbyme'
249
+ # require 'ts_anothersetoftests'
250
+ #
251
+ # Test::Unit is smart enough to find all the test cases existing in
252
+ # the ObjectSpace and wrap them up into a suite for you. It then runs
253
+ # the dynamic suite using the console TestRunner.
254
+ #
255
+ #
256
+ # == Questions?
257
+ #
258
+ # I'd really like to get feedback from all levels of Ruby
259
+ # practitioners about typos, grammatical errors, unclear statements,
260
+ # missing points, etc., in this document (or any other).
261
+ #
262
+
263
+ module Unit
264
+ # If set to false Test::Unit will not automatically run at exit.
265
+ def self.run=(flag)
266
+ @run = flag
267
+ end
268
+
269
+ # Automatically run tests at exit?
270
+ def self.run?
271
+ @run ||= false
272
+ end
273
+ end
274
+ end
275
+
276
+ at_exit do
277
+ unless $! || Test::Unit.run?
278
+ exit Test::Unit::AutoRunner.run
279
+ end
280
+ end