add a class for splitting up rake commands
This commit is contained in:
parent
32eff659bc
commit
7f698da887
@ -2,6 +2,41 @@
|
||||
|
||||
module Rails
|
||||
class TestTask < Rake::TestTask # :nodoc: all
|
||||
class TestInfo
|
||||
def initialize(tasks)
|
||||
@tasks = tasks
|
||||
end
|
||||
|
||||
def files
|
||||
@tasks.find_all { |t| File.file?(t) && !File.directory?(t) }
|
||||
end
|
||||
|
||||
def tasks
|
||||
@tasks - files - opt_names
|
||||
end
|
||||
|
||||
def opts
|
||||
opts = opt_names
|
||||
if opts.any?
|
||||
"-n #{opts.join ' '}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def opt_names
|
||||
(@tasks - files).reject { |t| task_defined? t }
|
||||
end
|
||||
|
||||
def task_defined?(task)
|
||||
Rake::Task.task_defined? task
|
||||
end
|
||||
end
|
||||
|
||||
def self.test_info(tasks)
|
||||
TestInfo.new tasks
|
||||
end
|
||||
|
||||
def initialize(name = :test)
|
||||
super
|
||||
@libs << "test" # lib *and* test seem like a better default
|
||||
|
35
railties/test/test_info_test.rb
Normal file
35
railties/test/test_info_test.rb
Normal file
@ -0,0 +1,35 @@
|
||||
require 'abstract_unit'
|
||||
require 'rails/test_unit/sub_test_task'
|
||||
|
||||
module Rails
|
||||
class TestInfoTest < ActiveSupport::TestCase
|
||||
def test_test_files
|
||||
info = new_test_info ['test']
|
||||
assert_predicate info.files, :empty?
|
||||
assert_nil info.opts
|
||||
assert_equal ['test'], info.tasks
|
||||
end
|
||||
|
||||
def test_with_file
|
||||
info = new_test_info ['test', __FILE__]
|
||||
assert_equal [__FILE__], info.files
|
||||
assert_nil info.opts
|
||||
assert_equal ['test'], info.tasks
|
||||
end
|
||||
|
||||
def test_with_opts
|
||||
info = new_test_info ['test', __FILE__, '/foo/']
|
||||
assert_equal [__FILE__], info.files
|
||||
assert_equal '-n /foo/', info.opts
|
||||
assert_equal ['test'], info.tasks
|
||||
end
|
||||
|
||||
def new_test_info(tasks)
|
||||
Class.new(TestTask::TestInfo) {
|
||||
def task_defined?(task)
|
||||
task == "test"
|
||||
end
|
||||
}.new tasks
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user