Rake::TestTask

La clase Rake::TestTask nos permite crear una tarea que ejecuta un conjunto de pruebas;
  Rake::TestTask.new do |t|
    t.libs << "test"
    t.test_files = FileList['test/test*.rb']
    t.verbose = true
  end
Si se llama a rake con la opción TEST=filename entonces sólo se ejecutará esa prueba.

Si se invoca con la opción TESTOPTS=options, las opciones se pasarán a Test::Unit. Ejemplos:

  rake test                           # run tests normally
  rake test TEST=just_one_file.rb     # run just one test file.
  rake test TESTOPTS="-v"             # run in verbose mode

Sigue otro ejemplo:

MacBookdeJohn:htmlRB john$ cat Rakefile 
$:.unshift 'lib/'
require 'rake/testtask'

# rake test TEST=just_one_file.rb     # run just one test file.
# rake test TESTOPTS="-v"             # run in verbose mode
Rake::TestTask.new do |t|
  # t.libs: List of directories to be added to $LOAD_PATH. (default is ‘lib’)
  t.libs << "test" 
  t.pattern = 'test/tc*.rb' # or t.test_files = FileList['test/tc*.rb'] 
  t.warning = true
  t.verbose = true # verbose test output. (default is false)
end

Ejecuciones:

MacBookdeJohn:htmlRB john$ ls -ltr test/
total 16
-rw-r--r--  1 john  staff   835 29 nov 12:27 tc_01_smoke.rb
-rw-r--r--  1 john  staff  1023  9 dic 11:35 tc_02_smoke.rb
MacBookdeJohn:htmlRB john$ rake test
(in /Users/john/Dropbox/src/projects-ull-john/ruby/htmlRB)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -w -I"lib:test" "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake/rake_test_loader.rb" "test/tc_01_smoke.rb" "test/tc_02_smoke.rb" 
./lib/html.rb:40: warning: `&' interpreted as argument prefix
Loaded suite /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake/rake_test_loader
Started
...
Finished in 0.001125 seconds.

3 tests, 7 assertions, 0 failures, 0 errors
Con la opción TESTOPTS="-v" la salida es mas detallada:

MacBookdeJohn:htmlRB john$ rake test TESTOPTS="-v" 
(in /Users/john/Dropbox/src/projects-ull-john/ruby/htmlRB)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -w -I"lib:test" "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake/rake_test_loader.rb" "test/tc_01_smoke.rb" "test/tc_02_smoke.rb" -v
./lib/html.rb:40: warning: `&' interpreted as argument prefix
Loaded suite /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake/rake_test_loader
Started
test_attr(TestHTML): .
test_attr2(TestHTML): .
test_simplepage(TestHTML): .

Finished in 0.000844 seconds.

3 tests, 7 assertions, 0 failures, 0 errors
Ejecución de un solo programa de prueba:

MacBookdeJohn:htmlRB john$ rake test TEST=tc_02_smoke.rb
(in /Users/john/Dropbox/src/projects-ull-john/ruby/htmlRB)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -w -I"lib:test" "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake/rake_test_loader.rb" "tc_02_smoke.rb" 
./lib/html.rb:40: warning: `&' interpreted as argument prefix
Loaded suite /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake/rake_test_loader
Started
..
Finished in 0.000623 seconds.

2 tests, 6 assertions, 0 failures, 0 errors

Donde



Subsecciones
Casiano Rodriguez León 2015-01-07