How to run the full MiniTest package without Rake?

Looked at this question and that more or less reflects the way I am currently running my entire package.

In addition, I installed the following rake command:

Rake::TestTask.new do |t| t.name = "spec:models" t.libs << "test" t.pattern = "spec/models/*_spec.rb" end 

But I notice when I run it with time rake spec:models , which completes in about 2.36 seconds. If I run all the individual tests in this directory using ruby /path/to/spec.rb (all of them are currently isolated from ActiveRecord - there is no stability yet, so very quickly), their total user total time is 2.36 seconds but I also notice that each file takes 0.4 user seconds to run from start to finish, the actual β€œtest” time reported by MiniTest is much, much faster (so that my whole package should be executed in less than 0 after loading the download , 15 seconds, not 2.36 seconds).

Example (for one specification file):

 Started 11/11: 100% |======================================| Time: 00:00:00 Finished in 0.02223s 11 tests, 15 assertions, 0 failures, 0 errors, 0 skips ruby path/to/spec.rb 0.43s user 0.06s system 88% cpu 0.559 total 

I suspect that Rake reloads the libraries between each test run, and this takes extra time into account. Anyway, can I test this or run the whole package without using Rake?

By the way, when I say "user time" earlier, I mean the first number obtained by adding time to my ruby ​​command to run one test file, so time ruby /path/to/spec.rb = ruby path/to/spec.rb 0.43s user 0.06s system 88% cpu 0.559 total

+6
source share
2 answers

Create a spec.rb file in the top directory of your project:

 $:<<'spec' # add to load path files = Dir.glob('spec/**/*.rb') files.each{|file| require file.gsub(/^spec\/|.rb$/,'')} 

Run it:

 ruby spec.rb 

If this works for you, you can rename the spec.rb file spec.rb you like, or move it to a more suitable place or change the download paths as you like, etc.

+5
source

This will execute any tests in the specs directory and subdirectories with _spec.rb at the end of the file name:

 ruby -Itest spec/**/*_spec.rb 
+1
source

Source: https://habr.com/ru/post/915763/


All Articles