Skip to content

Commit e57bb19

Browse files
committed
Improve initial project setup for running tests.
Must run `rake project:setup[mysql]` to create database.yml for your local env.
1 parent 9347c72 commit e57bb19

File tree

7 files changed

+38
-161
lines changed

7 files changed

+38
-161
lines changed

Rakefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ Bundler::GemHelper.install_tasks
2020

2121
require 'rake/testtask'
2222

23-
Rake::TestTask.new('test:units' => 'app:test:prepare') do |t|
23+
Rake::TestTask.new('test:units' => ['project:ensure_db_exists', 'app:test:prepare']) do |t|
2424
t.libs << 'lib'
2525
t.libs << 'test'
2626
t.pattern = 'test/unit/**/*_test.rb'
2727
t.verbose = false
2828
end
2929

30-
Rake::TestTask.new('test:functionals' => 'app:test:prepare') do |t|
30+
Rake::TestTask.new('test:functionals' => ['project:ensure_db_exists', 'app:test:prepare']) do |t|
3131
t.libs << 'lib'
3232
t.libs << 'test'
3333
t.pattern = 'test/functional/**/*_test.rb'
3434
t.verbose = false
3535

3636
end
3737

38-
Rake::TestTask.new('test:integration') do |t|
38+
Rake::TestTask.new('test:integration' => ['project:ensure_db_exists', 'app:test:prepare']) do |t|
3939
t.libs << 'lib'
4040
t.libs << 'test'
4141
t.pattern = 'test/integration/**/*_test.rb'
@@ -45,15 +45,15 @@ end
4545
require 'cucumber'
4646
require 'cucumber/rake/task'
4747

48-
Cucumber::Rake::Task.new(:features) do |t|
48+
Cucumber::Rake::Task.new(:features => ['project:ensure_db_exists', 'app:test:prepare']) do |t|
4949
t.cucumber_opts = "features --format progress"
5050
end
5151

52-
Cucumber::Rake::Task.new('features:fast') do |t|
52+
Cucumber::Rake::Task.new('features:fast' => ['project:ensure_db_exists', 'app:test:prepare']) do |t|
5353
t.cucumber_opts = "features --format progress --tags ~@cli"
5454
end
5555

56-
Cucumber::Rake::Task.new('features:cli') do |t|
56+
Cucumber::Rake::Task.new('features:cli' => ['project:ensure_db_exists', 'app:test:prepare']) do |t|
5757
t.cucumber_opts = "features --format progress --tags @cli"
5858
end
5959

@@ -62,7 +62,7 @@ desc "Run everything but the command line (slow) tests"
6262
task 'test:fast' => %w{test:units test:functionals test:integration features:fast}
6363

6464
desc 'Runs all the tests'
65-
task :test => 'app:test:prepare' do
65+
task :test => ['project:ensure_db_exists', 'app:test:prepare'] do
6666
tests_to_run = ENV['TEST'] ? ["test:single"] : %w(test:units test:functionals test:integration features)
6767
errors = tests_to_run.collect do |task|
6868
begin

config/database.jdbcmysql.yml.example

Lines changed: 0 additions & 30 deletions
This file was deleted.

config/database.mysql.yml.example

Lines changed: 0 additions & 27 deletions
This file was deleted.

config/database.postgres.yml.example

Lines changed: 0 additions & 25 deletions
This file was deleted.

config/database.sqlite3.yml.example

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/tasks/core_tasks.rake

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,43 @@ end
1717

1818

1919
# These are tasks for the core browsercms project, and shouldn't be bundled into the distributable gem
20-
namespace :test do
21-
22-
# Could be improved somewhat to get rid of unneeded warnings.
23-
desc "run tests against sqlite database"
24-
task :sqlite3 do
25-
cp(File.join('config', 'database.sqlite3.yml'), File.join('config', 'database.yml'), :verbose => true)
26-
Rake::Task['db:drop'].invoke
27-
Rake::Task['db:create'].invoke
28-
system "rake db:migrate test"
29-
end
30-
31-
# Could be improved somewhat to get rid of unneeded warnings.
32-
desc "run tests against mysql database"
33-
task :mysql do
34-
cp(File.join('config', 'database.mysql.yml'), File.join('config', 'database.yml'), :verbose => true)
35-
Rake::Task['db:drop'].invoke
36-
Rake::Task['db:create'].invoke
37-
system "rake db:migrate test"
20+
namespace :project do
21+
22+
# Could be improved somewhat to get rid of unneeded warnings.
23+
#desc "run tests against sqlite database"
24+
#task :sqlite3 do
25+
# cp(File.join('config', 'database.sqlite3.yml'), File.join('config', 'database.yml'), :verbose => true)
26+
# Rake::Task['db:drop'].invoke
27+
# Rake::Task['db:create'].invoke
28+
# system "rake db:migrate test"
29+
#end
30+
#
31+
## Could be improved somewhat to get rid of unneeded warnings.
32+
#desc "run tests against mysql database"
33+
#task :mysql do
34+
# cp(File.join('config', 'database.mysql.yml'), File.join('config', 'database.yml'), :verbose => true)
35+
# Rake::Task['db:drop'].invoke
36+
# Rake::Task['db:create'].invoke
37+
# system "rake db:migrate test"
38+
#end
39+
40+
task :ensure_db_exists do
41+
unless File.exists?("test/dummy/config/database.yml")
42+
fail("Need to create a database.yml file before running tests. Run:\n $ rake project:setup[database] to create a sample database.yml for the project.")
43+
end
3844
end
3945

4046
desc 'Copy database.yml files for running tests'
41-
task :setup do
42-
drivers = %w(jdbcmysql mysql postgres sqlite3).each do |driver|
43-
source = File.join('config', "database.#{driver}.yml.example")
44-
destination = File.join('config', "database.#{driver}.yml")
45-
cp(source, destination, :verbose => true)
47+
task :setup, :database do |t, args|
48+
drivers = %w(jdbcmysql mysql postgres sqlite3)
49+
unless drivers.include?(args[:database])
50+
fail("'#{args[:database]}' is not an available database. Choose from one of the following #{drivers.inspect}. i.e\n\t$ rake project:setup[mysql]")
4651
end
4752

48-
source = File.join('test/dummy/config', "database.yml.example")
53+
source = File.join('test/dummy/config', "database.#{args[:database]}.yml")
4954
destination = File.join('test/dummy/config', "database.yml")
5055
cp(source, destination, :verbose => true)
56+
57+
5158
end
5259
end

test/dummy/config/database.yml.example

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)