rake_tasks 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +5 -2
- data/README +31 -4
- data/lib/rake_tasks/doc.rb +7 -52
- data/lib/rake_tasks/gem.rb +7 -29
- data/lib/rake_tasks/lib/doc.rb +152 -0
- data/lib/rake_tasks/lib/gem.rb +97 -0
- data/lib/rake_tasks/lib/tests.rb +143 -0
- data/lib/rake_tasks/test.rb +11 -20
- data/lib/rake_tasks.rb +11 -7
- data/license/{gpl → gplv3} +0 -0
- data/license/{lgpl → lgplv3} +0 -0
- data/license/{lgplv3-88x31.png → lgplv3.png} +0 -0
- data/rake_tasks.gemspec +3 -1
- data/test/integration/doc_integration_test.rb +79 -0
- data/test/integration/gem_integration_test.rb +74 -0
- data/test/integration/tests_integration_test.rb +79 -0
- data/test/require.rb +5 -0
- data/test/unit/doc_unit_test.rb +145 -0
- data/test/unit/gem_unit_test.rb +276 -0
- data/test/unit/tests_unit_test.rb +125 -0
- metadata +41 -10
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rake_tasks (
|
4
|
+
rake_tasks (2.0.0)
|
5
5
|
rake (~> 0.9.2)
|
6
6
|
rdoc (~> 3.9.4)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
+
metaclass (0.0.1)
|
12
|
+
mocha (0.10.0)
|
13
|
+
metaclass (~> 0.0.1)
|
11
14
|
rake (0.9.2)
|
12
15
|
rdoc (3.9.4)
|
13
16
|
|
14
17
|
PLATFORMS
|
15
18
|
ruby
|
16
|
-
x86-mingw32
|
17
19
|
|
18
20
|
DEPENDENCIES
|
21
|
+
mocha (~> 0.10.0)
|
19
22
|
rake_tasks!
|
data/README
CHANGED
@@ -10,10 +10,37 @@ The following assumptions are currently made:
|
|
10
10
|
1. There is a valid .gemspec file in the root folder that is named the same
|
11
11
|
as the root folder.
|
12
12
|
|
13
|
-
2. Tests reside in a folder named 'test'
|
13
|
+
2. Tests reside in a folder named either 'test' or 'tests'
|
14
|
+
and test files are named *_test.rb or test_*.rb.
|
15
|
+
|
16
|
+
Additionally, if you have sub-folders under test(s)
|
17
|
+
(i.e. test/unit, test/performance), they will be available
|
18
|
+
using rake test:unit and rake test:performance.
|
19
|
+
Sub-folders that do not contain files matching the test file name patterns
|
20
|
+
will not be included in this set.
|
21
|
+
|
22
|
+
You may run a single test from any test file by using the following:
|
23
|
+
|
24
|
+
rake test:test_file[test_method]
|
25
|
+
|
26
|
+
test_file is the name of the test file without the pattern,
|
27
|
+
so if you have a test named my_class_test.rb with a test method
|
28
|
+
named my_test_method, it would be invoked by:
|
29
|
+
|
30
|
+
rake test:my_class[my_test_method]
|
14
31
|
|
15
32
|
3. Additional rake tasks are named *.rb and reside in a folder named 'tasks'.
|
16
33
|
|
34
|
+
4. README generation is more intelligent about licensing information.
|
35
|
+
If nothing else is available, RakeTasks will use the gemspec information
|
36
|
+
to populate the license information. If a license folder exists, RakeTasks
|
37
|
+
will look for files that match the license name and include links
|
38
|
+
to both licenses and images in the README.
|
39
|
+
|
40
|
+
If a README does not exist, one will be created.
|
41
|
+
If a README does exist, a README_GENERATED file will be created,
|
42
|
+
so as not to overwrite a 'real' README file.
|
43
|
+
|
17
44
|
The default task will be set in the following order:
|
18
45
|
|
19
46
|
1. If tests are found, rake will run test:all.
|
@@ -31,7 +58,7 @@ The default task will be set in the following order:
|
|
31
58
|
|
32
59
|
2. Require the gem in your Gemfile:
|
33
60
|
|
34
|
-
gem 'rake_tasks', '~> 0.0
|
61
|
+
gem 'rake_tasks', '~> 2.0.0'
|
35
62
|
|
36
63
|
3. Require the gem wherever you need to use it:
|
37
64
|
|
@@ -43,6 +70,6 @@ The default task will be set in the following order:
|
|
43
70
|
|
44
71
|
== License
|
45
72
|
|
46
|
-
RakeTasks is released under the {LGPLv3 license}[link:../../license/
|
73
|
+
RakeTasks is released under the {LGPLv3 license}[link:../../license/lgplv3].
|
47
74
|
|
48
|
-
link:../../license/lgplv3
|
75
|
+
link:../../license/lgplv3.png
|
data/lib/rake_tasks/doc.rb
CHANGED
@@ -28,59 +28,22 @@
|
|
28
28
|
################################################################################
|
29
29
|
#++
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
if File.file?(gem_spec_file)
|
31
|
+
if RakeTasks::Gem.gem_file?
|
34
32
|
############################################################################
|
35
33
|
namespace :doc do
|
36
34
|
############################################################################
|
37
35
|
|
38
|
-
|
36
|
+
gem_spec_file = RakeTasks::Gem.gem_spec_file
|
37
|
+
gem_spec = RakeTasks::Gem.gem_spec
|
39
38
|
|
40
|
-
readme = '
|
39
|
+
readme = 'README'
|
40
|
+
readme = 'README_GENERATED' if File.file?(readme)
|
41
41
|
|
42
42
|
file readme => gem_spec_file do |t|
|
43
|
-
|
44
|
-
header = '=='
|
45
|
-
|
46
|
-
content =<<-EOD
|
47
|
-
#{header} Welcome to #{gem_title}
|
48
|
-
|
49
|
-
#{gem_spec.description}
|
50
|
-
|
51
|
-
#{header} Getting Started
|
52
|
-
|
53
|
-
1. Install #{gem_title} at the command prompt if you haven't yet:
|
54
|
-
|
55
|
-
gem install #{gem_spec.name}
|
56
|
-
|
57
|
-
2. Require the gem in your Gemfile:
|
58
|
-
|
59
|
-
gem '#{gem_spec.name}', '~> #{gem_spec.version}'
|
60
|
-
|
61
|
-
3. Require the gem wherever you need to use it:
|
62
|
-
|
63
|
-
require '#{gem_spec.name}'
|
64
|
-
|
65
|
-
#{header} Usage
|
66
|
-
|
67
|
-
TODO
|
68
|
-
|
69
|
-
#{header} Additional Notes
|
70
|
-
|
71
|
-
TODO
|
72
|
-
|
73
|
-
#{header} Additional Documentation
|
74
|
-
|
75
|
-
rake rdoc:app
|
76
|
-
|
77
|
-
#{header} License
|
78
|
-
|
79
|
-
#{gem_title} is released under the #{gem_spec.license} license.
|
80
|
-
EOD
|
43
|
+
doc_obj = RakeTasks::Doc.new
|
81
44
|
|
82
45
|
File.open(readme, 'w') do |file|
|
83
|
-
file.puts
|
46
|
+
file.puts doc_obj.readme_contents
|
84
47
|
end
|
85
48
|
end
|
86
49
|
|
@@ -92,14 +55,6 @@ EOD
|
|
92
55
|
rm_f readme
|
93
56
|
end
|
94
57
|
|
95
|
-
def camelize(word)
|
96
|
-
result = ''
|
97
|
-
word.split('_').each do |section|
|
98
|
-
result += section.capitalize
|
99
|
-
end
|
100
|
-
return result
|
101
|
-
end
|
102
|
-
|
103
58
|
############################################################################
|
104
59
|
end # :doc
|
105
60
|
############################################################################
|
data/lib/rake_tasks/gem.rb
CHANGED
@@ -28,14 +28,13 @@
|
|
28
28
|
################################################################################
|
29
29
|
#++
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
if File.file?(gem_spec_file)
|
31
|
+
if RakeTasks::Gem.gem_file?
|
34
32
|
############################################################################
|
35
33
|
namespace :gem do
|
36
34
|
############################################################################
|
37
35
|
|
38
|
-
gem_spec = Gem
|
36
|
+
gem_spec = RakeTasks::Gem.gem_spec
|
37
|
+
gem_spec_file = RakeTasks::Gem.gem_spec_file
|
39
38
|
|
40
39
|
file gem_spec.file_name =>
|
41
40
|
[gem_spec_file, *Dir['lib/**/*.rb'], 'Gemfile', 'Gemfile.lock'] do |t|
|
@@ -61,32 +60,11 @@ if File.file?(gem_spec_file)
|
|
61
60
|
desc "Show/Set the version number."
|
62
61
|
task :version, [:number] do |t, args|
|
63
62
|
if args[:number].nil?
|
64
|
-
puts
|
63
|
+
puts RakeTasks::Gem.version(gem_spec)
|
65
64
|
else
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
File.open(gem_spec_file, 'r') do |file|
|
70
|
-
while line = file.gets
|
71
|
-
if line =~ /version *= *['"]#{gem_spec.version}['"]/
|
72
|
-
temp_file.puts line.sub(
|
73
|
-
/['"]#{gem_spec.version}['"]/, "'#{args[:number]}'")
|
74
|
-
else
|
75
|
-
temp_file.puts line
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
temp_file.flush
|
81
|
-
|
82
|
-
mv temp_file.path, gem_spec_file
|
83
|
-
|
84
|
-
rescue Exception => ex
|
85
|
-
raise ex
|
86
|
-
ensure
|
87
|
-
temp_file.close
|
88
|
-
temp_file.unlink
|
89
|
-
end
|
65
|
+
RakeTasks::Gem.version! args[:number], gem_spec
|
66
|
+
gem_spec = RakeTasks::Gem.gem_spec
|
67
|
+
puts RakeTasks::Gem.version(gem_spec)
|
90
68
|
end
|
91
69
|
end
|
92
70
|
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# This file holds the class that handles documentation utilities.
|
2
|
+
|
3
|
+
#--
|
4
|
+
################################################################################
|
5
|
+
# Copyright (C) 2011 Travis Herrick #
|
6
|
+
################################################################################
|
7
|
+
# #
|
8
|
+
# \v^V,^!v\^/ #
|
9
|
+
# ~% %~ #
|
10
|
+
# { _ _ } #
|
11
|
+
# ( * - ) #
|
12
|
+
# | / | #
|
13
|
+
# \ _, / #
|
14
|
+
# \__.__/ #
|
15
|
+
# #
|
16
|
+
################################################################################
|
17
|
+
# This program is free software: you can redistribute it #
|
18
|
+
# and/or modify it under the terms of the GNU Lesser General Public License #
|
19
|
+
# as published by the Free Software Foundation, #
|
20
|
+
# either version 3 of the License, or (at your option) any later version. #
|
21
|
+
################################################################################
|
22
|
+
# This program is distributed in the hope that it will be useful, #
|
23
|
+
# but WITHOUT ANY WARRANTY; #
|
24
|
+
# without even the implied warranty of MERCHANTABILITY #
|
25
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. #
|
26
|
+
# See the GNU Lesser General Public License for more details. #
|
27
|
+
# #
|
28
|
+
# You should have received a copy of the GNU Lesser General Public License #
|
29
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
30
|
+
################################################################################
|
31
|
+
#++
|
32
|
+
|
33
|
+
# The main module for this gem.
|
34
|
+
module RakeTasks
|
35
|
+
# This class will handle documentation utilities.
|
36
|
+
class Doc
|
37
|
+
# Constructor.
|
38
|
+
def initialize(gem_info = RakeTasks::Gem)
|
39
|
+
@gem_spec = gem_info.gem_spec
|
40
|
+
@gem_title = gem_info.gem_title(@gem_spec)
|
41
|
+
@license_path = 'license'
|
42
|
+
@contents = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# The default contents for a readme file.
|
46
|
+
def readme_contents
|
47
|
+
gem_title = @gem_title
|
48
|
+
gem_spec = @gem_spec
|
49
|
+
|
50
|
+
@contents ||= %Q{
|
51
|
+
#{header} Welcome to #{gem_title}
|
52
|
+
|
53
|
+
#{gem_spec.description}
|
54
|
+
|
55
|
+
#{header} Getting Started
|
56
|
+
|
57
|
+
1. Install #{gem_title} at the command prompt if you haven't yet:
|
58
|
+
|
59
|
+
gem install #{gem_spec.name}
|
60
|
+
|
61
|
+
2. Require the gem in your Gemfile:
|
62
|
+
|
63
|
+
gem '#{gem_spec.name}', '~> #{gem_spec.version}'
|
64
|
+
|
65
|
+
3. Require the gem wherever you need to use it:
|
66
|
+
|
67
|
+
require '#{gem_spec.name}'
|
68
|
+
|
69
|
+
#{header} Usage
|
70
|
+
|
71
|
+
TODO
|
72
|
+
|
73
|
+
#{header} Additional Notes
|
74
|
+
|
75
|
+
TODO
|
76
|
+
|
77
|
+
#{header} Additional Documentation
|
78
|
+
|
79
|
+
rake rdoc:app
|
80
|
+
#{license_details}}.strip
|
81
|
+
|
82
|
+
return @contents
|
83
|
+
end
|
84
|
+
|
85
|
+
########################################################################
|
86
|
+
private
|
87
|
+
########################################################################
|
88
|
+
|
89
|
+
# Header indicator.
|
90
|
+
def header
|
91
|
+
'=='
|
92
|
+
end
|
93
|
+
|
94
|
+
# Compose the license details.
|
95
|
+
# This will include links to the license and image,
|
96
|
+
# if they exist in the license folder.
|
97
|
+
def license_details
|
98
|
+
return if @gem_spec.licenses.empty?
|
99
|
+
|
100
|
+
# Set up the header (and other info. that will be the same regardless).
|
101
|
+
out = ''
|
102
|
+
out += "\n#{header} License\n\n"
|
103
|
+
out += "#{@gem_title} is released under the "
|
104
|
+
|
105
|
+
# Get image files.
|
106
|
+
images = Dir[
|
107
|
+
File.join(@license_path, '*.png'),
|
108
|
+
File.join(@license_path, '*.jpg'),
|
109
|
+
File.join(@license_path, '*.jpeg'),
|
110
|
+
File.join(@license_path, '*.gif')
|
111
|
+
]
|
112
|
+
|
113
|
+
# Get license files (by removing images from all files).
|
114
|
+
files = Dir[File.join(@license_path, '*')] - images
|
115
|
+
|
116
|
+
# Find the license file that matches the license.
|
117
|
+
found = nil
|
118
|
+
files.each do |file|
|
119
|
+
next unless File.file?(file)
|
120
|
+
if @gem_spec.license.downcase == File.basename(file).downcase
|
121
|
+
found = file
|
122
|
+
break
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Add the link to the license file.
|
127
|
+
if found
|
128
|
+
out += "{#{@gem_spec.license} license}[link:../../#{found}].\n"
|
129
|
+
else
|
130
|
+
out += "#{@gem_spec.license} license.\n"
|
131
|
+
end
|
132
|
+
|
133
|
+
# Find the image file that matches the license.
|
134
|
+
found = nil
|
135
|
+
images.each do |file|
|
136
|
+
next unless File.file?(file)
|
137
|
+
if @gem_spec.license.downcase ==
|
138
|
+
File.basename(file).sub(/\..+?$/, '').downcase
|
139
|
+
found = file
|
140
|
+
break
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Add the link to the image file.
|
145
|
+
if found
|
146
|
+
out += "\nlink:../../#{found}"
|
147
|
+
end
|
148
|
+
|
149
|
+
return out
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# This file holds the class that handles gem utilities.
|
2
|
+
|
3
|
+
#--
|
4
|
+
################################################################################
|
5
|
+
# Copyright (C) 2011 Travis Herrick #
|
6
|
+
################################################################################
|
7
|
+
# #
|
8
|
+
# \v^V,^!v\^/ #
|
9
|
+
# ~% %~ #
|
10
|
+
# { _ _ } #
|
11
|
+
# ( * - ) #
|
12
|
+
# | / | #
|
13
|
+
# \ _, / #
|
14
|
+
# \__.__/ #
|
15
|
+
# #
|
16
|
+
################################################################################
|
17
|
+
# This program is free software: you can redistribute it #
|
18
|
+
# and/or modify it under the terms of the GNU Lesser General Public License #
|
19
|
+
# as published by the Free Software Foundation, #
|
20
|
+
# either version 3 of the License, or (at your option) any later version. #
|
21
|
+
################################################################################
|
22
|
+
# This program is distributed in the hope that it will be useful, #
|
23
|
+
# but WITHOUT ANY WARRANTY; #
|
24
|
+
# without even the implied warranty of MERCHANTABILITY #
|
25
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. #
|
26
|
+
# See the GNU Lesser General Public License for more details. #
|
27
|
+
# #
|
28
|
+
# You should have received a copy of the GNU Lesser General Public License #
|
29
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
30
|
+
################################################################################
|
31
|
+
#++
|
32
|
+
|
33
|
+
# The main module for this gem.
|
34
|
+
module RakeTasks
|
35
|
+
# This class will handle gem utilities.
|
36
|
+
class Gem
|
37
|
+
class << self
|
38
|
+
# Check whether a gem spec file exists for this project.
|
39
|
+
def gem_file?
|
40
|
+
return !gem_spec_file.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the gem title.
|
44
|
+
# This is the gem name with underscores removed.
|
45
|
+
# Wherever an underscore is removed, the next letter is capitalized.
|
46
|
+
def gem_title(spec = gem_spec)
|
47
|
+
return nil unless spec.respond_to?(:name)
|
48
|
+
spec.name.split('_').map { |w| w.capitalize }.join('')
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get the gem specification.
|
52
|
+
def gem_spec(spec = Kernel.const_get('Gem').const_get('Specification'))
|
53
|
+
spec.load(gem_spec_file) if gem_file?
|
54
|
+
end
|
55
|
+
|
56
|
+
# Check for a gem spec file.
|
57
|
+
def gem_spec_file
|
58
|
+
file = File.basename(Dir.getwd) + '.gemspec'
|
59
|
+
return nil unless File.file? file
|
60
|
+
return file
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the name and version from the specified gem specification.
|
64
|
+
def version(spec = gem_spec)
|
65
|
+
if spec.respond_to?(:name) && spec.respond_to?(:version)
|
66
|
+
"#{spec.name} version #{spec.version}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Updates the version in the gem specification file.
|
71
|
+
def version!(value, spec = gem_spec, temp = Tempfile.new('temp_gem_spec'))
|
72
|
+
return if spec.nil?
|
73
|
+
|
74
|
+
begin
|
75
|
+
file = File.open(gem_spec_file, 'r')
|
76
|
+
|
77
|
+
while line = file.gets
|
78
|
+
if line =~ /version *= *['"]#{spec.version}['"]/
|
79
|
+
temp.puts line.sub(/(['"])#{spec.version}(['"])/, "\\1#{value}\\2")
|
80
|
+
else
|
81
|
+
temp.puts line
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
temp.flush
|
86
|
+
|
87
|
+
FileUtils.mv temp.path, gem_spec_file
|
88
|
+
rescue Exception => ex
|
89
|
+
raise ex
|
90
|
+
ensure
|
91
|
+
temp.close
|
92
|
+
temp.unlink
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# This file contains the class that assists in setting up test tasks.
|
2
|
+
|
3
|
+
#--
|
4
|
+
################################################################################
|
5
|
+
# Copyright (C) 2011 Travis Herrick #
|
6
|
+
################################################################################
|
7
|
+
# #
|
8
|
+
# \v^V,^!v\^/ #
|
9
|
+
# ~% %~ #
|
10
|
+
# { _ _ } #
|
11
|
+
# ( * - ) #
|
12
|
+
# | / | #
|
13
|
+
# \ _, / #
|
14
|
+
# \__.__/ #
|
15
|
+
# #
|
16
|
+
################################################################################
|
17
|
+
# This program is free software: you can redistribute it #
|
18
|
+
# and/or modify it under the terms of the GNU Lesser General Public License #
|
19
|
+
# as published by the Free Software Foundation, #
|
20
|
+
# either version 3 of the License, or (at your option) any later version. #
|
21
|
+
################################################################################
|
22
|
+
# This program is distributed in the hope that it will be useful, #
|
23
|
+
# but WITHOUT ANY WARRANTY; #
|
24
|
+
# without even the implied warranty of MERCHANTABILITY #
|
25
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. #
|
26
|
+
# See the GNU Lesser General Public License for more details. #
|
27
|
+
# #
|
28
|
+
# You should have received a copy of the GNU Lesser General Public License #
|
29
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
30
|
+
################################################################################
|
31
|
+
#++
|
32
|
+
|
33
|
+
# The main module for this gem.
|
34
|
+
module RakeTasks
|
35
|
+
# This class assists in setting up test tasks.
|
36
|
+
class Tests
|
37
|
+
class << self
|
38
|
+
# Indicates that tests exist.
|
39
|
+
def exist?
|
40
|
+
return !Dir[File.join(root, '**')].empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns an array of test files for the specified group.
|
44
|
+
def file_list(group = :all)
|
45
|
+
group = group.to_sym unless group.is_a?(Symbol)
|
46
|
+
|
47
|
+
list = []
|
48
|
+
|
49
|
+
paths(group).each do |path|
|
50
|
+
patterns.each do |pattern|
|
51
|
+
files = Dir[File.join(path, pattern)]
|
52
|
+
list << files unless files.empty?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
return list.flatten
|
57
|
+
end
|
58
|
+
|
59
|
+
# Convert a path to a file into an appropriate task name.
|
60
|
+
# This is done by removing the pattern that is used to indicate
|
61
|
+
# it is a test file.
|
62
|
+
def task_name(file_path)
|
63
|
+
file = File.basename(file_path, '.rb')
|
64
|
+
|
65
|
+
patterns.each do |pattern|
|
66
|
+
pattern = pattern.sub(/\.rb$/, '').sub(/\*/, '.+?')
|
67
|
+
|
68
|
+
if file =~ /#{pattern}/
|
69
|
+
pattern = pattern.sub(/\.\+\?/, '')
|
70
|
+
|
71
|
+
if pattern.index('_') == 0
|
72
|
+
return file.sub(/#{pattern}$/, '')
|
73
|
+
else
|
74
|
+
return file.sub(/^#{pattern}/, '')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Return an array containing the types of tests that are included.
|
82
|
+
def types
|
83
|
+
types = []
|
84
|
+
|
85
|
+
Dir[File.join(root, '**')].each do |path|
|
86
|
+
next if !File.directory?(path)
|
87
|
+
|
88
|
+
patterns.each do |pattern|
|
89
|
+
next if types.include?(File.basename(path))
|
90
|
+
types << File.basename(path) unless Dir[File.join(path, pattern)].empty?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
return types
|
95
|
+
end
|
96
|
+
|
97
|
+
####################################################################
|
98
|
+
private
|
99
|
+
####################################################################
|
100
|
+
|
101
|
+
# The patterns that indicate that a file contains tests.
|
102
|
+
def patterns
|
103
|
+
[
|
104
|
+
'*_test.rb',
|
105
|
+
'test_*.rb',
|
106
|
+
]
|
107
|
+
end
|
108
|
+
|
109
|
+
# Paths to check for test files.
|
110
|
+
# Only paths for a specified type will be returned, if specified.
|
111
|
+
def paths(group = :all)
|
112
|
+
paths = []
|
113
|
+
|
114
|
+
paths << [root] if group == :all
|
115
|
+
|
116
|
+
types.each do |type|
|
117
|
+
if group == type.to_sym || group == :all
|
118
|
+
paths << File.join(root, type)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
return paths
|
123
|
+
end
|
124
|
+
|
125
|
+
# The root test folder.
|
126
|
+
def root
|
127
|
+
roots.each do |r|
|
128
|
+
unless Dir[r].empty?
|
129
|
+
return r
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Returns an array of potential root folder names.
|
135
|
+
def roots
|
136
|
+
[
|
137
|
+
'test',
|
138
|
+
'tests'
|
139
|
+
]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/lib/rake_tasks/test.rb
CHANGED
@@ -28,41 +28,32 @@
|
|
28
28
|
################################################################################
|
29
29
|
#++
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
if File.directory?(test_dir)
|
31
|
+
if RakeTasks::Tests.exist?
|
34
32
|
############################################################################
|
35
33
|
namespace :test do
|
36
34
|
############################################################################
|
37
35
|
# Add a task to run all tests.
|
38
36
|
Rake::TestTask.new('all') do |task|
|
39
|
-
task.
|
37
|
+
task.test_files = RakeTasks::Tests.file_list
|
40
38
|
task.verbose = true
|
41
39
|
task.warning = true
|
42
40
|
end
|
43
41
|
Rake::Task[:all].comment = 'Run all tests'
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# Get the name to use for the task by removing '_test.rb' from the name.
|
50
|
-
task_name = File.basename(item, '.rb').gsub(/_test$/, '')
|
51
|
-
|
52
|
-
# Add each test.
|
53
|
-
Rake::TestTask.new(task_name) do |task|
|
54
|
-
task.pattern = item
|
43
|
+
# Add tasks for each type of test (unit, integration, performance, etc.).
|
44
|
+
RakeTasks::Tests.types.each do |type|
|
45
|
+
Rake::TestTask.new(type) do |task|
|
46
|
+
task.test_files = RakeTasks::Tests.file_list(type)
|
55
47
|
task.verbose = true
|
56
48
|
task.warning = true
|
57
49
|
end
|
50
|
+
Rake::Task[type].comment = "Run #{type} tests"
|
58
51
|
end
|
59
52
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
task :method, [:method_name] do |t, args|
|
65
|
-
puts `ruby ./#{test_dir}/#{file_name} --name #{args[:method_name]}`
|
53
|
+
# Add a way to call a specific method in a given file.
|
54
|
+
RakeTasks::Tests.file_list.each do |file_path|
|
55
|
+
task RakeTasks::Tests.task_name(file_path), [:method_name] do |t, args|
|
56
|
+
puts `ruby ./#{file_path} --name #{args[:method_name]}`
|
66
57
|
end
|
67
58
|
end
|
68
59
|
############################################################################
|