activesambaldap 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.en +6 -1
- data/NEWS.ja +6 -1
- data/README.en +3 -2
- data/README.ja +3 -2
- data/Rakefile +21 -2
- data/bin/asl-groupadd +0 -0
- data/bin/asl-groupadd.help +15 -0
- data/bin/asl-groupdel +0 -0
- data/bin/asl-groupdel.help +12 -0
- data/bin/asl-groupmod +0 -0
- data/bin/asl-groupmod.help +18 -0
- data/bin/asl-groupshow +0 -0
- data/bin/asl-groupshow.help +10 -0
- data/bin/asl-passwd +0 -0
- data/bin/asl-passwd.help +14 -0
- data/bin/asl-populate +0 -0
- data/bin/asl-populate.help +27 -0
- data/bin/asl-purge +0 -0
- data/bin/asl-purge.help +10 -0
- data/bin/asl-samba-computeradd +0 -0
- data/bin/asl-samba-computeradd.help +12 -0
- data/bin/asl-samba-groupadd +0 -0
- data/bin/asl-samba-groupadd.help +10 -0
- data/bin/asl-samba-groupdel +0 -0
- data/bin/asl-samba-groupdel.help +10 -0
- data/bin/asl-samba-groupmod +0 -0
- data/bin/asl-samba-groupmod.help +14 -0
- data/bin/asl-samba-useradd +0 -0
- data/bin/asl-samba-useradd.help +12 -0
- data/bin/asl-samba-userdel +0 -0
- data/bin/asl-samba-userdel.help +10 -0
- data/bin/asl-samba-usermod +0 -0
- data/bin/asl-samba-usermod.help +14 -0
- data/bin/asl-useradd +0 -0
- data/bin/asl-useradd.help +47 -0
- data/bin/asl-userdel +0 -0
- data/bin/asl-userdel.help +17 -0
- data/bin/asl-usermod +0 -0
- data/bin/asl-usermod.help +45 -0
- data/bin/asl-usershow +0 -0
- data/bin/asl-usershow.help +10 -0
- data/lib/active_samba_ldap.rb +9 -3
- data/lib/active_samba_ldap/account_entry.rb +1 -1
- data/lib/active_samba_ldap/group_entry.rb +3 -5
- data/lib/active_samba_ldap/reloadable.rb +2 -0
- data/lib/active_samba_ldap/samba_group_entry.rb +1 -1
- data/lib/active_samba_ldap/version.rb +1 -1
- data/misc/rd2html.rb +1 -1
- data/rails/plugin/active_samba_ldap/init.rb +15 -0
- data/test-unit/History.txt +32 -0
- data/test-unit/README.txt +32 -0
- data/test-unit/Rakefile +22 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/lib/test/unit.rb +280 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +722 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +250 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color.rb +61 -0
- data/test-unit/lib/test/unit/diff.rb +524 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +185 -0
- data/test-unit/lib/test/unit/notification.rb +116 -0
- data/test-unit/lib/test/unit/omission.rb +129 -0
- data/test-unit/lib/test/unit/pending.rb +130 -0
- data/test-unit/lib/test/unit/priority.rb +146 -0
- data/test-unit/lib/test/unit/runner/console.rb +46 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +174 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +195 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test_descendant.rb +135 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_load.rb +333 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test_assertions.rb +693 -0
- data/test-unit/test/test_attribute.rb +86 -0
- data/test-unit/test/test_color.rb +37 -0
- data/test-unit/test/test_diff.rb +477 -0
- data/test-unit/test/test_emacs_runner.rb +60 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_fixture.rb +275 -0
- data/test-unit/test/test_notification.rb +33 -0
- data/test-unit/test/test_omission.rb +81 -0
- data/test-unit/test/test_pending.rb +64 -0
- data/test-unit/test/test_priority.rb +89 -0
- data/test-unit/test/test_testcase.rb +411 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit_test_util.rb +12 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/asl-test-utils.rb +0 -1
- data/test/run-test.rb +8 -12
- data/test/test_asl_groupmod.rb +3 -1
- data/test/test_asl_useradd.rb +3 -3
- data/test/test_samba_encrypt.rb +0 -1
- metadata +225 -88
- data/po/active-samba-ldap.pot +0 -459
- data/test/test-unit-ext.rb +0 -4
- data/test/test-unit-ext/always-show-result.rb +0 -28
- data/test/test-unit-ext/backtrace-filter.rb +0 -17
- data/test/test-unit-ext/long-display-for-emacs.rb +0 -25
- data/test/test-unit-ext/priority.rb +0 -186
data/bin/asl-usermod
CHANGED
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Usage: asl-usermod [options] USER_NAME
|
2
|
+
-c, --[no-]computer-account is a Windows Workstation
|
3
|
+
(otherwise, Windows user)
|
4
|
+
(false)
|
5
|
+
--gecos=GECOS gecos
|
6
|
+
-d, --home-directory=HOME_DIR home directory
|
7
|
+
-m, --[no-]move-home-directory move home directory
|
8
|
+
(false)
|
9
|
+
-r, --rename=NEW_NAME new user name (cn and dn are updated)
|
10
|
+
-u, --uid=UID uid
|
11
|
+
--[no-]allow-non-unique-uid uid can be non unique
|
12
|
+
(false)
|
13
|
+
-g, --gid=GID gid
|
14
|
+
-G, --groups=GID1,GID2,GID3 supplementary groups (comma separated)
|
15
|
+
--[no-]merge-groups replace supplementary groups
|
16
|
+
(false)
|
17
|
+
-s, --shell=SHELL shell
|
18
|
+
--given-name=NAME given name
|
19
|
+
-N, --common-name=NAME common name
|
20
|
+
-S, --surname=NAME surname
|
21
|
+
For samba accounts:
|
22
|
+
-e, --expire-date=DATE expire date
|
23
|
+
-C, --[no-]can-change-password can change password
|
24
|
+
-M, --[no-]must-change-password must change password
|
25
|
+
--samba-home-path=PATH sambaHomePath
|
26
|
+
(SMB home share, like '\\PDC\user'
|
27
|
+
--samba-home-drive=DRIVE sambaHomeDrive
|
28
|
+
(letter associated with home share, like 'H:')
|
29
|
+
--samba-logon-script=SCRIPT sambaLogonScript
|
30
|
+
(DOS script to execute on login)
|
31
|
+
--samba-profile-path=PATH sambaProfilePath
|
32
|
+
(profile directory, like '\\PDC\profiles\user')
|
33
|
+
--samba-account-flags=FLAGS sambaAcctFlags
|
34
|
+
(samba account control bits, like '[NDHTUMWSLXI]')
|
35
|
+
-D, --[no-]disable-user disable this user
|
36
|
+
-E, --[no-]enable-user enable this user
|
37
|
+
Common options:
|
38
|
+
--config=CONFIG Specify configuration file
|
39
|
+
Default configuration files:
|
40
|
+
/etc/activesambaldap/config.yaml
|
41
|
+
/etc/activesambaldap/bind.yaml
|
42
|
+
/home/kou/.activesambaldap.conf
|
43
|
+
/home/kou/.activesambaldap.bind
|
44
|
+
-h, --help Show this message
|
45
|
+
--version Show version
|
data/bin/asl-usershow
CHANGED
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Usage: asl-usershow [options] USER_NAME
|
2
|
+
Common options:
|
3
|
+
--config=CONFIG Specify configuration file
|
4
|
+
Default configuration files:
|
5
|
+
/etc/activesambaldap/config.yaml
|
6
|
+
/etc/activesambaldap/bind.yaml
|
7
|
+
/home/kou/.activesambaldap.conf
|
8
|
+
/home/kou/.activesambaldap.bind
|
9
|
+
-h, --help Show this message
|
10
|
+
--version Show version
|
data/lib/active_samba_ldap.rb
CHANGED
@@ -8,12 +8,18 @@ require_gem_if_need = Proc.new do |library_name, gem_name, *options|
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
required_active_ldap_version = ">= 0.
|
11
|
+
required_active_ldap_version = ">= 1.0.1"
|
12
12
|
require_gem_if_need.call("active_ldap", "activeldap",
|
13
13
|
required_active_ldap_version)
|
14
14
|
|
15
|
-
if
|
16
|
-
|
15
|
+
if ActiveSupport.const_defined?(:Dependencies)
|
16
|
+
dependencies = ActiveSupport::Dependencies
|
17
|
+
else
|
18
|
+
dependencies = Dependencies
|
19
|
+
end
|
20
|
+
|
21
|
+
if dependencies.respond_to?(:load_paths)
|
22
|
+
dependencies.load_paths << File.expand_path(File.dirname(__FILE__))
|
17
23
|
end
|
18
24
|
|
19
25
|
require 'active_samba_ldap/version'
|
@@ -121,7 +121,7 @@ module ActiveSambaLdap
|
|
121
121
|
|
122
122
|
def change_uid_number(uid, allow_non_unique=false)
|
123
123
|
check_unique_uid_number(uid) unless allow_non_unique
|
124
|
-
self.uid_number = Integer(uid)
|
124
|
+
self.uid_number = Integer(uid)
|
125
125
|
end
|
126
126
|
|
127
127
|
def change_password(password)
|
@@ -30,9 +30,7 @@ module ActiveSambaLdap
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def find_by_gid_number(number)
|
33
|
-
|
34
|
-
value = Integer(number).to_s
|
35
|
-
find(:first, :filter => "(#{attribute}=#{value})")
|
33
|
+
find(:first, :filter => ["gidNumber", Integer(number)])
|
36
34
|
end
|
37
35
|
|
38
36
|
private
|
@@ -129,7 +127,7 @@ module ActiveSambaLdap
|
|
129
127
|
|
130
128
|
def change_gid_number(gid, allow_non_unique=false)
|
131
129
|
check_unique_gid_number(gid) unless allow_non_unique
|
132
|
-
self.gid_number = gid
|
130
|
+
self.gid_number = gid
|
133
131
|
end
|
134
132
|
|
135
133
|
def destroy(options={})
|
@@ -159,7 +157,7 @@ module ActiveSambaLdap
|
|
159
157
|
|
160
158
|
def check_unique_gid_number(gid_number)
|
161
159
|
ActiveSambaLdap::Base.restart_nscd do
|
162
|
-
if self.class.find_by_gid_number(
|
160
|
+
if self.class.find_by_gid_number(gid_number)
|
163
161
|
raise GidNumberAlreadyExists.new(gid_number)
|
164
162
|
end
|
165
163
|
end
|
@@ -102,7 +102,7 @@ module ActiveSambaLdap
|
|
102
102
|
def change_gid_number(gid, allow_non_unique=false)
|
103
103
|
result = super
|
104
104
|
return result unless samba_available?
|
105
|
-
rid = self.class.gid2rid(gid_number
|
105
|
+
rid = self.class.gid2rid(gid_number)
|
106
106
|
change_sid(rid, allow_non_unique)
|
107
107
|
end
|
108
108
|
|
data/misc/rd2html.rb
CHANGED
@@ -34,7 +34,7 @@ Dir[File.join(top, "*.{ja,en}")].each do |f|
|
|
34
34
|
x
|
35
35
|
end
|
36
36
|
end
|
37
|
-
output_base = File.basename(f).sub(/(ja|en)\z/, "html.\\1")
|
37
|
+
output_base = File.basename(f).downcase.sub(/(ja|en)\z/, "html.\\1")
|
38
38
|
File.open(File.join(html_dir, output_base), "w") do |out|
|
39
39
|
out.puts(`ruby #{args.flatten.join(' ')}`)
|
40
40
|
end
|
@@ -1,5 +1,15 @@
|
|
1
1
|
require_library_or_gem 'active_samba_ldap'
|
2
|
+
|
2
3
|
ActiveSambaLdap::Base.logger ||= RAILS_DEFAULT_LOGGER
|
4
|
+
|
5
|
+
required_version = ["0", "0", "6"]
|
6
|
+
if (ActiveLdap::VERSION.split(".") <=> required_version) < 0
|
7
|
+
ActiveLdap::Base.class_eval do
|
8
|
+
format = _("You need ActiveSambaLdap %s or later")
|
9
|
+
logger.error(format % required_version.join("."))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
ldap_configuration_file = File.join(RAILS_ROOT, 'config', 'ldap.yml')
|
4
14
|
if File.exist?(ldap_configuration_file)
|
5
15
|
ActiveSambaLdap::Base.configurations =
|
@@ -16,3 +26,8 @@ end
|
|
16
26
|
class ActionView::Base
|
17
27
|
include ActiveLdap::Helper
|
18
28
|
end
|
29
|
+
|
30
|
+
require 'active_ldap/action_controller/ldap_benchmarking'
|
31
|
+
class ActionController::Base
|
32
|
+
include ActiveLdap::ActionController::LdapBenchmarking
|
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,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.
|
data/test-unit/Rakefile
ADDED
@@ -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,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
|