Trying to use a rake task to run only tests in the test/models directory. Using minitest.

I have a rake task that will run all test

  require "rake/testtask"

  Rake::TestTask.new(:test => "db:test:prepare") do |t| 
    t.libs << "test"
    t.pattern = "test/**/*_test.rb"
 end

 task :default => :test

Then, running 'rake' hits the default and runs all tests. I want to write a second rake task that would only run tests in the models directory (test/models/).

I played around with this existing TestTask by simply changing

t.pattern = "test/**/*_test.rb"

to

t.pattern = "test/models/*_test.rb"

but, it seems to still run all the tests...not just models. Strange?

QUESTIONS

How can I accomplish this? How to I need to name a second TestTask that will run only models, and how do I tell rake to run that test instead of the default :test?

有帮助吗?

解决方案

The pattern you are looking for is "test/models/**/*_test.rb". The "**" will match subdirectories as well.

If you are using minitest-rails then you have lots of tasks added for you. To run all Model tests run:

rake minitest:models

To see all the rake tasks creates for you, run:

rake -T

其他提示

As usual, the answer was quite simple. Just took a bit of digging around. Make sure you have the following in your application.rb (inside the module).

config.generators do |g|
    g.fixture_replacement :factory_girl # if your using factory_girl
    g.test_framework :mini_test, :spec => true, :fixture => false
end 

Then you have access to minitests built in commands. The one I was looking for is as simple

rake minitest:models

Booya!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top