Pregunta

Some tests require internet connection and some other don't. So they are divided into two test groups with different file name patterns. How to update below Rakefile so that they can be run separately with different rake tasks?

It seems the question/answer here doesn't help in this case.

And the rakefile below runs all the test cases regardless what rake tasks are invoked on command line. Neither rake test nor rake itest works as expected.

The current Rakefile content is,

require 'rake/testtask'

Rake::TestTask.new do |t|
  t.test_files = FileList['test/test_*.rb']
end

Rake::TestTask.new do |t|
  t.test_files = FileList['test/itest_*.rb']
end

desc "Run tests with no internet required"
task :default => :test

desc "Run tests need internet connection"
task :internet => :test
¿Fue útil?

Solución

I've figured out how to associate the different testtask with different rake task. The trick is adding a task name while creating a new testtask. Like this,

Rake::TestTask.new(:default) do |t|
  t.test_files = FileList['test/test_*.rb']
end

Rake::TestTask.new(:internet) do |t|
  t.test_files = FileList['test/itest_*.rb']
end

desc "No internet connection required"
task :default => :test

desc "Needs internet connection"
task :internet => :test

So rake internet will just run the test cases that need internet connections.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top