Вопрос

When I run rake test, it doesn't run tests in a new folder that I have created.

By default Rails has this folder inside the test folder:
enter image description here

When I run test, i.e rake test, it tests the content of the test folder.

I have added an api folder inside the test folder.
enter image description here

The contents of the api folder are tested when I do this: rake test:run TEST=test/api/users_test.rb

But, when I just do rake test, it doesn't test the content of the api folder. How to configure it?

Это было полезно?

Решение

rake test:all should run all tests in subdirectories of the test folder, even non-default ones.

If you want to make a rake test:api task: Do rake -w test | grep '^rake test' to see the files (in the railties gem) where Rails defines test tasks. In testing.rake you'll see how Rails defines tasks for the default subdirectories. Make a lib/tasks/test.rake and do the same thing for your new subdirectory:

Rails::TestTask.new('api' => "test:prepare") do |t|
  t.pattern = "test/api/**/*_test.rb"
end
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top