dust 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/array_extension.rb +5 -0
- data/lib/definition_error.rb +4 -0
- data/lib/dust.rb +6 -25
- data/lib/nil_extension.rb +5 -0
- data/lib/object_extension.rb +36 -0
- data/lib/symbol_extension.rb +5 -0
- data/lib/test_case_extension.rb +25 -0
- data/rakefile.rb +1 -1
- data/test/failing_with_helper_unit_test.rb +16 -0
- data/test/failing_with_setup_unit_test.rb +16 -0
- data/test/{unit_test.rb → passing_unit_test.rb} +0 -0
- data/test/passing_with_helper_unit_test.rb +10 -0
- data/test/passing_with_helpers_unit_test.rb +13 -0
- data/test/passing_with_setup_unit_test.rb +10 -0
- metadata +13 -2
data/lib/dust.rb
CHANGED
@@ -1,25 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def functional_tests(&block)
|
10
|
-
full_path_file_name = eval "__FILE__", block.binding
|
11
|
-
test_name = File.basename(full_path_file_name, ".rb")
|
12
|
-
test_class = eval "module Functionals; class #{test_name.capitalize} < Test::Unit::TestCase; self; end; end"
|
13
|
-
test_class.class_eval &block
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
def self.test(name, &block)
|
19
|
-
test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
|
20
|
-
raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s
|
21
|
-
define_method test_name do
|
22
|
-
instance_eval &block
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/object_extension')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/array_extension')
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/nil_extension')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/symbol_extension')
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_case_extension')
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/definition_error')
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Object
|
2
|
+
def unit_tests(options={}, &block)
|
3
|
+
do_tests("Units", options, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def functional_tests(options={}, &block)
|
7
|
+
do_tests("Functionals", options, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def do_tests(type, options, &block)
|
12
|
+
options[:allow] = options[:allow].arrayize
|
13
|
+
full_path_file_name = eval "__FILE__", block.binding
|
14
|
+
test_name = File.basename(full_path_file_name, ".rb")
|
15
|
+
test_class = eval "module #{type}; class #{test_name.capitalize} < Test::Unit::TestCase; self; end; end"
|
16
|
+
test_class.class_eval &block
|
17
|
+
check_for_setup(test_class, options)
|
18
|
+
check_for_helpers(test_class, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_for_setup(test_class, options)
|
22
|
+
if test_class.instance_methods(false).include?("setup") && Test::Unit::TestCase.disallow_setup? &&
|
23
|
+
!options[:allow].include?(:setup)
|
24
|
+
raise Dust::DefinitionError.new("setup is not allowed on class #{test_class.name}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_for_helpers(test_class, options)
|
29
|
+
test_class.instance_methods(false).each do |method_name|
|
30
|
+
if method_name !~ /^test_/ && Test::Unit::TestCase.disallow_helpers? && !options[:allow].include?(method_name.to_sym)
|
31
|
+
p method_name.to_sym
|
32
|
+
raise Dust::DefinitionError.new("helper methods are not allowed on class #{test_class.name}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Test::Unit::TestCase
|
2
|
+
def self.disallow_setup!
|
3
|
+
@disallow_setup = true
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.disallow_setup?
|
7
|
+
@disallow_setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.disallow_helpers!
|
11
|
+
@disallow_helpers = true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.disallow_helpers?
|
15
|
+
@disallow_helpers
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.test(name, &block)
|
19
|
+
test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
|
20
|
+
raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s
|
21
|
+
define_method test_name do
|
22
|
+
instance_eval &block
|
23
|
+
end
|
24
|
+
end
|
25
|
+
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.2"
|
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'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
begin
|
4
|
+
unit_tests do
|
5
|
+
Test::Unit::TestCase.disallow_helpers!
|
6
|
+
def helper_method
|
7
|
+
end
|
8
|
+
|
9
|
+
test("true"){}
|
10
|
+
end
|
11
|
+
raise "shouldn't be here"
|
12
|
+
rescue Dust::DefinitionError => ex
|
13
|
+
raise unless ex.message == "helper methods are not allowed on class Units::Failing_with_helper_unit_test"
|
14
|
+
ensure
|
15
|
+
Test::Unit::TestCase.class_eval { @disallow_helpers = nil }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
begin
|
4
|
+
unit_tests do
|
5
|
+
Test::Unit::TestCase.disallow_setup!
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
test("true"){}
|
10
|
+
end
|
11
|
+
raise "shouldn't be here"
|
12
|
+
rescue Dust::DefinitionError => ex
|
13
|
+
raise unless ex.message == "setup is not allowed on class Units::Failing_with_setup_unit_test"
|
14
|
+
ensure
|
15
|
+
Test::Unit::TestCase.class_eval { @disallow_setup = nil }
|
16
|
+
end
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
Test::Unit::TestCase.disallow_helpers!
|
4
|
+
unit_tests :allow => [:helper, :helper2] do
|
5
|
+
def helper
|
6
|
+
end
|
7
|
+
|
8
|
+
def helper2
|
9
|
+
end
|
10
|
+
|
11
|
+
test("true"){}
|
12
|
+
end
|
13
|
+
Test::Unit::TestCase.class_eval { @disallow_helpers = nil }
|
metadata
CHANGED
@@ -3,7 +3,7 @@ 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.
|
6
|
+
version: 0.1.2
|
7
7
|
date: 2007-08-14 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:
|
@@ -29,11 +29,22 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Jay Fields
|
31
31
|
files:
|
32
|
+
- lib/array_extension.rb
|
33
|
+
- lib/definition_error.rb
|
32
34
|
- lib/dust.rb
|
35
|
+
- lib/nil_extension.rb
|
36
|
+
- lib/object_extension.rb
|
37
|
+
- lib/symbol_extension.rb
|
38
|
+
- lib/test_case_extension.rb
|
33
39
|
- test/all_tests.rb
|
40
|
+
- test/failing_with_helper_unit_test.rb
|
41
|
+
- test/failing_with_setup_unit_test.rb
|
34
42
|
- test/functional_test.rb
|
43
|
+
- test/passing_unit_test.rb
|
44
|
+
- test/passing_with_helper_unit_test.rb
|
45
|
+
- test/passing_with_helpers_unit_test.rb
|
46
|
+
- test/passing_with_setup_unit_test.rb
|
35
47
|
- test/test_helper.rb
|
36
|
-
- test/unit_test.rb
|
37
48
|
- rakefile.rb
|
38
49
|
- README
|
39
50
|
test_files:
|