0

ユニットテストや機能テストではないテストがたくさんあります。それらは次の形式です。test/foo/special_test.rb

rake test:unitsフォルダ内のすべてのテストを実行するようなrakeタスクを作成したいと思いfooます。どうすればよいですか?

編集:私は実際にrake test:fooは少し違うようにしたいと思います。単純に実行するときに実行したくrake test:unitsないというrake test点です。

4

1 に答える 1

1

これがどこから来たのか覚えていないので、残念ながら適切な承認を与えることはできませんが、これはうまくいくはずです。使用をやめたので「すべき」と言いますが、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
于 2013-01-08T17:22:32.823 に答える