Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More inteligent running of test tasks #1981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions padrino-gen/lib/padrino-gen/generators/components/tests/bacon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ def app(app = nil, &blk)
end
TEST

BACON_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
Rake::TestTask.new("test:\#{folder}") do |test|
test.pattern = "test/\#{folder}/**/*_test.rb"
test.verbose = true
end
end

desc "Run application test suite"
task 'test' => test_tasks.map { |f| "test:\#{f}" }
TEST

BACON_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

Expand Down Expand Up @@ -79,7 +63,7 @@ def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'bacon', :group => 'test'
insert_test_suite_setup BACON_SETUP, :path => 'test/test_config.rb'
create_file destination_root("test/test.rake"), BACON_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:test)\n", :before => 'PadrinoTasks.init')
end

def generate_controller_test(name, path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ def setup_test
create_file destination_root("cucumber.yml"), CUCUMBER_YML
require_dependencies 'rspec', :group => 'test'
insert_test_suite_setup RSPEC_SETUP, :path => "spec/spec_helper.rb"
create_file destination_root("spec/spec.rake"), RSPEC_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:spec)\n", :before => 'PadrinoTasks.init')
end
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ def app(app = nil, &blk)
end
TEST

MINITEST_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
Rake::TestTask.new("test:\#{folder}") do |test|
test.pattern = "test/\#{folder}/**/*_test.rb"
test.verbose = true
end
end

desc "Run application test suite"
task 'test' => test_tasks.map { |f| "test:\#{f}" }
TEST

MINITEST_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_CONTROLLER_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')

Expand Down Expand Up @@ -86,7 +70,7 @@ def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'minitest', :require => 'minitest/autorun', :group => 'test'
insert_test_suite_setup MINITEST_SETUP
create_file destination_root("test/test.rake"), MINITEST_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:test)\n", :before => 'PadrinoTasks.init')
end

def generate_controller_test(name, path)
Expand Down
18 changes: 1 addition & 17 deletions padrino-gen/lib/padrino-gen/generators/components/tests/riot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ class Riot::Context
end
TEST

RIOT_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
Rake::TestTask.new("test:\#{folder}") do |test|
test.pattern = "test/\#{folder}/**/*_test.rb"
test.verbose = true
end
end

desc "Run application test suite"
task 'test' => test_tasks.map { |f| "test:\#{f}" }
TEST

RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

Expand Down Expand Up @@ -93,7 +77,7 @@ def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'riot', :group => 'test'
insert_test_suite_setup RIOT_SETUP
create_file destination_root("test/test.rake"), RIOT_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:test)\n", :before => 'PadrinoTasks.init')
end

def generate_controller_test(name, path)
Expand Down
25 changes: 1 addition & 24 deletions padrino-gen/lib/padrino-gen/generators/components/tests/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,6 @@ def app(app = nil, &blk)
end
TEST

RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
begin
require 'rspec/core/rake_task'

spec_tasks = Dir['spec/*/'].each_with_object([]) do |d, result|
result << File.basename(d) unless Dir["\#{d}*"].empty?
end

spec_tasks.each do |folder|
desc "Run the spec suite in \#{folder}"
RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
t.pattern = "./spec/\#{folder}/**/*_spec.rb"
t.rspec_opts = "--color"
end
end

desc "Run complete application spec suite"
task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
rescue LoadError
puts "RSpec is not part of this bundle, skip specs."
end
TEST

RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST)
require 'spec_helper'

Expand Down Expand Up @@ -89,7 +66,7 @@ def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'rspec', :group => 'test'
insert_test_suite_setup RSPEC_SETUP, :path => "spec/spec_helper.rb"
create_file destination_root("spec/spec.rake"), RSPEC_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:spec)\n", :before => 'PadrinoTasks.init')
end

def generate_controller_test(name, path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ class !NAME!ControllerTest < Test::Unit::TestCase
end
TEST

SHOULDA_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
Rake::TestTask.new("test:\#{folder}") do |test|
test.pattern = "test/\#{folder}/**/*_test.rb"
test.verbose = true
end
end

desc "Run application test suite"
task 'test' => test_tasks.map { |f| "test:\#{f}" }
TEST

SHOULDA_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')

Expand Down Expand Up @@ -90,7 +74,7 @@ def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'shoulda', :group => 'test'
insert_test_suite_setup SHOULDA_SETUP
create_file destination_root("test/test.rake"), SHOULDA_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:test)\n", :before => 'PadrinoTasks.init')
end

def generate_controller_test(name, path = nil)
Expand Down
18 changes: 1 addition & 17 deletions padrino-gen/lib/padrino-gen/generators/components/tests/steak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ def app
end
TEST

STEAK_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_RAKE)
require 'rspec/core/rake_task'

spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }

spec_tasks.each do |folder|
RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
t.pattern = "./spec/\#{folder}/**/*_spec.rb"
t.rspec_opts = %w(-fs --color)
end
end

desc "Run complete application spec suite"
task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
TEST

STEAK_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_MODEL_TEST)
require 'spec_helper'

Expand All @@ -87,7 +71,7 @@ def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'steak', :group => 'test'
insert_test_suite_setup STEAK_SETUP, :path => "spec/spec_helper.rb"
create_file destination_root("spec/spec.rake"), STEAK_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:spec)\n", :before => 'PadrinoTasks.init')
end

# Generates a controller test given the controllers name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ def app(app = nil, &blk)
end
TEST

TESTUNIT_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_RAKE)
require 'rake/testtask'

test_tasks = Dir['test/*/'].map { |d| File.basename(d) }

test_tasks.each do |folder|
Rake::TestTask.new("test:\#{folder}") do |test|
test.pattern = "test/\#{folder}/**/*_test.rb"
test.verbose = true
end
end

desc "Run application test suite"
task 'test' => test_tasks.map { |f| "test:\#{f}" }
TEST

TESTUNIT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_CONTROLLER_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')

Expand Down Expand Up @@ -86,7 +70,7 @@ def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'test-unit', :require => 'test/unit', :group => 'test'
insert_test_suite_setup TESTUNIT_SETUP
create_file destination_root("test/test.rake"), TESTUNIT_RAKE
inject_into_file(destination_root('Rakefile'), "PadrinoTasks.use(:test)\n", :before => 'PadrinoTasks.init')
end

def generate_controller_test(name, path)
Expand Down
30 changes: 30 additions & 0 deletions padrino-gen/lib/padrino-gen/padrino-tasks/spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if PadrinoTasks.load?(:spec, false)
require 'rspec/core/rake_task'
require 'padrino-gen/padrino-tasks/test-helpers'

app_tasks = Padrino::Generators::TestHelpers.app_tasks(Padrino::Generators::TestHelpers.spec_glob)
app_tasks.each do |app, tests|
tests.each do |name, folder|
desc "Run specs in #{folder}"
RSpec::Core::RakeTask.new("spec:#{name}") do |t|
t.pattern = Padrino::Generators::TestHelpers.spec_glob(folder)
t.verbose = true
end
end

next unless app && app != 'app'

desc "Run all the specs for the #{app} app"
RSpec::Core::RakeTask.new("spec:#{app}") do |t|
t.pattern = Padrino::Generators::TestHelpers.spec_glob("spec/#{app}")
t.verbose = true
end
end

desc 'Run application test suite'
RSpec::Core::RakeTask.new do |t|
t.verbose = true
end

task :default => 'spec'
end
36 changes: 36 additions & 0 deletions padrino-gen/lib/padrino-gen/padrino-tasks/test-helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Padrino
module Generators
module TestHelpers
def self.spec_glob(root = 'spec')
"#{root}/**/*_spec.rb"
end

def self.test_glob(root = 'test')
"#{root}/**/*_test.rb"
end

def self.app_tasks(glob)
app_tasks = Hash.new { |apps, name| apps[name] = [] }

Dir[glob].each do |path|
dirs = path.split('/')
app = nil
if dirs[2].end_with?('.rb') && File.file?(path)
app = 'app'
name = dirs[1]
else
app = dirs[1]
name = app == 'app' ? dirs[2] : "#{dirs[1]}:#{dirs[2]}"
end

test = [ name, File.dirname(path) ]
next if app_tasks[app].include?(test)

app_tasks[app] << test
end

app_tasks
end
end
end
end
31 changes: 31 additions & 0 deletions padrino-gen/lib/padrino-gen/padrino-tasks/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if PadrinoTasks.load?(:test, false)
require 'rake/testtask'
require 'padrino-gen/padrino-tasks/test-helpers'

app_tasks = Padrino::Generators::TestHelpers.app_tasks(Padrino::Generators::TestHelpers.test_glob)
app_tasks.each do |app, tests|
tests.each do |name, folder|
Rake::TestTask.new("test:#{name}") do |t|
t.description = "Run tests in #{folder}"
t.pattern = Padrino::Generators::TestHelpers.test_glob(folder)
t.verbose = true
end
end

next unless app && app != 'app'

Rake::TestTask.new("test:#{app}") do |t|
t.description = "Run all the tests for the #{app} app"
t.pattern = Padrino::Generators::TestHelpers.test_glob("test/#{app}")
t.verbose = true
end
end

Rake::TestTask.new do |t|
t.description = 'Run application test suite'
t.pattern = Padrino::Generators::TestHelpers.test_glob
t.verbose = true
end

task :default => 'test'
end
Loading