dust 0.1.2 → 0.1.4
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.
- data/README +31 -0
- data/lib/array_extension.rb +1 -1
- data/lib/definition_error.rb +17 -1
- data/lib/dust.rb +1 -0
- data/lib/nil_extension.rb +1 -1
- data/lib/object_extension.rb +31 -5
- data/lib/string_extension.rb +5 -0
- data/lib/symbol_extension.rb +1 -1
- data/lib/test_case_extension.rb +69 -18
- data/rakefile.rb +1 -1
- data/test/failing_with_helper_unit_test.rb +1 -1
- data/test/failing_with_setup_unit_test.rb +1 -1
- data/test/functional_test.rb +5 -0
- data/test/passing_unit_test.rb +4 -0
- metadata +3 -2
data/README
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
= Dust
|
2
|
+
|
3
|
+
Dust adds descriptive block syntax test definition.
|
4
|
+
|
5
|
+
by Jay[http://blog.jayfields.com] Fields[http://blog.jayfields.com]
|
6
|
+
|
7
|
+
== Download and Installation
|
8
|
+
|
9
|
+
You can download Dust from here[http://rubyforge.org/projects/dust] or install it with the following command.
|
10
|
+
|
11
|
+
$ gem install dust
|
12
|
+
|
13
|
+
== License
|
14
|
+
|
15
|
+
You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt).
|
16
|
+
|
17
|
+
== Examples
|
18
|
+
|
19
|
+
unit_tests do
|
20
|
+
|
21
|
+
test "assert true" do
|
22
|
+
assert_equal true, true
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
See the tests for more examples
|
28
|
+
|
29
|
+
== Contributors
|
30
|
+
|
31
|
+
Dan Manges
|
data/lib/array_extension.rb
CHANGED
data/lib/definition_error.rb
CHANGED
@@ -1,4 +1,20 @@
|
|
1
|
-
module Dust
|
1
|
+
module Dust #:nodoc:
|
2
|
+
# Dust::DefinitionError is raised when you attempt to define a disallowed method within a test file.
|
3
|
+
#
|
4
|
+
# Test::Unit::TestCase.disallow_setup!
|
5
|
+
#
|
6
|
+
# unit_tests do
|
7
|
+
# def setup
|
8
|
+
# ...
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# test "name" do
|
12
|
+
# ...
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# The above code will generate the following error
|
17
|
+
# Dust::DefinitionError: setup is not allowed on class Units::[TestClassName]
|
2
18
|
class DefinitionError < StandardError
|
3
19
|
end
|
4
20
|
end
|
data/lib/dust.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/object_extension')
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/array_extension')
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/nil_extension')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/string_extension')
|
4
5
|
require File.expand_path(File.dirname(__FILE__) + '/symbol_extension')
|
5
6
|
require File.expand_path(File.dirname(__FILE__) + '/test_case_extension')
|
6
7
|
require File.expand_path(File.dirname(__FILE__) + '/definition_error')
|
data/lib/nil_extension.rb
CHANGED
data/lib/object_extension.rb
CHANGED
@@ -1,31 +1,57 @@
|
|
1
1
|
class Object
|
2
|
+
# call-seq: unit_tests(options={}, &block)
|
3
|
+
#
|
4
|
+
# Used to define a block of unit tests.
|
5
|
+
#
|
6
|
+
# unit_tests do
|
7
|
+
# test "verify something" do
|
8
|
+
# ...
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# Configuration Options:
|
13
|
+
# * allow - Allows you to specify the methods that are allowed despite being disallowed.
|
14
|
+
# See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info
|
2
15
|
def unit_tests(options={}, &block)
|
3
16
|
do_tests("Units", options, &block)
|
4
17
|
end
|
5
18
|
|
19
|
+
# call-seq: unit_tests(options={}, &block)
|
20
|
+
#
|
21
|
+
# Used to define a block of functional tests.
|
22
|
+
#
|
23
|
+
# functional_tests do
|
24
|
+
# test "verify something" do
|
25
|
+
# ...
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# Configuration Options:
|
30
|
+
# * allow - Allows you to specify the methods that are allowed despite being disallowed.
|
31
|
+
# See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info
|
6
32
|
def functional_tests(options={}, &block)
|
7
33
|
do_tests("Functionals", options, &block)
|
8
34
|
end
|
9
35
|
|
10
|
-
|
11
|
-
def do_tests(type, options, &block)
|
36
|
+
protected
|
37
|
+
def do_tests(type, options, &block) #:nodoc:
|
12
38
|
options[:allow] = options[:allow].arrayize
|
13
39
|
full_path_file_name = eval "__FILE__", block.binding
|
14
40
|
test_name = File.basename(full_path_file_name, ".rb")
|
15
|
-
test_class = eval "module #{type}; class #{test_name.
|
41
|
+
test_class = eval "module #{type}; class #{test_name.to_class_name} < Test::Unit::TestCase; self; end; end"
|
16
42
|
test_class.class_eval &block
|
17
43
|
check_for_setup(test_class, options)
|
18
44
|
check_for_helpers(test_class, options)
|
19
45
|
end
|
20
46
|
|
21
|
-
def check_for_setup(test_class, options)
|
47
|
+
def check_for_setup(test_class, options) #:nodoc:
|
22
48
|
if test_class.instance_methods(false).include?("setup") && Test::Unit::TestCase.disallow_setup? &&
|
23
49
|
!options[:allow].include?(:setup)
|
24
50
|
raise Dust::DefinitionError.new("setup is not allowed on class #{test_class.name}")
|
25
51
|
end
|
26
52
|
end
|
27
53
|
|
28
|
-
def check_for_helpers(test_class, options)
|
54
|
+
def check_for_helpers(test_class, options) #:nodoc:
|
29
55
|
test_class.instance_methods(false).each do |method_name|
|
30
56
|
if method_name !~ /^test_/ && Test::Unit::TestCase.disallow_helpers? && !options[:allow].include?(method_name.to_sym)
|
31
57
|
p method_name.to_sym
|
data/lib/symbol_extension.rb
CHANGED
data/lib/test_case_extension.rb
CHANGED
@@ -1,25 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Test #:nodoc:
|
2
|
+
module Unit #:nodoc:
|
3
|
+
class TestCase
|
4
|
+
# call-seq: disallow_setup!
|
5
|
+
#
|
6
|
+
# Used to disallow setup methods in test specifications.
|
7
|
+
#
|
8
|
+
# Test::Unit::TestCase.disallow_setup!
|
9
|
+
#
|
10
|
+
# A test specification can override this behavior by passing :setup in the :allow options.
|
11
|
+
#
|
12
|
+
# unit_tests :allow => :setup do
|
13
|
+
# def setup
|
14
|
+
# ...
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# test "verify something" do
|
18
|
+
# ...
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
def self.disallow_setup!
|
22
|
+
@disallow_setup = true
|
23
|
+
end
|
5
24
|
|
6
|
-
|
7
|
-
|
8
|
-
|
25
|
+
def self.disallow_setup? #:nodoc:
|
26
|
+
@disallow_setup
|
27
|
+
end
|
9
28
|
|
10
|
-
|
11
|
-
|
12
|
-
|
29
|
+
# call-seq: disallow_helpers!
|
30
|
+
#
|
31
|
+
# Used to disallow helper methods in test specifications.
|
32
|
+
#
|
33
|
+
# Test::Unit::TestCase.disallow_helper!
|
34
|
+
#
|
35
|
+
# A test specification can override this behavior by passing the helper name (as a symbol) in the :allow options.
|
36
|
+
#
|
37
|
+
# unit_tests :allow => [:create_something, :destroy_something] do
|
38
|
+
# test "verify something" do
|
39
|
+
# ...
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# def create_something
|
43
|
+
# ...
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# def destroy_something
|
47
|
+
# ...
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
def self.disallow_helpers!
|
51
|
+
@disallow_helpers = true
|
52
|
+
end
|
13
53
|
|
14
|
-
|
15
|
-
|
16
|
-
|
54
|
+
def self.disallow_helpers? #:nodoc:
|
55
|
+
@disallow_helpers
|
56
|
+
end
|
17
57
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
58
|
+
# call-seq: test(name, &block)
|
59
|
+
#
|
60
|
+
# Used to define a test and assign it a descriptive name.
|
61
|
+
#
|
62
|
+
# unit_tests do
|
63
|
+
# test "verify something" do
|
64
|
+
# ...
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
def self.test(name, &block)
|
68
|
+
test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
|
69
|
+
raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s
|
70
|
+
define_method test_name do
|
71
|
+
instance_eval &block
|
72
|
+
end
|
73
|
+
end
|
23
74
|
end
|
24
75
|
end
|
25
76
|
end
|
data/rakefile.rb
CHANGED
@@ -28,7 +28,7 @@ Gem::manage_gems
|
|
28
28
|
specification = Gem::Specification.new do |s|
|
29
29
|
s.name = "dust"
|
30
30
|
s.summary = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax."
|
31
|
-
s.version = "0.1.
|
31
|
+
s.version = "0.1.4"
|
32
32
|
s.author = 'Jay Fields'
|
33
33
|
s.description = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax."
|
34
34
|
s.email = 'dust-developer@rubyforge.org'
|
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
end
|
11
11
|
raise "shouldn't be here"
|
12
12
|
rescue Dust::DefinitionError => ex
|
13
|
-
raise unless ex.message == "helper methods are not allowed on class Units::
|
13
|
+
raise unless ex.message == "helper methods are not allowed on class Units::FailingWithHelperUnitTest"
|
14
14
|
ensure
|
15
15
|
Test::Unit::TestCase.class_eval { @disallow_helpers = nil }
|
16
16
|
end
|
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
end
|
11
11
|
raise "shouldn't be here"
|
12
12
|
rescue Dust::DefinitionError => ex
|
13
|
-
raise unless ex.message == "setup is not allowed on class Units::
|
13
|
+
raise unless ex.message == "setup is not allowed on class Units::FailingWithSetupUnitTest"
|
14
14
|
ensure
|
15
15
|
Test::Unit::TestCase.class_eval { @disallow_setup = nil }
|
16
16
|
end
|
data/test/functional_test.rb
CHANGED
data/test/passing_unit_test.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: dust
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 0.1.4
|
7
|
+
date: 2007-08-17 00:00:00 -04:00
|
8
8
|
summary: Dust is an add on for Test::Unit that allows an alternative test definintion syntax.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/dust.rb
|
35
35
|
- lib/nil_extension.rb
|
36
36
|
- lib/object_extension.rb
|
37
|
+
- lib/string_extension.rb
|
37
38
|
- lib/symbol_extension.rb
|
38
39
|
- lib/test_case_extension.rb
|
39
40
|
- test/all_tests.rb
|