Skip to content

Commit

Permalink
Restructure rake test task runner (publiclab#380)
Browse files Browse the repository at this point in the history
* add a mysql setup file

* Squash commits
  • Loading branch information
sashadev-sky authored and avsingh999 committed Mar 30, 2019
1 parent 45a4f7e commit 8573505
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ install:

script:
- sed -ri "s/REPO_TOKEN/$REPO_TOKEN/" .coveralls.yml
- docker-compose exec web bash -l -c "CI=true TRAVIS=true rake test"
- docker-compose run web bash -l -c "CI=true TRAVIS=true rake test:all"
1 change: 0 additions & 1 deletion MYSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,5 @@ $ mysql -u <username> -p
```



## Pending: please add instructions for your respective system

6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)

# Load all the rake tasks from the "tasks" folder.
task_dir = File.expand_path("../tasks", __FILE__)
Dir["#{task_dir}/**/*.rake"].each do |task_file|
load task_file
end

Mapknitter::Application.load_tasks
112 changes: 112 additions & 0 deletions lib/tasks/test_unit.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# ==================== #

# HOW TO RUN #

# You can find all rake tasks, both those that come built-in with rake / rails and custom created ones,
# by running `rake --tasks`. Note you might need to set up repo configurations before you are able to run this.

# `rake --tasks`, shows two columns: the name of the rake task (functions as the CLI command to run the task) and the
# description (what the task does). All the tasks created in this file start with "Autotask" in the description
# for easy reference. You can also find the commands (or command patterns for collections) commented above their respective tasks below.

# TEST STRUCTURE #

# Currently, you can
# 1) run all unit, functional, and integration tests together.
# 2) run only unit, functional, or integration tests (files within the corresponding folder can be run concurrently or one a time).
# 3) Last, you can run separate test files within the unit, functional, and integration test folders.

# If proper naming convention is followed, tasks are autogenerated for individual testing files added to the unit, functional, and
# integration folders (see creation of 'COMPUTE' arrays below).

# ==================== #

namespace :test do

# command: rake test:all
# run unit, functional, and integration test folders (one folder at a time, in the order indicated in the pattern below)
Rake::TestTask.new do |t|
t.name = "all"
t.description = "Autotask - run unit, functional, and integration tests"
t.libs << "test"
t.pattern = FileList["test/unit/*_test.rb", "test/functional/*_test.rb", "test/integration/*_test.rb"]
t.warning = false
t.verbose = true
end

# command pattern: rake test:unit_test_file.rb
# autogenerates a rake task for every test file added to test/unit
COMPUTE_UNIT_TASKS = []
Dir.glob("test/unit/*_test.rb").each do |task|
collection = task.gsub(/test\/unit\//, "")
Rake::TestTask.new(:"#{collection}") do |t|
t.libs << "test"
t.description = "Autotask - run unit tests - #{collection}"
t.pattern = FileList["test/unit/#{collection}"]
t.warning = false
t.verbose = true
end
COMPUTE_UNIT_TASKS << "#{collection}"
end

# command: rake test:unit
# run all unit test files (one file at a time in alphabetical order)
desc "Autotask - run unit tests"
task :unit => COMPUTE_UNIT_TASKS

# command: rake test:unit_parallel
# run all unit test files concurrently (one file at a time, order is not guaranteed)
desc "Autotask - run unit tests in parallel"
multitask :unit_parallel => COMPUTE_UNIT_TASKS

# command pattern: rake test:functional_test_file.rb
# autogenerates a rake task for every test file added to test/functional
COMPUTE_FUNCTIONAL_TASKS = []
Dir.glob("test/functional/*_test.rb").each do |task|
collection = task.gsub(/test\/functional\//, "")
Rake::TestTask.new(:"#{collection}") do |t|
t.libs << "test"
t.description = "Autotask - run functional tests - #{collection}"
t.pattern = FileList["test/functional/#{collection}"]
t.warning = false
t.verbose = true
end
COMPUTE_FUNCTIONAL_TASKS << "#{collection}"
end

# command: rake test:functional
# run all functional test files
desc "Autotask - run functional tests"
task :functional => COMPUTE_FUNCTIONAL_TASKS

# command: rake test:functional_parallel
# run all functional test files concurrently
desc "Autotask - run functional tests in parallel"
multitask :functional_parallel => COMPUTE_FUNCTIONAL_TASKS

# command pattern: rake test:integration_test_file.rb
# autogenerates a rake task for every test file added to test/integration
COMPUTE_INTEGRATION_TASKS = []
Dir.glob("test/integration/*_test.rb").each do |task|
collection = task.gsub(/test\/integration\//, "")
Rake::TestTask.new(:"#{collection}") do |t|
t.libs << "test"
t.description = "Autotask - run integration tests - #{collection}"
t.pattern = FileList["test/integration/#{collection}"]
t.warning = false
t.verbose = true
end
COMPUTE_INTEGRATION_TASKS << "#{collection}"
end

# command: rake test:integration
# run all integration test files
desc "Autotask - run integration tests"
task :integration => COMPUTE_INTEGRATION_TASKS

# command: rake test:integration_parallel
# run all integration test files concurrently
desc "Autotask - run integration tests in parallel"
multitask :integration_parallel => COMPUTE_INTEGRATION_TASKS

end

0 comments on commit 8573505

Please sign in to comment.