rake_tasks 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ source "http://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem 'mocha', '~> 0.10.0'
7
- end
6
+ gem 'mocha' , '~> 0.10.0'
7
+ gem 'fakefs', '~> 0.4.0', :require => 'fakefs/safe'
8
+ end
data/Gemfile.lock CHANGED
@@ -1,22 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_tasks (2.0.0)
5
- rake (~> 0.9.2)
6
- rdoc (~> 3.9.4)
4
+ rake_tasks (2.0.1)
7
5
 
8
6
  GEM
9
7
  remote: http://rubygems.org/
10
8
  specs:
9
+ fakefs (0.4.0)
11
10
  metaclass (0.0.1)
12
11
  mocha (0.10.0)
13
12
  metaclass (~> 0.0.1)
14
- rake (0.9.2)
15
- rdoc (3.9.4)
16
13
 
17
14
  PLATFORMS
18
15
  ruby
19
16
 
20
17
  DEPENDENCIES
18
+ fakefs (~> 0.4.0)
21
19
  mocha (~> 0.10.0)
22
20
  rake_tasks!
data/README CHANGED
@@ -58,12 +58,26 @@ The default task will be set in the following order:
58
58
 
59
59
  2. Require the gem in your Gemfile:
60
60
 
61
- gem 'rake_tasks', '~> 2.0.0'
61
+ gem 'rake_tasks', '~> 2.0.1'
62
62
 
63
63
  3. Require the gem wherever you need to use it:
64
64
 
65
65
  require 'rake_tasks'
66
66
 
67
+ == Updates
68
+
69
+ 2.0.1 Added test:full task (requires rvm).
70
+
71
+ test:full allows a user to run tests against multiple ruby/gemset/rake
72
+ configurations by specifying them in a yaml file in the test folder.
73
+
74
+ A common rubies.yml file might look something like this:
75
+
76
+ - ruby: 1.9.2
77
+ gemset: my_gem_test
78
+ - ruby: 1.9.3
79
+ gemset: my_gem_test
80
+
67
81
  == Additional Documentation
68
82
 
69
83
  rake rdoc:app
@@ -34,7 +34,6 @@ if RakeTasks::Gem.gem_file?
34
34
  ############################################################################
35
35
 
36
36
  gem_spec_file = RakeTasks::Gem.gem_spec_file
37
- gem_spec = RakeTasks::Gem.gem_spec
38
37
 
39
38
  readme = 'README'
40
39
  readme = 'README_GENERATED' if File.file?(readme)
@@ -0,0 +1,75 @@
1
+ # This file holds the class that handles parsing output from files
2
+ # while testing across rubies/gemsets.
3
+
4
+ #--
5
+ ################################################################################
6
+ # Copyright (C) 2011 Travis Herrick #
7
+ ################################################################################
8
+ # #
9
+ # \v^V,^!v\^/ #
10
+ # ~% %~ #
11
+ # { _ _ } #
12
+ # ( * - ) #
13
+ # | / | #
14
+ # \ _, / #
15
+ # \__.__/ #
16
+ # #
17
+ ################################################################################
18
+ # This program is free software: you can redistribute it #
19
+ # and/or modify it under the terms of the GNU Lesser General Public License #
20
+ # as published by the Free Software Foundation, #
21
+ # either version 3 of the License, or (at your option) any later version. #
22
+ ################################################################################
23
+ # This program is distributed in the hope that it will be useful, #
24
+ # but WITHOUT ANY WARRANTY; #
25
+ # without even the implied warranty of MERCHANTABILITY #
26
+ # or FITNESS FOR A PARTICULAR PURPOSE. #
27
+ # See the GNU Lesser General Public License for more details. #
28
+ # #
29
+ # You should have received a copy of the GNU Lesser General Public License #
30
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
31
+ ################################################################################
32
+ #++
33
+
34
+ # The main module for this gem.
35
+ module RakeTasks
36
+ # This class will handle parsing duties.
37
+ class Parser
38
+ def initialize
39
+ @data = []
40
+ end
41
+
42
+ # Parse a given line.
43
+ # It will be sent to standard out if it meets appropriate criteria.
44
+ # Summary lines are split to provide sums of tests, assertions, etc.
45
+ def parse(line)
46
+ case line
47
+ when /^[\.EF]+$/, /^Using /, /^Finished (tests )?in \d+/
48
+ puts line.strip #unless line.strip.empty?
49
+ when /^\d+ tests, \d+ assertions, /
50
+ puts line.strip
51
+ @data << line.split(', ').map { |x| x.to_i }
52
+ end
53
+ end
54
+
55
+ # Calculate the summary and send it to standard out.
56
+ def summarize
57
+ tests = 0
58
+ assertions = 0
59
+ failures = 0
60
+ errors = 0
61
+ skips = 0
62
+
63
+ @data.each do |status|
64
+ tests = tests + status[0]
65
+ assertions = assertions + status[1]
66
+ failures = failures + status[2]
67
+ errors = errors + status[3]
68
+ skips = skips + status[4]
69
+ end
70
+
71
+ puts "%d tests, %d assertions, %d failures, %d errors, %d skips" % [
72
+ tests, assertions, failures, errors, skips]
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,12 @@
1
+ #!/bin/bash
2
+
3
+ if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
4
+ source "$HOME/.rvm/scripts/rvm"
5
+ elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
6
+ source "/usr/local/rvm/scripts/rvm"
7
+ else
8
+ printf "ERROR: An RVM installation was not found.\n"
9
+ fi
10
+
11
+ rvm use $2
12
+ rake $3 $1
@@ -37,7 +37,7 @@ module RakeTasks
37
37
  class << self
38
38
  # Indicates that tests exist.
39
39
  def exist?
40
- return !Dir[File.join(root, '**')].empty?
40
+ return !root.nil? && !file_list.empty?
41
41
  end
42
42
 
43
43
  # Returns an array of test files for the specified group.
@@ -94,18 +94,93 @@ module RakeTasks
94
94
  return types
95
95
  end
96
96
 
97
+ # Indicates whether tests can be run against multiple rubies.
98
+ def run_rubies?
99
+ File.file? rubies_yaml
100
+ end
101
+
102
+ # Runs tests against specified ruby/gemset/rake configurations.
103
+ def run_ruby_tests
104
+ parser = Parser.new
105
+
106
+ configs = test_configs
107
+
108
+ # Loop through the test configurations to initialize gemsets.
109
+ gem_rubies = []
110
+ configs.each do |config|
111
+ next if gem_rubies.include?(config[:ruby])
112
+ gem_rubies << config[:ruby]
113
+
114
+ cmd = ['bash', RakeTasks::SCRIPTS[:gemsets]]
115
+ cmd << config[:ruby].split('@')
116
+
117
+ pid = Process.spawn(*cmd.flatten)
118
+ Process.wait pid
119
+ end
120
+
121
+ # Loop through the test configurations.
122
+ configs.each do |config|
123
+ puts '*' * 80
124
+
125
+ if config[:rake]
126
+ puts "#{config[:ruby]} - #{config[:rake]}"
127
+ end
128
+
129
+ cmd = ['bash', RakeTasks::SCRIPTS[:rubies], 'test:all']
130
+ cmd << config[:ruby]
131
+ cmd << "_#{config[:rake]}_" if config[:rake]
132
+
133
+ # Run the tests.
134
+ pid = Process.spawn(*cmd, :out => 'out.log', :err => 'err.log')
135
+ Process.wait pid
136
+
137
+ File.open('out.log', 'r') do |file|
138
+ while line = file.gets
139
+ parser.parse line
140
+ end
141
+ end
142
+ end
143
+
144
+ FileUtils.rm 'out.log'
145
+ FileUtils.rm 'err.log'
146
+
147
+ puts '*' * 80
148
+ parser.summarize
149
+ end
150
+
151
+ # Returns a hash containing all testable rubies/gemsets.
152
+ # ==== Output
153
+ # [Hash] The configurations that will be tested.
154
+ def test_configs
155
+ configs = Psych.load(rubies_list)
156
+ return unless configs
157
+
158
+ # Loop through the configurations to set keys to symbols
159
+ # and add gemsets to rubies.
160
+ for i in 0..configs.length - 1 do
161
+ config = configs[i]
162
+
163
+ # Change keys to symbols (and remove the string-based pairs).
164
+ ['ruby', 'gemset', 'rake'].each do |key|
165
+ if config[key]
166
+ config[key.to_sym] = config[key]
167
+ config.delete(key)
168
+ end
169
+ end
170
+
171
+ # Add the '@' symbol to include gemsets.
172
+ config[:gemset] = '@' + config[:gemset] if config[:gemset]
173
+ config[:ruby] = config[:ruby].to_s + config[:gemset].to_s
174
+ config.delete(:gemset)
175
+ end
176
+
177
+ return configs.reject { |x| x[:ruby] and x[:ruby].strip.empty? }
178
+ end
179
+
97
180
  ####################################################################
98
181
  private
99
182
  ####################################################################
100
183
 
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
184
  # Paths to check for test files.
110
185
  # Only paths for a specified type will be returned, if specified.
111
186
  def paths(group = :all)
@@ -122,6 +197,14 @@ module RakeTasks
122
197
  return paths
123
198
  end
124
199
 
200
+ # The patterns that indicate that a file contains tests.
201
+ def patterns
202
+ [
203
+ '*_test.rb',
204
+ 'test_*.rb',
205
+ ]
206
+ end
207
+
125
208
  # The root test folder.
126
209
  def root
127
210
  roots.each do |r|
@@ -129,6 +212,7 @@ module RakeTasks
129
212
  return r
130
213
  end
131
214
  end
215
+ return
132
216
  end
133
217
 
134
218
  # Returns an array of potential root folder names.
@@ -138,6 +222,25 @@ module RakeTasks
138
222
  'tests'
139
223
  ]
140
224
  end
225
+
226
+ # Returns the contents of the rubies.yml file.
227
+ # ==== Output
228
+ # [String] The contents of the rubies yaml file.
229
+ def rubies_list
230
+ file = File.join(rubies_yaml)
231
+
232
+ # Read the yaml file.
233
+ # Psych must be available on the system,
234
+ # preferably via installing ruby with libyaml already installed.
235
+ File.open(file, 'r') do |f|
236
+ return f.read
237
+ end
238
+ end
239
+
240
+ # Returns the location of the rubies yaml file.
241
+ def rubies_yaml
242
+ File.join('.', root, 'rubies.yml')
243
+ end
141
244
  end
142
245
  end
143
246
  end
@@ -52,10 +52,18 @@ if RakeTasks::Tests.exist?
52
52
 
53
53
  # Add a way to call a specific method in a given file.
54
54
  RakeTasks::Tests.file_list.each do |file_path|
55
+ desc "Run individual tests in #{file_path}."
55
56
  task RakeTasks::Tests.task_name(file_path), [:method_name] do |t, args|
56
57
  puts `ruby ./#{file_path} --name #{args[:method_name]}`
57
58
  end
58
59
  end
60
+
61
+ if RakeTasks::Tests::run_rubies?
62
+ desc 'Runs tests against specified rubies and gemsets.'
63
+ task :full do |t|
64
+ RakeTasks::Tests::run_ruby_tests
65
+ end
66
+ end
59
67
  ############################################################################
60
68
  end # :test
61
69
  ############################################################################
data/lib/rake_tasks.rb CHANGED
@@ -28,15 +28,27 @@
28
28
  ################################################################################
29
29
  #++
30
30
 
31
- require 'rake'
32
31
  require 'rake/testtask'
33
32
  require 'rdoc/task'
34
33
  require 'rake/clean'
35
34
  require 'tempfile'
36
35
  require 'fileutils'
36
+ require 'psych'
37
+
38
+ module RakeTasks
39
+ # Contains the full path to the shell script to run tests in other env's.
40
+ SCRIPTS = {
41
+ :rubies => File.expand_path(File.join(
42
+ File.dirname(__FILE__), 'rake_tasks', 'lib', 'rubies.sh')),
43
+ :gemsets => File.expand_path(File.join(
44
+ File.dirname(__FILE__), 'rake_tasks', 'lib', 'bundle_install.sh')),
45
+ }
46
+ end
37
47
 
38
48
  gem_name = File.basename(__FILE__, '.rb')
39
49
 
50
+ task :default
51
+
40
52
  # Require lib files.
41
53
  Dir[File.join(File.dirname(__FILE__), gem_name, 'lib', '*.rb')].each do |lib|
42
54
  require lib
data/rake_tasks.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rake_tasks'
3
- s.version = '2.0.0'
3
+ s.version = '2.0.1'
4
4
 
5
5
  s.summary = 'Basic rake tasks. You know you want some.'
6
6
  s.description =%Q{
@@ -19,13 +19,11 @@ mmmm yummy
19
19
  s.extra_rdoc_files << 'README'
20
20
 
21
21
  s.require_paths = ['lib']
22
- s.files = Dir['*', 'lib/**/*.rb', 'license/*']
22
+ s.files = Dir['*', 'lib/**/*.rb', 'lib/**/rubies.sh', 'license/*']
23
23
  s.test_files = Dir['test/**/*.rb']
24
24
 
25
- s.add_dependency 'rdoc', '~> 3.9.4'
26
- s.add_dependency 'rake', '~> 0.9.2'
27
-
28
- s.add_development_dependency 'mocha', '~> 0.10.0'
25
+ s.add_development_dependency 'mocha' , '~> 0.10.0'
26
+ s.add_development_dependency 'fakefs', '~> 0.4.0'
29
27
 
30
28
  s.has_rdoc = true
31
29
  end
@@ -31,8 +31,21 @@
31
31
  require_relative File.join('../require'.split('/'))
32
32
 
33
33
  class TestsIntegrationTest < Test::Unit::TestCase
34
+ # Supported ruby versions.
35
+ def rubies
36
+ ['1.9.2-p290', '1.9.3-p0']
37
+ end
38
+ private :rubies
39
+
40
+ # Supported rake versions.
41
+ def rakes
42
+ ['0.8.7', '0.9.0', '0.9.1', '0.9.2', '0.9.2.2']
43
+ end
44
+ private :rakes
45
+
34
46
  def setup
35
- @class = RakeTasks::Tests
47
+ @module = RakeTasks
48
+ @class = @module::Tests
36
49
  @file_path = 'test'
37
50
  end
38
51
 
@@ -61,6 +74,24 @@ class TestsIntegrationTest < Test::Unit::TestCase
61
74
  check_file_list :integration
62
75
  end
63
76
 
77
+ def test_rubies
78
+ assert_equal configs, @class.test_configs
79
+ end
80
+
81
+ def test_rubies_shell_script_location_should_be_lib
82
+ loc = File.expand_path(File.join(
83
+ File.dirname(__FILE__), '../../lib/rake_tasks/lib/rubies.sh'))
84
+ assert_equal loc, @module::SCRIPTS[:rubies]
85
+ assert File.file?(loc)
86
+ end
87
+
88
+ def test_bundle_install_shell_script_location_should_be_lib
89
+ loc = File.expand_path(File.join(
90
+ File.dirname(__FILE__), '../../lib/rake_tasks/lib/bundle_install.sh'))
91
+ assert_equal loc, @module::SCRIPTS[:gemsets]
92
+ assert File.file?(loc)
93
+ end
94
+
64
95
  ############################################################################
65
96
  private
66
97
  ############################################################################
@@ -76,4 +107,14 @@ class TestsIntegrationTest < Test::Unit::TestCase
76
107
  @class.file_list(group).join("\n")
77
108
  end
78
109
  end
110
+
111
+ def configs
112
+ configs = []
113
+ rubies.each do |ruby|
114
+ rakes.each do |rake|
115
+ configs << { :ruby => ruby + '@rake_tasks_test', :rake => rake }
116
+ end
117
+ end
118
+ return configs
119
+ end
79
120
  end
@@ -0,0 +1,125 @@
1
+ # This file provides some common functions used in multiple test classes.
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
+ # Main module.
34
+ module RakeTasks
35
+ # This module contains methods/info. that is shared among test classes.
36
+ module RakeTasksShared
37
+
38
+ ############################################################################
39
+ private
40
+ ############################################################################
41
+
42
+ # The patterns that indicate that a file contains tests.
43
+ def files
44
+ ['*_test.rb',
45
+ 'test_*.rb']
46
+ end
47
+
48
+ # Paths that may contain tests.
49
+ def paths
50
+ ['test', 'tests']
51
+ end
52
+
53
+ # Returns the root folder.
54
+ # This will always be '/root'.
55
+ def root
56
+ '/root'
57
+ end
58
+
59
+ ############################################################################
60
+ # I/O support methods.
61
+ ############################################################################
62
+
63
+ # Returns the output from stdout as a string.
64
+ # ==== Output
65
+ # [String] The output from stdout.
66
+ #
67
+ # All trailing line feeds are removed.
68
+ def out
69
+ @out.respond_to?(:string) ? @out.string.gsub(/\n*\z/, '') : ''
70
+ end
71
+
72
+ # Returns the output from stderr as a string.
73
+ # ==== Output
74
+ # [String] The output from stderr.
75
+ #
76
+ # All trailing line feeds are removed.
77
+ def err
78
+ @err.respond_to?(:string) ? @err.string.gsub(/\n*\z/, '') : ''
79
+ end
80
+
81
+ # Return the actual output to stdout and stderr.
82
+ # ==== Output
83
+ # [Array] Two element array of strings.
84
+ #
85
+ # The first element is from stdout.
86
+ #
87
+ # The second element is from stderr.
88
+ def real_finis
89
+ return out, err
90
+ end
91
+
92
+ # Reset the stdout and stderr stream variables.
93
+ def reset_io
94
+ @out = StringIO.new
95
+ @err = StringIO.new
96
+ end
97
+
98
+ # Wrap a block to capture the output to stdout and stderr.
99
+ # ==== Input
100
+ # [&block : Block] The block of code
101
+ # that will have stdout and stderr trapped.
102
+ def wrap_output(&block)
103
+ begin
104
+ $stdout = @out
105
+ $stderr = @err
106
+ yield
107
+ rescue SystemExit
108
+ AppState.state = :dead
109
+ ensure
110
+ $stdout = STDOUT
111
+ $stderr = STDERR
112
+ end
113
+ end
114
+
115
+ ############################################################################
116
+ # Assertions.
117
+ ############################################################################
118
+
119
+ # Asserts that the specified text matches a given pattern.
120
+ def assert_match(pattern, text, msg = nil)
121
+ msg = msg || "<#{mu_pp(text)}> expected to match\n<#{mu_pp(pattern)}>"
122
+ assert text.match(pattern), msg
123
+ end
124
+ end
125
+ end
data/test/require.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'bundler'
1
2
  require 'test/unit'
2
3
 
3
4
  Bundler.require :test
4
5
 
5
6
  require_relative File.join('../lib/rake_tasks'.split('/'))
7
+ require_relative File.join('./lib/rake_tasks_shared'.split('/'))
@@ -0,0 +1,130 @@
1
+ #--
2
+ ################################################################################
3
+ # Copyright (C) 2011 Travis Herrick #
4
+ ################################################################################
5
+ # #
6
+ # \v^V,^!v\^/ #
7
+ # ~% %~ #
8
+ # { _ _ } #
9
+ # ( * - ) #
10
+ # | / | #
11
+ # \ _, / #
12
+ # \__.__/ #
13
+ # #
14
+ ################################################################################
15
+ # This program is free software: you can redistribute it #
16
+ # and/or modify it under the terms of the GNU Lesser General Public License #
17
+ # as published by the Free Software Foundation, #
18
+ # either version 3 of the License, or (at your option) any later version. #
19
+ ################################################################################
20
+ # This program is distributed in the hope that it will be useful, #
21
+ # but WITHOUT ANY WARRANTY; #
22
+ # without even the implied warranty of MERCHANTABILITY #
23
+ # or FITNESS FOR A PARTICULAR PURPOSE. #
24
+ # See the GNU Lesser General Public License for more details. #
25
+ # #
26
+ # You should have received a copy of the GNU Lesser General Public License #
27
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
28
+ ################################################################################
29
+ #++
30
+
31
+ require_relative File.join('../require'.split('/'))
32
+
33
+ class ParserTest < Test::Unit::TestCase
34
+ include RakeTasks::RakeTasksShared
35
+
36
+ def setup
37
+ reset_io
38
+ @module = RakeTasks
39
+ @class = @module::Parser
40
+ @obj = @class.new
41
+ end
42
+
43
+ def test_assert_works
44
+ assert true
45
+ end
46
+
47
+ def test_lines_should_print
48
+ printable_lines.each do |line|
49
+ wrap_output { @obj.parse line }
50
+ assert_match line.chomp + '\Z', out
51
+ end
52
+ assert_equal printable_lines.join(''), out
53
+ end
54
+
55
+ def test_lines_should_not_print
56
+ unprintable_lines.each do |line|
57
+ wrap_output { @obj.parse line }
58
+ assert_no_match Regexp.new(line), out
59
+ end
60
+ assert_equal '', out
61
+ end
62
+
63
+ def test_summary
64
+ summary_lines.each_value do |lines|
65
+ lines[:in].each do |line|
66
+ wrap_output { @obj.parse line }
67
+ end
68
+
69
+ reset_io
70
+ wrap_output { @obj.summarize }
71
+ @obj = @class.new
72
+
73
+ assert_equal lines[:out], out
74
+ end
75
+ end
76
+
77
+ def test_line_feeds_should_not_result_in_empty_lines
78
+ lines = [
79
+ "............\n",
80
+ "\n",
81
+ "35 tests, 203 assertions, 0 failures, 0 errors, 0 skips\n",
82
+ ]
83
+
84
+ lines.each do |line|
85
+ wrap_output { @obj.parse line }
86
+ end
87
+
88
+ assert_equal lines[0] + lines[2].chomp, out
89
+ end
90
+
91
+ ##############################################################################
92
+ private
93
+ ##############################################################################
94
+
95
+ def summary_lines
96
+ {
97
+ :single => {
98
+ :in => ["35 tests, 203 assertions, 0 failures, 0 errors, 0 skips\n"],
99
+ :out => '35 tests, 203 assertions, 0 failures, 0 errors, 0 skips',
100
+ },
101
+ :mutiple => {
102
+ :in => ["35 tests, 194 assertions, 3 failures, 4 errors, 2 skips\n",
103
+ "35 tests, 196 assertions, 1 failures, 5 errors, 1 skips\n"],
104
+ :out => '70 tests, 390 assertions, 4 failures, 9 errors, 3 skips',
105
+ },
106
+ }
107
+ end
108
+
109
+ def printable_lines
110
+ [
111
+ "Using /home/travis/.rvm/gems/ruby-1.9.3-p0 with gemset rake_tasks_test\n",
112
+ "...................................\n",
113
+ "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n",
114
+ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n",
115
+ "Finished in 0.208333 seconds.\n",
116
+ "Finished tests in 0.246907s, 141.7536 tests/s, 822.1707 assertions/s.\n",
117
+ "EF.EF.EF.EF.EF.EF.EF.EF.EF.EF.EF.EF\n",
118
+ "35 tests, 203 assertions, 0 failures, 0 errors, 0 skips\n",
119
+ "35 tests, 203 assertions, 0 failures, 0 errors, 0 skips",
120
+ ]
121
+ end
122
+
123
+ def unprintable_lines
124
+ [
125
+ "Run options: \n",
126
+ "# Running tests:\n",
127
+ "\n",
128
+ ]
129
+ end
130
+ end
@@ -31,8 +31,21 @@
31
31
  require_relative File.join('../require'.split('/'))
32
32
 
33
33
  class TestsUnitTest < Test::Unit::TestCase
34
+ include RakeTasks::RakeTasksShared
35
+
34
36
  def setup
35
- @class = RakeTasks::Tests
37
+ super
38
+ FakeFS.activate!
39
+ FileUtils.mkdir_p root
40
+ Dir.chdir root
41
+ @module = RakeTasks
42
+ @class = @module::Tests
43
+ end
44
+
45
+ def teardown
46
+ FakeFS::FileSystem.clear
47
+ FakeFS.deactivate!
48
+ super
36
49
  end
37
50
 
38
51
  def test_file_name_to_task_name
@@ -41,85 +54,231 @@ class TestsUnitTest < Test::Unit::TestCase
41
54
  end
42
55
 
43
56
  def test_tests_exist
44
- @class.expects(:root => 'root').with.once
45
- Dir.expects(:[] => []).with('root/**').once
46
- assert_equal false, @class.exist?
57
+ paths.each do |path|
58
+ files.each do |file|
59
+ clear_test_files
60
+
61
+ assert !@class.exist?, "#{path} folder should not contain anything."
62
+ FileUtils.mkdir_p File.join(path, 'something')
63
+ assert !@class.exist?,
64
+ "#{path} folder should not contain any matching files."
47
65
 
48
- @class.expects(:root => 'root').with.once
49
- Dir.expects(:[] => ['root/path']).with('root/**').once
50
- assert @class.exist?
66
+ FileUtils.touch File.join(path, file.gsub(/\*/, 'abc'))
67
+ assert @class.exist?, "#{path} should contain one matching file."
68
+ end
69
+ end
51
70
  end
52
71
 
53
- def test_file_list
54
- @class.stubs(:root => 'root').with
55
- @class.expects(:types => ['alphabet', 'number']).with.once
56
-
57
- patterns.each do |pattern|
58
- Dir.expects(
59
- :[] => []).with("root/#{pattern}").once
60
- case pattern
61
- when /^\*/
62
- Dir.expects(
63
- :[] => ['root/alphabet/abc_test.rb', 'root/alphabet/def_test.rb']).
64
- with("root/alphabet/#{pattern}").once
65
- Dir.expects(
66
- :[] => ['root/number/add_test.rb']).
67
- with("root/number/#{pattern}").once
68
- when /\*.rb$/
69
- Dir.expects(:[] => []).with("root/alphabet/#{pattern}").once
70
- Dir.expects(:[] => []).with("root/number/#{pattern}").once
72
+ def test_file_list_and_types
73
+ file_list = [
74
+ { :path => 'alphabet', :file => 'abc' },
75
+ { :path => 'alphabet', :file => 'def' },
76
+ { :path => 'number' , :file => 'add' },
77
+ ]
78
+
79
+ paths.each do |path|
80
+ files.each do |file|
81
+ clear_test_files
82
+ list = file_list.map do |f|
83
+ file_path = file.gsub(/\*/, f[:file])
84
+ file_path = File.join(path, f[:path], file_path)
85
+
86
+ FileUtils.mkdir_p File.dirname(file_path)
87
+ FileUtils.touch file_path
88
+ File.join root, file_path
89
+ end
90
+
91
+ FileUtils.mkdir_p File.join(root, path, 'color')
92
+ FileUtils.touch File.join(root, path, 'color', 'red.txt')
93
+
94
+ assert_equal list, @class.file_list
95
+ assert_equal file_list.map { |f| f[:path] }.uniq, @class.types
71
96
  end
72
97
  end
98
+ end
73
99
 
74
- assert_equal [
75
- 'root/alphabet/abc_test.rb',
76
- 'root/alphabet/def_test.rb',
77
- 'root/number/add_test.rb',
78
- ],
79
- @class.file_list
100
+ def test_rubies_check
101
+ paths.each do |path|
102
+ clear_test_files
103
+ FileUtils.mkdir_p path
104
+ assert !@class.run_rubies?,
105
+ 'The user should not be able to run tests agaisnt multiple Rubies.'
106
+ FileUtils.touch File.join(path, rubies_yaml_file)
107
+ assert @class.run_rubies?,
108
+ 'The user should be able to run tests agaisnt multiple Rubies.'
109
+ end
80
110
  end
81
111
 
82
- def test_types
83
- @class.stubs(:root => 'root')
84
-
85
- File.stubs(:directory? => true)
86
- File.expects(:directory? => false).with('root/file.rb').once
87
-
88
- Dir.expects(:[] => [
89
- 'root/mammal', 'root/marsupial', 'root/primate', 'root/file.rb']).
90
- with('root/**').once
91
-
92
- patterns.each do |pattern|
93
- [
94
- "root/mammal/#{pattern}",
95
- "root/marsupial/#{pattern}",
96
- "root/primate/#{pattern}",
97
- ].each do |path|
98
- if path =~ /primate/
99
- Dir.expects(:[] => []).with(path).once
100
- else
101
- Dir.expects(:[] => [File.join(File.dirname(path), 'file_test.rb')]).
102
- with(path).at_least(0)
112
+ def test_config_data
113
+ paths.each do |path|
114
+ clear_test_files
115
+
116
+ FileUtils.mkdir_p path
117
+
118
+ configs.keys.each do |config|
119
+ File.open("./#{path}/rubies.yml", 'w') do |file|
120
+ file.write configs[config][:in]
103
121
  end
122
+
123
+ assert_equal configs[config][:out], @class.test_configs,
124
+ "rubies.yml in #{path} did not result in expected outcome"
104
125
  end
105
126
  end
106
- #~ File.expects(:directory? => true).with('root/mammal').once
107
- #~ File.expects(:directory? => true).with('root/marsupial').once
108
- #~ File.expects(:directory? => true).with('root/primate').once
109
- #~ File.expects(:directory? => false).with('root/file.rb').once
127
+ end
128
+
129
+ def test_run_rubies
130
+ path = paths[0]
131
+ FileUtils.mkdir_p path
132
+
133
+ configs.each do |k, v|
134
+ next unless v[:out].is_a?(Array)
135
+
136
+ File.open("./#{path}/rubies.yml", 'w') do |file|
137
+ file.write v[:in]
138
+ end
139
+
140
+ matches = []
141
+ gem_rubies = []
142
+ v[:out].each_with_index do |config, i|
143
+ if config[:ruby] and !config[:ruby].strip.empty?
144
+ unless gem_rubies.include?(config[:ruby])
145
+ gem_rubies << config[:ruby]
146
+ gems = ['bash', @module::SCRIPTS[:gemsets]]
147
+
148
+ Process.expects(:spawn).with(*gems, *config[:ruby].split('@'))
149
+ .returns(101 + i).once
150
+ Process.expects(:wait).with(101 + i).once
151
+ end
152
+
153
+ rubies = ['bash', @module::SCRIPTS[:rubies], 'test:all']
154
+ rubies << config[:ruby]
155
+ rubies << "_#{config[:rake]}_" if config[:rake]
110
156
 
111
- assert_equal ['mammal', 'marsupial'], @class.types
157
+ Process.expects(:spawn).with(*rubies,
158
+ :out => 'out.log', :err => 'err.log').
159
+ returns(71 + i).once
160
+ Process.expects(:wait).with(71 + i).once
161
+
162
+ matches << "#{config[:ruby]} - #{config[:rake]}\n*" if config[:rake]
163
+ end
164
+ end
165
+
166
+ FileUtils.touch 'out.log'
167
+ FileUtils.touch 'err.log'
168
+
169
+ reset_io
170
+ wrap_output { @class.run_ruby_tests }
171
+
172
+ assert !File.file?('out.log'), 'Log file (out.log) should be deleted.'
173
+ assert !File.file?('err.log'), 'Log file (err.log) should be deleted.'
174
+
175
+ matches.each do |match|
176
+ assert_match match, out
177
+ end
178
+
179
+ assert_no_match Regexp.new(" - \n"), out
180
+ end
112
181
  end
113
182
 
114
183
  ############################################################################
115
184
  private
116
185
  ############################################################################
117
186
 
118
- # The patterns that indicate that a file contains tests.
119
- def patterns
120
- [
121
- '*_test.rb',
122
- 'test_*.rb',
123
- ]
187
+ def clear_test_files
188
+ paths.each do |path|
189
+ FileUtils.rm_rf(path) if File.directory?(path)
190
+ end
191
+ end
192
+
193
+ def configs
194
+ yaml = {
195
+ :basic => {
196
+ :out => [
197
+ {:ruby => '1.9.2@my_gemset', :rake => '0.8.7'},
198
+ {:ruby => '1.9.3@my_gems' , :rake => '0.9.2'},
199
+ ], # :out
200
+ }, # :basic
201
+ :no_rake => {
202
+ :out => [
203
+ {:ruby => '1.9.2@my_gemset'},
204
+ {:ruby => '1.9.3@my_gems' },
205
+ ], # :out
206
+ }, # :no_rake
207
+ :ruby_only => {
208
+ :out => [
209
+ {:ruby => '1.9.2'},
210
+ {:ruby => '1.9.3'},
211
+ ], # :out
212
+ }, # :ruby_only
213
+ :gemset_only => {
214
+ :out => [
215
+ {:ruby => '@the_gem'},
216
+ {:ruby => '@a_gem'},
217
+ ], # :out
218
+ }, # :gemset_only
219
+ :multi_rake => {
220
+ :out => [
221
+ {:ruby => '1.9.3@multi_rake', :rake => '0.8.7'},
222
+ {:ruby => '1.9.3@multi_rake', :rake => '0.9.2'},
223
+ ], # :multi_rake
224
+ }, # :basic
225
+ :nothing => {
226
+ :in => '',
227
+ :out => nil,
228
+ }, # :nothing
229
+ :nonsense => {
230
+ :out => [],
231
+ }, # :nonsense
232
+ }
233
+
234
+ yaml[:basic][:in] = <<-BASIC
235
+ - ruby: 1.9.2
236
+ gemset: my_gemset
237
+ rake: 0.8.7
238
+ - ruby: 1.9.3
239
+ gemset: my_gems
240
+ rake: 0.9.2
241
+ BASIC
242
+
243
+ yaml[:no_rake][:in] = <<-NO_RAKE
244
+ - ruby: 1.9.2
245
+ gemset: my_gemset
246
+ - ruby: 1.9.3
247
+ gemset: my_gems
248
+ NO_RAKE
249
+
250
+ yaml[:ruby_only][:in] = <<-RUBY_ONLY
251
+ - ruby: 1.9.2
252
+ - ruby: 1.9.3
253
+ RUBY_ONLY
254
+
255
+ yaml[:gemset_only][:in] = <<-GEMSET_ONLY
256
+ - gemset: the_gem
257
+ - gemset: a_gem
258
+ GEMSET_ONLY
259
+
260
+ yaml[:multi_rake][:in] = <<-MULTI_RAKE
261
+ - ruby: 1.9.3
262
+ gemset: multi_rake
263
+ rake: 0.8.7
264
+ - ruby: 1.9.3
265
+ gemset: multi_rake
266
+ rake: 0.9.2
267
+ MULTI_RAKE
268
+
269
+ yaml[:nonsense][:in] = <<-NONSENSE
270
+ - key1: value1
271
+ - key2: value2
272
+ NONSENSE
273
+
274
+ yaml.each_key do |k|
275
+ yaml[k][:in] = yaml[k][:in].strip
276
+ end
277
+
278
+ yaml
279
+ end
280
+
281
+ def rubies_yaml_file
282
+ 'rubies.yml'
124
283
  end
125
284
  end
metadata CHANGED
@@ -1,80 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rake_tasks
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 0
8
- - 0
9
- version: 2.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Travis Herrick
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-10-11 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rdoc
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 3
30
- - 9
31
- - 4
32
- version: 3.9.4
33
- type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rake
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
12
+ date: 2011-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mocha
16
+ requirement: &19696180 !ruby/object:Gem::Requirement
39
17
  none: false
40
- requirements:
18
+ requirements:
41
19
  - - ~>
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 9
46
- - 2
47
- version: 0.9.2
48
- type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: mocha
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.0
22
+ type: :development
52
23
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
24
+ version_requirements: *19696180
25
+ - !ruby/object:Gem::Dependency
26
+ name: fakefs
27
+ requirement: &19695500 !ruby/object:Gem::Requirement
54
28
  none: false
55
- requirements:
29
+ requirements:
56
30
  - - ~>
57
- - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 10
61
- - 0
62
- version: 0.10.0
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.0
63
33
  type: :development
64
- version_requirements: *id003
65
- description: |-
66
- RakeTasks provides basic rake tasks for generating documentation,
34
+ prerelease: false
35
+ version_requirements: *19695500
36
+ description: ! 'RakeTasks provides basic rake tasks for generating documentation,
37
+
67
38
  building and installing gems, and running tests.
68
- It will also load additional rake tasks if they are in a folder named 'tasks'.
69
- mmmm yummy
39
+
40
+ It will also load additional rake tasks if they are in a folder named ''tasks''.
41
+
42
+ mmmm yummy'
70
43
  email: tthetoad@gmail.com
71
44
  executables: []
72
-
73
45
  extensions: []
74
-
75
- extra_rdoc_files:
46
+ extra_rdoc_files:
76
47
  - README
77
- files:
48
+ files:
78
49
  - Gemfile.lock
79
50
  - Gemfile
80
51
  - README
@@ -88,6 +59,8 @@ files:
88
59
  - lib/rake_tasks/lib/tests.rb
89
60
  - lib/rake_tasks/lib/gem.rb
90
61
  - lib/rake_tasks/lib/doc.rb
62
+ - lib/rake_tasks/lib/parser.rb
63
+ - lib/rake_tasks/lib/rubies.sh
91
64
  - license/lgplv3
92
65
  - license/lgplv3.png
93
66
  - license/gplv3
@@ -95,46 +68,43 @@ files:
95
68
  - test/unit/gem_unit_test.rb
96
69
  - test/unit/tests_unit_test.rb
97
70
  - test/unit/doc_unit_test.rb
71
+ - test/unit/parser_test.rb
98
72
  - test/integration/tests_integration_test.rb
99
73
  - test/integration/gem_integration_test.rb
100
74
  - test/integration/doc_integration_test.rb
101
- has_rdoc: true
75
+ - test/lib/rake_tasks_shared.rb
102
76
  homepage: http://www.bitbucket.org/ToadJamb/gems_rake_tasks
103
- licenses:
77
+ licenses:
104
78
  - LGPLv3
105
79
  post_install_message:
106
80
  rdoc_options: []
107
-
108
- require_paths:
81
+ require_paths:
109
82
  - lib
110
- required_ruby_version: !ruby/object:Gem::Requirement
83
+ required_ruby_version: !ruby/object:Gem::Requirement
111
84
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
90
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- segments:
124
- - 0
125
- version: "0"
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
126
95
  requirements: []
127
-
128
96
  rubyforge_project:
129
- rubygems_version: 1.3.7
97
+ rubygems_version: 1.8.10
130
98
  signing_key:
131
99
  specification_version: 3
132
100
  summary: Basic rake tasks. You know you want some.
133
- test_files:
101
+ test_files:
134
102
  - test/require.rb
135
103
  - test/unit/gem_unit_test.rb
136
104
  - test/unit/tests_unit_test.rb
137
105
  - test/unit/doc_unit_test.rb
106
+ - test/unit/parser_test.rb
138
107
  - test/integration/tests_integration_test.rb
139
108
  - test/integration/gem_integration_test.rb
140
109
  - test/integration/doc_integration_test.rb
110
+ - test/lib/rake_tasks_shared.rb