ユニットテストや機能テストではないテストがたくさんあります。それらは次の形式です。test/foo/special_test.rb
rake test:units
フォルダ内のすべてのテストを実行するようなrakeタスクを作成したいと思いfoo
ます。どうすればよいですか?
編集:私は実際にrake test:foo
は少し違うようにしたいと思います。単純に実行するときに実行したくrake test:units
ないというrake test
点です。
ユニットテストや機能テストではないテストがたくさんあります。それらは次の形式です。test/foo/special_test.rb
rake test:units
フォルダ内のすべてのテストを実行するようなrakeタスクを作成したいと思いfoo
ます。どうすればよいですか?
編集:私は実際にrake test:foo
は少し違うようにしたいと思います。単純に実行するときに実行したくrake test:units
ないというrake test
点です。
これがどこから来たのか覚えていないので、残念ながら適切な承認を与えることはできませんが、これはうまくいくはずです。使用をやめたので「すべき」と言いますが、gitの履歴から取得しました。
# First, 'reopen' the default :test namespace and create your custom task.
namespace :test do
Rake::TestTask.new(:foo_tests => ["test:prepare", "other_dependent_rake_tasks"] ) do |t|
DatabaseCleaner.strategy = :transaction # If using this.
t.libs << "test"
# Will also get subfolders within test/foo
t.test_files = FileList['test/foo/**/*_test.rb', 'test/foo/*_test.rb']
end
end
デフォルトの「テスト」タスクを削除して再定義すると、実行時rake test
に自動的に実行されるようになりますrake test:foo_tests
。
remove_task "test"
desc 'Adding onto Rails regular tests'
task :test do
# Add all the names of tests you want run here.
errors = %w(test:units test:functionals test:integration test:foo_tests).collect do |task|
begin
puts "Running: #{task}"
Rake::Task[task].invoke
nil
rescue => e
task
end
end.compact
abort "Errors running #{errors * ', '}!" if errors.any?
end